use linuxcnc_hal::{
error::PinRegisterError,
hal_pin::{InputPin, OutputPin},
prelude::*,
HalComponent, RegisterResources, Resources,
};
use std::{
error::Error,
thread,
time::{Duration, Instant},
};
struct Pins {
input_1: InputPin<f64>,
output_1: OutputPin<f64>,
}
impl Resources for Pins {
type RegisterError = PinRegisterError;
fn register_resources(comp: &RegisterResources) -> Result<Self, Self::RegisterError> {
Ok(Pins {
input_1: comp.register_pin::<InputPin<f64>>("input-1")?,
output_1: comp.register_pin::<OutputPin<f64>>("output-1")?,
})
}
}
fn main() -> Result<(), Box<dyn Error>> {
rtapi_logger::init().ok();
let comp: HalComponent<Pins> = HalComponent::new("rust-comp")?;
let pins = comp.resources();
let start = Instant::now();
while !comp.should_exit() {
let time = start.elapsed().as_secs() as i32;
pins.output_1.set_value(time.into())?;
println!("Input: {:?}", pins.input_1.value());
thread::sleep(Duration::from_millis(1000));
}
Ok(())
}