InputPin

Struct InputPin 

Source
pub struct InputPin<S> { /* private fields */ }
Expand description

An input pin readable by the component

Supported pin types are as follows

TypeStorageEquivalent linuxcnc_hal_sys function
InputPin<f64>f64hal_pin_float_new
InputPin<u32>u32hal_pin_u32_new
InputPin<i32>i32hal_pin_s32_new
InputPin<bool>boolhal_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§

Source§

impl<S: Debug> Debug for InputPin<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> Drop for InputPin<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl HalPin for InputPin<bool>

Source§

type Storage = bool

The underlying storage type for the given pin Read more
Source§

fn name(&self) -> &str

Get the pin’s name
Source§

fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>

Get a mutable pointer to underlying shared memory storing this pin’s value
Source§

fn storage(&self) -> Result<&Self::Storage, StorageError>

Get a reference to the underlying shared memory storing the pin’s value
Source§

fn register( full_pin_name: &str, component_id: i32, ) -> Result<Self, PinRegisterError>

Register the pin with the LinuxCNC HAL Read more
Source§

fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>

Allocate memory using hal_malloc() for storing pin value in Read more
Source§

impl HalPin for InputPin<f64>

Source§

type Storage = f64

The underlying storage type for the given pin Read more
Source§

fn name(&self) -> &str

Get the pin’s name
Source§

fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>

Get a mutable pointer to underlying shared memory storing this pin’s value
Source§

fn storage(&self) -> Result<&Self::Storage, StorageError>

Get a reference to the underlying shared memory storing the pin’s value
Source§

fn register( full_pin_name: &str, component_id: i32, ) -> Result<Self, PinRegisterError>

Register the pin with the LinuxCNC HAL Read more
Source§

fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>

Allocate memory using hal_malloc() for storing pin value in Read more
Source§

impl HalPin for InputPin<i32>

Source§

type Storage = i32

The underlying storage type for the given pin Read more
Source§

fn name(&self) -> &str

Get the pin’s name
Source§

fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>

Get a mutable pointer to underlying shared memory storing this pin’s value
Source§

fn storage(&self) -> Result<&Self::Storage, StorageError>

Get a reference to the underlying shared memory storing the pin’s value
Source§

fn register( full_pin_name: &str, component_id: i32, ) -> Result<Self, PinRegisterError>

Register the pin with the LinuxCNC HAL Read more
Source§

fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>

Allocate memory using hal_malloc() for storing pin value in Read more
Source§

impl HalPin for InputPin<u32>

Source§

type Storage = u32

The underlying storage type for the given pin Read more
Source§

fn name(&self) -> &str

Get the pin’s name
Source§

fn storage_mut(&self) -> Result<&mut Self::Storage, StorageError>

Get a mutable pointer to underlying shared memory storing this pin’s value
Source§

fn storage(&self) -> Result<&Self::Storage, StorageError>

Get a reference to the underlying shared memory storing the pin’s value
Source§

fn register( full_pin_name: &str, component_id: i32, ) -> Result<Self, PinRegisterError>

Register the pin with the LinuxCNC HAL Read more
Source§

fn allocate_storage() -> Result<*mut *mut Self::Storage, StorageError>

Allocate memory using hal_malloc() for storing pin value in Read more
Source§

impl PinRead for InputPin<bool>

Source§

fn value(&self) -> Result<&<Self as HalPin>::Storage, StorageError>

Get the value of the pin
Source§

impl PinRead for InputPin<f64>

Source§

fn value(&self) -> Result<&<Self as HalPin>::Storage, StorageError>

Get the value of the pin
Source§

impl PinRead for InputPin<i32>

Source§

fn value(&self) -> Result<&<Self as HalPin>::Storage, StorageError>

Get the value of the pin
Source§

impl PinRead for InputPin<u32>

Source§

fn value(&self) -> Result<&<Self as HalPin>::Storage, StorageError>

Get the value of the pin

Auto Trait Implementations§

§

impl<S> Freeze for InputPin<S>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.