NAME

k8055m_poll -- Wait for new input

LIBRARY

k8055-pic18f access library

SYNOPSIS

#include "k8055m.h"

int
k8055m_poll(int cardNumber);
    

DESCRIPTION

The k8055m library uses a background thread to continuously read the HID reports, sent by the k8055-pic18f card. This thread keeps track of all input port and counter changes. Functions like k8055m_get_digital_in() therefore have instant access to the last known state of input data.

However, a code construct like

while (k8055m_get_digital_in(theCard, 0)) {
    ...
}

will cause a busy loop, wasting an entire CPU core, until line I1 of theCard is released.

To avoid such busy loops, k8055m_poll() should be called in between reading the same input ports. k8055m_poll() will immediately return, if the background thread has received a new HID report from the card since its last call. It will wait for the next HID report otherwise.

RETURN VALUES

Returns 0 on success, -1 on error.

CAVEATS

There should be a mechanism to register a callback function, that is invoked on the arrival of new HID reports.