|
arduino-emulator
|
Single reader thread + byte-stream parser shared by every Firmata-based hardware backend (GPIO, I2C, SPI, ...) that talks to the same device. More...
#include <FirmataTransport.h>
Public Types | |
| using | AnalogHandler = std::function< void(const FirmataAnalogMessage &)> |
| using | DigitalHandler = std::function< void(const FirmataDigitalMessage &)> |
| using | SysexHandler = std::function< void(const FirmataSysexMessage &)> |
Public Member Functions | |
| void | addSysexHandler (uint8_t command, SysexHandler handler) |
| bool | begin (Stream &stream) |
| Start the background reader thread on the given stream. | |
| void | end () |
| Stop the reader thread and detach from the stream. | |
| void | onAnalogMessage (AnalogHandler handler) |
| Register the (single) handler for analog pin reports. | |
| void | onDigitalMessage (DigitalHandler handler) |
| Register the (single) handler for digital port reports. | |
| operator bool () const | |
| void | removeSysexHandler (uint8_t command) |
| Remove a previously registered SysEx handler. | |
| void | writeByte (uint8_t b) |
| void | writeBytes (const uint8_t *data, size_t len) |
| Thread-safe write of a raw byte sequence (e.g. a whole SysEx message). | |
Single reader thread + byte-stream parser shared by every Firmata-based hardware backend (GPIO, I2C, SPI, ...) that talks to the same device.
A real Firmata device is reached over exactly one Stream (typically a serial port). Digital/analog GPIO reports, I2C replies and SPI replies are all multiplexed over that single connection, so only one thread may ever read from the Stream. Each hardware backend registers the message types it cares about via onDigitalMessage()/onAnalogMessage()/ addSysexHandler() and shares one FirmataTransport instance; writes are serialized with an internal mutex so requests from different backends don't interleave on the wire.
Register a handler for SysEx messages carrying the given command byte (e.g. I2C_REPLY or SPI_DATA). Replaces any previously registered handler for the same command.