[][src]Struct ndless_async::keypad::KeypadListener

pub struct KeypadListener<'a> { /* fields omitted */ }

Polls the keypad.

use ndless_async::task::{block_on, AsyncListeners};
use ndless_async::keypad::{KeypadListener, KeyState};
use ndless_async::StreamExt;

let listeners = AsyncListeners::new();
block_on(&listeners, async {
    let keypad = KeypadListener::new(&listeners.timer());
    let mut stream = keypad.stream();
    while let Some(event) = stream.next().await {
        println!(
            "Key {:?} was {}",
            event.key,
            if event.state == KeyState::Released {
                "released"
            } else {
                "pressed"
            }
        );
    }
});

Implementations

impl<'a> KeypadListener<'a>[src]

pub fn new(timer_listener: &'a TimerListener) -> Self[src]

Creates a new keypad listener that polls the keypad 30 times per second. Use the new_with_* series of functions to change the polling rate. You may also poll the keypad manually by using new_manually_polled.

pub fn new_with_hz(timer_listener: &'a TimerListener, hz: u32) -> Self[src]

Creates a new keypad listener that polls the keypad with the specified number of events per second.

pub fn new_with_ms(timer_listener: &'a TimerListener, dur: u32) -> Self[src]

Creates a new keypad listener that polls the keypad every dur milliseconds.

pub fn new_with_rate(timer_listener: &'a TimerListener, dur: Duration) -> Self[src]

Creates a new keypad listener that polls the keypad with the specified interval.

pub fn new_with_ticks(timer_listener: &'a TimerListener, ticks: u32) -> Self[src]

Creates a new keypad listener that polls the keypad every specified ticks.

pub fn new_manually_polled() -> Self[src]

Creates a new keypad listener that isn't automatically polled. You'll need to use poll periodically to poll the keypad.

pub fn poll(&self)[src]

Polls the keypad. You shouldn't have to use this normally.

pub fn stream(&self) -> KeyStream[src]

Each call to stream returns a unique stream, meaning that calling it from different tasks will allow each task to receive every event. A buffer of 100 keypress events is allocated. Use stream_with_buffer to specify a custom size.

Warning

Don't use this function in a loop. You should call stream before the loop, or use a stream combinator such as for_each. Failure to do so will result in lost events and less efficient code.

pub fn stream_with_buffer(&self, size: usize) -> KeyStream[src]

This is the same as stream, except that it allows specifying a buffer size other than the default of 100.

Warning

Don't use this function in a loop. You should call stream_with_buffer before the loop, or use a stream combinator such as for_each. Failure to do so will result in lost events and less efficient code.

pub fn list_keys(&self) -> Ref<Vec<Key>>[src]

Returns a Ref to the keys that are currently pressed. You must drop this reference either explicitly or by ending the current scope before .awaiting something. The program will crash otherwise.

Auto Trait Implementations

impl<'a> !Send for KeypadListener<'a>

impl<'a> !Sync for KeypadListener<'a>

impl<'a> Unpin for KeypadListener<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.