Class pn532::scanner

Class Documentation

class scanner

Helper class that continuously scans for targets and calls scanner_responder methods in response. This class can automatically track rejected targets and ignore them until they have left the RF field. This is a move-only object.

auto pn532 = pn532::controller(comm_channel);
if (not comm_channel.wake()) {
    std::printf("Channel did not wake!\n");
} else {
    pn532::scanner scanner{pn532};
    my_responder_subclass responder{};
    scanner.loop(responder);
}

Public Functions

scanner() = default

Default-constructs a scanner which does nothing. All methods exist immediately.

explicit scanner(std::shared_ptr<controller> ctrl, ms max_scan_interval = 5s)

Constructs a scanner wrapping around ctrl.

Parameters:
  • ctrl – The reference must stay valid throughout the whole lifetime of this object.

  • max_scan_interval – Maximum interval after which a scan operation is aborted and restarted.

scanner(scanner const&) = delete
scanner &operator=(scanner const&) = delete
scanner(scanner&&) noexcept = default
scanner &operator=(scanner&&) noexcept = default
inline std::vector<scanned_target> const &in_rf() const

List of targets currently in the RF field.

inline ms max_scan_interval() const

Maximum interval of time after which loop is guaranteed to check any stop condition. This corresponds to the timeout time of controller::initiator_auto_poll.

inline void set_max_scan_interval(ms timeout)

Changes max_scan_interval.

Parameters:

timeout – Maximum interval after which a scan operation is aborted and restarted.

void loop(scanner_responder &responder, bool init_and_test = true)

Main loop scanning for tags.

Parameters:
  • responder – Responder class that reacts to the events.

  • init_and_test – If True, controller::init_and_test will be called before the loop starts, and exit if it fails. Otherwise, no test is performed and the loop jumps into scanning.

controller &ctrl()

Reference to the controller.

Warning

Calling this with a default-constructed scanner will abort.

controller const &ctrl() const

Reference to the controller.

Warning

Calling this with a default-constructed scanner will abort.

void stop()

Aborts loop. This will only take effect at the next scan attempt, thus it will take max_scan_interval ms before loop actually exits. This function returns immediately.