pub struct SharedDeviceState { /* private fields */ }Expand description
Thread-safe device state container.
This struct provides thread-safe access to device state and allows for state change notifications.
Implementations§
Sourcepub fn new(device_info: DeviceInfo, device_data: DeviceData) -> Self
pub fn new(device_info: DeviceInfo, device_data: DeviceData) -> Self
Sourcepub fn setup_notifications(&self) -> Receiver<StateChangeType>
pub fn setup_notifications(&self) -> Receiver<StateChangeType>
Sourcepub fn status(&self) -> ThreadStatus
pub fn status(&self) -> ThreadStatus
Sourcepub fn set_running(&self, running: bool)
pub fn set_running(&self, running: bool)
Sourcepub fn set_paused(&self, paused: bool)
pub fn set_paused(&self, paused: bool)
Sourcepub fn update_from_device_with_notifications(&self, device: &PoKeysDevice)
pub fn update_from_device_with_notifications(&self, device: &PoKeysDevice)
Update the device state from a PoKeys device and detect changes.
§Parameters
device- The PoKeys device to update from.
Sourcepub fn update(&self, update_fn: impl FnOnce(&mut DeviceState))
pub fn update(&self, update_fn: impl FnOnce(&mut DeviceState))
§Parameters
update_fn- A function that updates the device state.
Sourcepub fn read<T>(&self, read_fn: impl FnOnce(&DeviceState) -> T) -> T
pub fn read<T>(&self, read_fn: impl FnOnce(&DeviceState) -> T) -> T
Sourcepub fn last_update(&self) -> u64
pub fn last_update(&self) -> u64
Sourcepub fn get_digital_input(&self, pin: u32) -> Option<bool>
pub fn get_digital_input(&self, pin: u32) -> Option<bool>
Sourcepub fn get_analog_input(&self, pin: u32) -> Option<u32>
pub fn get_analog_input(&self, pin: u32) -> Option<u32>
Sourcepub fn get_encoder_value(&self, encoder_index: u32) -> Option<i32>
pub fn get_encoder_value(&self, encoder_index: u32) -> Option<i32>
Sourcepub fn get_pwm_duty_cycle(&self, channel: usize) -> Option<u32>
pub fn get_pwm_duty_cycle(&self, channel: usize) -> Option<u32>
Sourcepub fn set_digital_output(&self, pin: u32, value: bool)
pub fn set_digital_output(&self, pin: u32, value: bool)
Set a digital output value.
§Parameters
pin- The pin number to set.value- The value to set (true for high, false for low).
Sourcepub fn set_analog_output(&self, pin: u32, value: u32)
pub fn set_analog_output(&self, pin: u32, value: u32)
Set an analog output value.
§Parameters
pin- The pin number to set.value- The value to set (0-4095 for 12-bit DAC).
Sourcepub fn set_pwm_duty_cycle(&self, channel: usize, duty: u32)
pub fn set_pwm_duty_cycle(&self, channel: usize, duty: u32)
Set a PWM duty cycle.
§Parameters
channel- The PWM channel to set.duty- The duty cycle to set (0-4095 for 12-bit PWM).
Sourcepub fn set_custom_value(&self, key: &str, value: &str)
pub fn set_custom_value(&self, key: &str, value: &str)
Sourcepub fn get_custom_value(&self, key: &str) -> Option<String>
pub fn get_custom_value(&self, key: &str) -> Option<String>
Sourcepub fn with_state<F, T>(&self, f: F) -> Twhere
F: FnOnce(&DeviceState) -> T,
pub fn with_state<F, T>(&self, f: F) -> Twhere
F: FnOnce(&DeviceState) -> T,
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more