Function pn532::helper::scan

Function Documentation

result<autorelease_target> pn532::helper::scan(std::shared_ptr<controller> const &ctrl, scanned_target const &skip_prev_target = scanned_target{}, std::vector<target_type> const &targets = controller::poll_all_targets, ms timeout = long_timeout)

Helper function to simplify scanning task.

This method makes the usage of controller::initiator_auto_poll a bit more handy, by automatically handling the rejection of the previous target and any multiple target. It can be easily used as follows:

while (true) {
    if (const auto r = pn532::helper::scan(controller, target); r and *r) {
        // Do something with scanned target *r.
    }
}

The rejection mechanism can also be used to detect when the previous target has left the RF field.

scanned_target previous_target{};
while (true) {
    if (const auto r = pn532::helper::scan(controller, previous_target); r) {
        if (previous_target) {
            // previous_target has left the RF field.
        }
        if (*r) {
            // Do something with scanned target *r.
        }
        previous_target = *r;
    }
}
Parameters:
  • ctrl – Controller to use for scanning.

  • skip_prev_target – A previously returned target to ignore.

  • targets – Type of targets to search for.

  • timeout – Timeout of the scan operation.

Returns:

A scanned_target instance, if any is found, otherwise none, or an error.