pub struct ButtonMatrix<ROW, COL, NAME, const ROWS: usize, const COLS: usize> { /* private fields */ }Expand description
Debounced scanner for a rectangular button matrix.
ROWS input pins are read while each of the COLS output pins is selected
one at a time. Each key has an independent debouncer, so multiple keys can
be pressed and released during the same scan.
Implementations§
Source§impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> ButtonMatrix<ROW, COL, NAME, ROWS, COLS>
impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> ButtonMatrix<ROW, COL, NAME, ROWS, COLS>
Sourcepub const fn new(
rows: [ROW; ROWS],
columns: [COL; COLS],
names: [[NAME; COLS]; ROWS],
) -> Self
pub const fn new( rows: [ROW; ROWS], columns: [COL; COLS], names: [[NAME; COLS]; ROWS], ) -> Self
Creates a matrix using MatrixConfig::active_low.
Sourcepub const fn with_config(
rows: [ROW; ROWS],
columns: [COL; COLS],
names: [[NAME; COLS]; ROWS],
config: MatrixConfig,
) -> Self
pub const fn with_config( rows: [ROW; ROWS], columns: [COL; COLS], names: [[NAME; COLS]; ROWS], config: MatrixConfig, ) -> Self
Creates a matrix with a custom configuration.
Sourcepub const fn config(&self) -> MatrixConfig
pub const fn config(&self) -> MatrixConfig
Returns the current configuration.
Sourcepub fn set_config(&mut self, config: MatrixConfig)
pub fn set_config(&mut self, config: MatrixConfig)
Replaces the whole configuration.
Sourcepub const fn debounce_ms(&self) -> Millis
pub const fn debounce_ms(&self) -> Millis
Returns the current debounce time.
Sourcepub fn set_debounce_ms(&mut self, debounce_ms: Millis)
pub fn set_debounce_ms(&mut self, debounce_ms: Millis)
Sets the debounce time.
Sourcepub const fn row_active_level(&self) -> ActiveLevel
pub const fn row_active_level(&self) -> ActiveLevel
Returns the current row active level.
Sourcepub fn set_row_active_level(&mut self, row_active_level: ActiveLevel)
pub fn set_row_active_level(&mut self, row_active_level: ActiveLevel)
Sets the row active level.
Sourcepub const fn column_drive(&self) -> ColumnDrive
pub const fn column_drive(&self) -> ColumnDrive
Returns the current column drive polarity.
Sourcepub fn set_column_drive(&mut self, column_drive: ColumnDrive)
pub fn set_column_drive(&mut self, column_drive: ColumnDrive)
Sets the column drive polarity.
Sourcepub fn name(&self, row: usize, column: usize) -> Option<NAME>where
NAME: Copy,
pub fn name(&self, row: usize, column: usize) -> Option<NAME>where
NAME: Copy,
Returns the name assigned to a key.
Sourcepub fn state(&self, row: usize, column: usize) -> Option<ButtonState>
pub fn state(&self, row: usize, column: usize) -> Option<ButtonState>
Returns the stable debounced state of a key.
Sourcepub fn is_pressed(&self, row: usize, column: usize) -> bool
pub fn is_pressed(&self, row: usize, column: usize) -> bool
Returns true if the key is currently stably pressed.
Sourcepub fn held_ms(
&self,
row: usize,
column: usize,
now_ms: Millis,
) -> Option<Millis>
pub fn held_ms( &self, row: usize, column: usize, now_ms: Millis, ) -> Option<Millis>
Returns the current debounced hold time for a key, or None if the key
is released or the indexes are out of range.
Sourcepub const fn pressed_keys(
&self,
now_ms: Millis,
) -> PressedKeys<'_, ROW, COL, NAME, ROWS, COLS> ⓘ
pub const fn pressed_keys( &self, now_ms: Millis, ) -> PressedKeys<'_, ROW, COL, NAME, ROWS, COLS> ⓘ
Iterates over all keys that are currently stably pressed.
Sourcepub fn rows_mut(&mut self) -> &mut [ROW; ROWS]
pub fn rows_mut(&mut self) -> &mut [ROW; ROWS]
Returns mutable access to the row pins.
Sourcepub fn columns_mut(&mut self) -> &mut [COL; COLS]
pub fn columns_mut(&mut self) -> &mut [COL; COLS]
Returns mutable access to the column pins.
Sourcepub fn into_parts(self) -> ([ROW; ROWS], [COL; COLS], [[NAME; COLS]; ROWS])
pub fn into_parts(self) -> ([ROW; ROWS], [COL; COLS], [[NAME; COLS]; ROWS])
Returns the inner pins and the key-name matrix.
Source§impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> ButtonMatrix<ROW, COL, NAME, ROWS, COLS>
impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> ButtonMatrix<ROW, COL, NAME, ROWS, COLS>
Sourcepub fn scan(
&mut self,
now_ms: Millis,
) -> Result<ButtonMatrixEvents<NAME, ROWS, COLS>, MatrixError<ROW::Error, COL::Error>>
pub fn scan( &mut self, now_ms: Millis, ) -> Result<ButtonMatrixEvents<NAME, ROWS, COLS>, MatrixError<ROW::Error, COL::Error>>
Scans the whole matrix once and returns all debounced transition events.
The method drives one column active at a time, reads every row, updates independent debouncers for all keys, and then moves to the next column. It does not allocate and it does not wait internally.