pub struct KeyState<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> { /* private fields */ }
Expand description

The KeyState handles all of the decision making and state changes based on a high or low signal from a GPIO pin

Implementations§

source§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

source

pub fn new() -> Self

source

pub fn record(&mut self, on: bool) -> (State, bool, u32)

Record the GPIO read event and adjust debounce state machine accordingly

Returns: (State, idle, cycles_since_state_change)

source

pub fn state(&self) -> (State, bool, u32)

Returns thet current state and cycles since the state changed

(State, idle, cycles_since_state_change)

source

pub fn cycles_since_state_change(&self) -> u32

Number of cycles since the last state change 0 when the state first changes

source

pub fn idle(&self) -> bool

True if the switch is idle idle indicates the switch is off and there have been no events

Trait Implementations§

source§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> Clone for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

source§

fn clone(&self) -> KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> Default for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> Copy for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

Auto Trait Implementations§

§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> RefUnwindSafe for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> Send for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> Sync for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> Unpin for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

§

impl<const CSIZE: usize, const SCAN_PERIOD_US: u32, const DEBOUNCE_US: u32, const IDLE_MS: u32> UnwindSafe for KeyState<CSIZE, SCAN_PERIOD_US, DEBOUNCE_US, IDLE_MS>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.