Struct esp32_simple::button::Button

source ·
pub struct Button<'a, T, MODE, TR>
where T: InputPin, MODE: InputMode, TR: Trigger,
{ /* private fields */ }
Expand description

Represents a button with a notifier and a GPIO pin.

§Type Parameters

  • 'a - Lifetime of the button.
  • T - Type of the GPIO pin.
  • MODE - Input mode of the GPIO pin.
  • TR - The trigger type implementing the Trigger trait.

Implementations§

source§

impl<'a, T, MODE, TR> Button<'a, T, MODE, TR>
where T: InputPin, MODE: InputMode, TR: Trigger,

source

pub fn new( notifier: Notifier<TR>, trigger: &'static TR, pin: PinDriver<'a, T, MODE>, state: Arc<Mutex<State>>, ) -> Result<Self>

Creates a new Button instance.

§Arguments
  • notifier - A notifier to send button press events.
  • trigger - The trigger to emit when the button is pressed.
  • pin - A GPIO pin driver.
  • state - Shared state of the button.
§Returns

A new Button instance.

§Errors

Returns an error if the button cannot be initialized.

Trait Implementations§

source§

impl<T, MODE, TR> Poller for Button<'_, T, MODE, TR>
where T: InputPin, MODE: InputMode, TR: Trigger,

source§

fn poll(&mut self) -> Result<!>

Polls the button for state changes.

This function continuously checks the button state and notifies when it is pressed.

§Errors

Returns an error if the notifier fails or if the state cannot be toggled.

source§

impl<T, MODE, TR> Switch for Button<'_, T, MODE, TR>
where T: InputPin, MODE: InputMode, TR: Trigger,

source§

fn toggle(&mut self) -> Result<()>

Toggles the state of the button.

§Returns

Ok(()) on success.

§Errors

Returns an error if the mutex lock cannot be acquired.

Auto Trait Implementations§

§

impl<'a, T, MODE, TR> Freeze for Button<'a, T, MODE, TR>
where T: Freeze,

§

impl<'a, T, MODE, TR> RefUnwindSafe for Button<'a, T, MODE, TR>
where TR: RefUnwindSafe, T: RefUnwindSafe, MODE: RefUnwindSafe,

§

impl<'a, T, MODE, TR> Send for Button<'a, T, MODE, TR>

§

impl<'a, T, MODE, TR> Sync for Button<'a, T, MODE, TR>
where T: Sync, MODE: Sync,

§

impl<'a, T, MODE, TR> Unpin for Button<'a, T, MODE, TR>
where TR: Unpin, T: Unpin, MODE: Unpin,

§

impl<'a, T, MODE, TR> !UnwindSafe for Button<'a, T, MODE, TR>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.