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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! HAL parameters
use ;
pub use HalParameter;
/// Parameter write mode.
/// A parameter that can be read and written by LinuxCNC
///
/// Supported parameter types are as follows
///
/// | Type | Storage | Equivalent `linuxcnc_hal_sys` function |
/// | ------------------| ------- | -------------------------------------- |
/// | `Parameter<f64>` | `f64` | [`hal_param_float_new`] |
/// | `Parameter<u32>` | `u32` | [`hal_param_u32_new`] |
/// | `Parameter<i32>` | `i32` | [`hal_param_s32_new`] |
/// | `Parameter<bool>` | `bool` | [`hal_param_bit_new`] |
///
/// # Examples
///
/// ## Create a parameter
///
/// This example creates an `Parameter` under `demo-component.named-parameter`.
///
/// ```rust,no_run
/// use linuxcnc_hal::{
/// error::ParameterRegisterError,
/// Parameter,
/// prelude::*,
/// HalComponent, RegisterResources, Resources,
/// };
/// use std::{
/// error::Error,
/// thread,
/// time::{Duration, Instant},
/// };
///
/// struct MyApp {
/// parameter: Parameter<f64>,
/// }
///
/// impl Resources for MyApp {
/// type RegisterError = ParameterRegisterError;
///
/// fn register_resources(comp: &RegisterResources) -> Result<Self, Self::RegisterError> {
/// Ok(MyApp {
/// parameter: comp.register_parameter("named-parameter")?,
/// })
/// }
/// }
///
/// fn main() -> Result<(), Box<dyn Error>> {
/// let comp: HalComponent<MyApp> = HalComponent::new("demo-component")?;
///
/// let MyApp { parameter } = comp.resources();
///
/// let start = Instant::now();
///
/// // Main control loop
/// while !comp.should_exit() {
/// parameter.set_value(123.45f64);
/// thread::sleep(Duration::from_millis(1000));
/// }
///
/// Ok(())
/// }
/// ```
impl_param!;
impl_param!;
impl_param!;
impl_param!;