Struct aircontrol::AirControl

source ·
pub struct AirControl { /* private fields */ }
Expand description

Represents a struct for the AirControl coach and mini devices, allowing for monitoring of CO2 levels, temperature, and humidity.

§Fields

  • device: A thread-safe reference to the HID device interface.
  • callbacks: A list of callback functions to be called with updated sensor data.
  • running: A flag indicating whether the monitoring loop is currently running.
  • monitoring_thread: The thread, which reads the values and sends them to the callback functions

Implementations§

source§

impl AirControl

Initializes a new instance of the AirControl interface.

Attempts to create a HID API instance and open the specified device. On success, returns an AirControl object, otherwise returns an error string indicating the failure reason.

§Errors

Returns an error if the HID API instance cannot be created or the device cannot be opened.

source

pub fn new() -> Result<Self, &'static str>

source

pub fn start_monitoring(&mut self)

Starts the monitoring process in a separate thread.

Spawns a new thread and saves them in ’monitoring_thread. It continuously reads data from the device and invokes registered callbacks with the latest sensor readings. The loop runs until stop_monitoring` is called.

§Returns

A JoinHandle for the spawned thread, allowing the caller to manage the thread’s lifecycle.

source

pub fn stop_monitoring(&mut self)

Stops the monitoring process.

Sets the running flag to false, which signals the monitoring thread to terminate and waits for the thread to finish.

source

pub fn register_callback( &self, callback: Box<dyn Fn(DateTime<Utc>, u16, f32, f32) + Send> )

Registers a new callback function to be invoked with sensor data updates.

§Parameters
  • callback: A Callback function that takes sensor readings as parameters.

Auto Trait Implementations§

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>,

§

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>,

§

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.