mcp23017_scanner

Scan a matrix keyboard with an API modelled after the keypad module

  • Author(s): Neradoc

Implementation Notes

Software and Dependencies:

class mcp23017_scanner.Event(key: int, pressed: bool, timestamp: int = None)

A key transition event.

Parameters:
  • key_number (int) – the key number

  • pressed (bool) – True if the key was pressed; False if it was released.

  • timestamp (int) – The time in milliseconds that the keypress occurred in the supervisor.ticks_ms time system. If specified as None, the current value of supervisor.ticks_ms is used.

key_number

The key number.

pressed

True if the event represents a key down (pressed) transition. The opposite of released.

property released: bool

True if the event represents a key up (released) transition. The opposite of pressed.

timestamp

The timestamp.

class mcp23017_scanner.EventQueue

A queue of Event objects, filled by a scanner.

append(event: Event) None

Append an event at the end of the queue

clear() None

Clear any queued key transition events.

get() Event

Return the next key transition event. Return None if no events are pending.

get_into(event: Event) bool

Store the next key transition event in the supplied event, if available, and return True. If there are no queued events, do not touch event and return False. Note: in python this does not optimize to avoid allocating.

class mcp23017_scanner.McpKeysScanner(mcp: any, pins: Iterable[int], irq: Pin | None = None)

Class to scan a key per pin of the MCP chip.

Pins 0-7 are on port A. Pins 8-15 are on port B.

class mcp23017_scanner.McpMatrixScanner(mcp: any, row_pins: Iterable[int], column_pins: Iterable[int], irq: Pin | None = None)

Class to scan a matrix of keys connected to the MCP chip.

Columns are on port A and inputs. Rows are on port B and outputs.

key_number_to_row_column(key_number: int) Tuple[int]

Convert key number to row, column

row_column_to_key_number(row: int, column: int) int

Convert row, column to key number

class mcp23017_scanner.McpScanner(mcp: any, irq: Pin | None = None)

Base class for MCP scanners.

property events

The EventQueue associated with this Scanner. (read-only)

deinit() None

Release the IRQ pin

property key_count: int

The number of keys that are being scanned. (read-only)

reset() None

Reset the internal state of the scanner to assume that all keys are now released. Any key that is already pressed at the time of this call will therefore cause a new key-pressed event to occur on the next scan.

update() None

Run the scan and create events in the event queue.