Module gpio::dummy
[−]
[src]
GPIO dummy input/output
The dummy module can be used instead of a GPIO implementation tied to hardware to run unit tests or otherwise provide means to test an application when no embedded device is around.
It supports the same interface as other GPIOs and its input and output behaviour can be configured in a flexible manner.
Example
The DummyGpioIn
reads values from a callback:
use std::time; use gpio::{GpioIn, GpioValue}; use gpio::dummy::DummyGpioIn; // a simple dummy gpio that is always `true`/`High` let mut dg = DummyGpioIn::new(|| true); assert_eq!(GpioValue::High, dg.read_value().unwrap()); // another example that flips every second let mut timed_gpio = DummyGpioIn::new(|| { std::time::SystemTime::now() .duration_since(time::UNIX_EPOCH) .unwrap() .as_secs() % 2 == 0 }); println!("timed: {:?}", timed_gpio.read_value().unwrap());
Output can simple be swallowed by a dummy output port:
use gpio::{GpioOut}; use gpio::dummy::DummyGpioOut; let mut dg = DummyGpioOut::new(|_| ()); dg.set_value(true);
Structs
DummyGpioIn |
Dummy GPIO input pin |
DummyGpioOut |
Dummy GPIO output pin |