Struct Parameter

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

A parameter that can be read and written by LinuxCNC

Supported parameter types are as follows

TypeStorageEquivalent linuxcnc_hal_sys function
Parameter<f64>f64hal_param_float_new
Parameter<u32>u32hal_param_u32_new
Parameter<i32>i32hal_param_s32_new
Parameter<bool>boolhal_param_bit_new

§Examples

§Create a parameter

This example creates an Parameter under demo-component.named-parameter.

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(())
}

Implementations§

Source§

impl Parameter<f64>

Source

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

Get the value of the parameter

Source

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

Set the value of the parameter

Source§

impl Parameter<u32>

Source

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

Get the value of the parameter

Source

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

Set the value of the parameter

Source§

impl Parameter<i32>

Source

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

Get the value of the parameter

Source

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

Set the value of the parameter

Source§

impl Parameter<bool>

Source

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

Get the value of the parameter

Source

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

Set the value of the parameter

Trait Implementations§

Source§

impl<S: Debug> Debug for Parameter<S>

Source§

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

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

impl<S> Drop for Parameter<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Parameter<S>

§

impl<S> RefUnwindSafe for Parameter<S>
where S: RefUnwindSafe,

§

impl<S> !Send for Parameter<S>

§

impl<S> !Sync for Parameter<S>

§

impl<S> Unpin for Parameter<S>

§

impl<S> UnwindSafe for Parameter<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.