Struct linuxcnc_hal::hal_pin::InputPin
source · pub struct InputPin<S> { /* private fields */ }
Expand description
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
.
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(())
}
Trait Implementations
sourceimpl HalPin for InputPin<bool>
impl HalPin for InputPin<bool>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moresourceimpl HalPin for InputPin<f64>
impl HalPin for InputPin<f64>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moresourceimpl HalPin for InputPin<i32>
impl HalPin for InputPin<i32>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moresourceimpl HalPin for InputPin<u32>
impl HalPin for InputPin<u32>
sourcefn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>
Get a mutable pointer to underlying shared memory storing this pin’s value
sourcefn storage(&self) -> Result<&Self::Storage, StorageError>
fn storage(&self) -> Result<&Self::Storage, StorageError>
Get a reference to the underlying shared memory storing the pin’s value
sourcefn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
fn register(
full_pin_name: &str,
component_id: i32
) -> Result<Self, PinRegisterError>
Register the pin with the LinuxCNC HAL Read more
sourcefn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>
Allocate memory using
hal_malloc()
for storing pin value in Read moreAuto Trait Implementations
impl<S> RefUnwindSafe for InputPin<S>where
S: RefUnwindSafe,
impl<S> !Send for InputPin<S>
impl<S> !Sync for InputPin<S>
impl<S> Unpin for InputPin<S>
impl<S> UnwindSafe for InputPin<S>where
S: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more