pub struct SwitchManager { /* private fields */ }Expand description
Switch manager for obniz board switch
Implementations§
Source§impl SwitchManager
impl SwitchManager
pub fn new(obniz: Obniz) -> Self
Sourcepub async fn get_state(&self) -> ObnizResult<SwitchState>
pub async fn get_state(&self) -> ObnizResult<SwitchState>
Get current switch state
Sourcepub async fn is_pressed(&self) -> ObnizResult<bool>
pub async fn is_pressed(&self) -> ObnizResult<bool>
Check if switch is currently pressed (any direction)
Sourcepub async fn is_pressed_direction(
&self,
direction: SwitchState,
) -> ObnizResult<bool>
pub async fn is_pressed_direction( &self, direction: SwitchState, ) -> ObnizResult<bool>
Check if switch is pressed in specific direction
Sourcepub async fn on_change<F>(&self, callback: F) -> ObnizResult<()>
pub async fn on_change<F>(&self, callback: F) -> ObnizResult<()>
Register callback for switch state changes
Sourcepub async fn on_push<F>(&self, callback: F) -> ObnizResult<()>
pub async fn on_push<F>(&self, callback: F) -> ObnizResult<()>
Register callback for push events only
Sourcepub async fn on_release<F>(&self, callback: F) -> ObnizResult<()>
pub async fn on_release<F>(&self, callback: F) -> ObnizResult<()>
Register callback for release events
Sourcepub async fn on_left<F>(&self, callback: F) -> ObnizResult<()>
pub async fn on_left<F>(&self, callback: F) -> ObnizResult<()>
Register callback for left direction events
Sourcepub async fn on_right<F>(&self, callback: F) -> ObnizResult<()>
pub async fn on_right<F>(&self, callback: F) -> ObnizResult<()>
Register callback for right direction events
Sourcepub async fn on_any_press<F>(&self, callback: F) -> ObnizResult<()>
pub async fn on_any_press<F>(&self, callback: F) -> ObnizResult<()>
Register callback for any press event (push, left, or right)
Sourcepub fn remove_callback(&self) -> ObnizResult<()>
pub fn remove_callback(&self) -> ObnizResult<()>
Remove switch callback
Sourcepub async fn wait_for_state(
&self,
target_state: SwitchState,
timeout_ms: Option<u64>,
) -> ObnizResult<()>
pub async fn wait_for_state( &self, target_state: SwitchState, timeout_ms: Option<u64>, ) -> ObnizResult<()>
Wait for specific switch state (blocking until state is reached)
Sourcepub async fn wait_for_press(
&self,
timeout_ms: Option<u64>,
) -> ObnizResult<SwitchState>
pub async fn wait_for_press( &self, timeout_ms: Option<u64>, ) -> ObnizResult<SwitchState>
Wait for any press event
Sourcepub async fn wait_for_release(&self, timeout_ms: Option<u64>) -> ObnizResult<()>
pub async fn wait_for_release(&self, timeout_ms: Option<u64>) -> ObnizResult<()>
Wait for release event
Trait Implementations§
Source§impl Clone for SwitchManager
impl Clone for SwitchManager
Auto Trait Implementations§
impl !RefUnwindSafe for SwitchManager
impl !UnwindSafe for SwitchManager
impl Freeze for SwitchManager
impl Send for SwitchManager
impl Sync for SwitchManager
impl Unpin for SwitchManager
impl UnsafeUnpin for SwitchManager
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