Crates.io | dummy-pin |
lib.rs | dummy-pin |
version | 1.0.0 |
source | src |
created_at | 2021-03-10 09:11:32.770708 |
updated_at | 2024-01-19 08:05:44.274136 |
description | Dummy implementations of the input/output pin embedded-hal traits. |
homepage | https://github.com/eldruin/dummy-pin-rs |
repository | https://github.com/eldruin/dummy-pin-rs |
max_upload_size | |
id | 366712 |
size | 39,794 |
This provides dummy implementations of the input/output pin embedded-hal
traits.
This is useful when dealing with setups where a certain pin is handled by hardware in a way
that the software does not need to know about, for example.
In addition to the no-op, zero-cost DummyPin
, this crate provides an implementation of LastStateDummyPin
,
which stores the last state set at runtime and returns it when read.
This example demonstrates how the same driver can operate with either a real or a dummy output pin.
use dummy_pin::DummyPin;
use embedded_hal::digital::OutputPin;
use linux_embedded_hal::SysfsPin;
struct Driver<P> {
output: P,
}
impl<P, E> Driver<P>
where
P: OutputPin<Error = E>,
{
fn new(pin: P) -> Self {
Driver { output: pin }
}
fn do_something(&mut self) -> Result<(), E> {
// ...
self.output.set_high()
}
}
fn main() {
// The same driver can operate with either a real or a dummy pin.
let real_pin = SysfsPin::new(25);
let mut driver_with_real_pin = Driver::new(real_pin);
driver_with_real_pin.do_something().unwrap();
let dummy_pin = DummyPin::new_low();
let mut driver_with_dummy_pin = Driver::new(dummy_pin);
driver_with_dummy_pin.do_something().unwrap();
}
For questions, issues, feature requests, and other changes, please file an issue in the github project.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.