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§
sourcefn poll(&mut self, now: Instant<C>)
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.
sourcefn has_changed(&self) -> bool
fn has_changed(&self) -> bool
Indicates that the switch state has has_changed since the last poll
sourcefn is_pressed(&self) -> bool
fn is_pressed(&self) -> bool
Indicates that the switch is in pressed state
sourcefn is_released(&self) -> bool
fn is_released(&self) -> bool
Indicates that the switch is in released state
sourcefn pressed_for(&self) -> Option<Milliseconds<C::T>>
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
sourcefn released_for(&self) -> Option<Milliseconds<C::T>>
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
sourcefn prev_state_lasted_for(&self) -> Milliseconds<C::T>
fn prev_state_lasted_for(&self) -> Milliseconds<C::T>
Returns the duration for which the last switch state lasted for
sourcefn current_state(&self, now: Instant<C>) -> Milliseconds<C::T>
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