Trait embedded_simple_ui::switch::Switch

source ·
pub trait Switch<C: Clock> {
    // Required methods
    fn reset(&mut self);
    fn poll(&mut self, now: Instant<C>);
    fn has_changed(&self) -> bool;
    fn is_pressed(&self) -> bool;
    fn is_released(&self) -> bool;
    fn pressed_for(&self) -> Option<Milliseconds<C::T>>;
    fn released_for(&self) -> Option<Milliseconds<C::T>>;
    fn prev_state_lasted_for(&self) -> Milliseconds<C::T>;
    fn current_state(&self, now: Instant<C>) -> Milliseconds<C::T>;
    fn wait(&mut self, clock: &C);
}
Expand description

UI Switch

This advanced switch tracks it’s own state and can provide some additional information on it’s current state, how long the current state is in effect and how long the last state was in effect.

Implementors of this trait should own their resources. TODO: implement ability to set the default state for the user

Required Methods§

source

fn reset(&mut self)

Reset the switch state to initial values

source

fn poll(&mut self, now: Instant<C>)

Poll the switch for the hardware state changes

This must be done in regular intervals in order to make this abstraction work properly. There might be limits on what this abstraction can track based on how small / large the intervals are.

source

fn has_changed(&self) -> bool

Indicates that the switch state has has_changed since the last poll

source

fn is_pressed(&self) -> bool

Indicates that the switch is in pressed state

source

fn is_released(&self) -> bool

Indicates that the switch is in released state

source

fn pressed_for(&self) -> Option<Milliseconds<C::T>>

Returns the duration for which the switch has been pressed for

This is a wrapper for last_state_lasted_for that conveniently returns None if current state is not the opposite of the state the function name indicates

Returns None if the switch is not in released state

source

fn released_for(&self) -> Option<Milliseconds<C::T>>

Returns the duration for which the switch has been released for

This is a wrapper for last_state_lasted_for that conveniently returns None if current state is not the opposite of the state the function name indicates

Returns None if the switch is not in the pressed state

source

fn prev_state_lasted_for(&self) -> Milliseconds<C::T>

Returns the duration for which the last switch state lasted for

source

fn current_state(&self, now: Instant<C>) -> Milliseconds<C::T>

Returns the duration for which the current state is held

Requires an instant to be passed in to compare against the switch state

source

fn wait(&mut self, clock: &C)

Wait for the state to change

Polls the switch until it’s state has been changed

This operation is blocking

Implementors§

source§

impl<P: InputPin, S: PressedState, C: Clock> Switch<C> for PinSwitch<P, S, C>