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
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.
pub fn new() -> Result<Self, &'static str>
sourcepub fn start_monitoring(&mut self)
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.
sourcepub fn stop_monitoring(&mut self)
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.