pub trait IoProtocol:
IO
+ DynClone
+ Send
+ Sync
+ Debug
+ Display {
// Required methods
fn open(&mut self) -> Result<(), Error>;
fn close(&mut self) -> Result<(), Error>;
fn report_analog(&mut self, channel: u8, state: bool) -> Result<(), Error>;
fn report_digital(&mut self, pin: u8, state: bool) -> Result<(), Error>;
fn sampling_interval(&mut self, interval: u16) -> Result<(), Error>;
// Provided method
fn get_name(&self) -> &'static str { ... }
}
Expand description
Defines the trait all protocols must implement.
Required Methods§
Sourcefn report_analog(&mut self, channel: u8, state: bool) -> Result<(), Error>
fn report_analog(&mut self, channel: u8, state: bool) -> Result<(), Error>
Sets the analog reporting state
of the specified analog pin
.
When activated, the pin will send its value periodically. The value will be stored in the IoProtocol synced data.
use hermes_five::hardware::{Board, Hardware};
use hermes_five::io::IO;
let mut board = Board::default();
board.get_protocol().report_analog(0, true).expect("");
board.get_io().read().get_pin("A0").expect("").value;
Sourcefn report_digital(&mut self, pin: u8, state: bool) -> Result<(), Error>
fn report_digital(&mut self, pin: u8, state: bool) -> Result<(), Error>
Sets the digital reporting state
of the specified digital pin
.
This will activate the reporting of all pins in port (hence the pin will send us its value periodically) https://github.com/firmata/protocol/blob/master/protocol.md
Sourcefn sampling_interval(&mut self, interval: u16) -> Result<(), Error>
fn sampling_interval(&mut self, interval: u16) -> Result<(), Error>
Set the sampling interval
(in ms).
The sampling interval sets how often analog data and i2c data is reported to the client. The default for the arduino implementation is 19ms. This means that every 19ms analog data will be reported and any i2c devices with read continuous mode will be read. https://github.com/firmata/protocol/blob/master/protocol.md#sampling-interval