1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate;
use ;
/// An input pin readable by the component
///
/// Supported pin types are as follows
///
/// | Type | Storage | Equivalent `linuxcnc_hal_sys` function |
/// | ---------------- | ------- | -------------------------------------- |
/// | `InputPin<f64>` | `f64` | [`hal_pin_float_new`] |
/// | `InputPin<u32>` | `u32` | [`hal_pin_u32_new`] |
/// | `InputPin<i32>` | `i32` | [`hal_pin_s32_new`] |
/// | `InputPin<bool>` | `bool` | [`hal_pin_bit_new`] |
///
/// # Examples
///
/// ## Create a pin
///
/// This example creates an `InputPin` under `demo-component.named-pin`.
///
/// ```rust,no_run
/// use linuxcnc_hal::{
/// error::PinRegisterError,
/// hal_pin::{InputPin},
/// prelude::*,
/// HalComponent, RegisterResources, Resources,
/// };
/// use std::{
/// error::Error,
/// thread,
/// time::{Duration, Instant},
/// };
///
/// struct Pins {
/// pin: InputPin<f64>,
/// }
///
/// impl Resources for Pins {
/// type RegisterError = PinRegisterError;
///
/// fn register_resources(comp: &RegisterResources) -> Result<Self, Self::RegisterError> {
/// Ok(Pins {
/// pin: comp.register_pin::<InputPin<f64>>("named-pin")?,
/// })
/// }
/// }
///
/// fn main() -> Result<(), Box<dyn Error>> {
/// let comp: HalComponent<Pins> = HalComponent::new("demo-component")?;
///
/// let Pins { pin } = comp.resources();
///
/// let start = Instant::now();
///
/// // Main control loop
/// while !comp.should_exit() {
/// println!("Input: {:?}", pin.value());
///
/// thread::sleep(Duration::from_millis(1000));
/// }
///
/// Ok(())
/// }
/// ```
impl_pin!;
impl_pin!;
impl_pin!;
impl_pin!;