Struct KeypadInput

Source
pub struct KeypadInput<'a, E> { /* private fields */ }
Expand description

A virtual embedded-hal input pin representing one key of the keypad.

A KeypadInput stores references to one row and one column pin. When you read from it with .is_low() or .is_high(), it secretly sets the column pin low, reads from the row pin, and then sets the column pin high again. The column pin is actually stored inside a RefCell in the keypad struct, so that multiple KeypadInputs can mutate the column pin’s state as needed, even though they only have a shared/immutable reference to it.

This has several implications.

  1. Reading from KeypadInputs is not reentrant. If we were in the middle of reading a KeypadInput and entered an interrupt service routine that read any KeypadInput of the same keypad, we might read an incorrect value or cause a panic.

  2. Reading from a KeypadInput is slower than reading from a real input pin, because it needs to change the output pin state twice for every read.

Implementations§

Source§

impl<'a, E> KeypadInput<'a, E>

Source

pub fn new( row: &'a dyn InputPin<Error = E>, col: &'a RefCell<dyn OutputPin<Error = E>>, ) -> Self

Create a new KeypadInput. For use in macros.

Trait Implementations§

Source§

impl<'a, E> InputPin for KeypadInput<'a, E>

Source§

fn is_high(&self) -> Result<bool, E>

Read the state of the key at this row and column. Not reentrant.

Source§

fn is_low(&self) -> Result<bool, E>

Read the state of the key at this row and column. Not reentrant.

Source§

type Error = E

Error type

Auto Trait Implementations§

§

impl<'a, E> Freeze for KeypadInput<'a, E>

§

impl<'a, E> !RefUnwindSafe for KeypadInput<'a, E>

§

impl<'a, E> !Send for KeypadInput<'a, E>

§

impl<'a, E> !Sync for KeypadInput<'a, E>

§

impl<'a, E> Unpin for KeypadInput<'a, E>

§

impl<'a, E> !UnwindSafe for KeypadInput<'a, E>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.