circuitpython/shared-bindings/keypad
Jeff Epler 76f03a2bee
Make keypad select/poll'able for better async
This allows a small wrapper class to be written
```py
class AsyncEventQueue:
    def __init__(self, events):
        self._events = events

    async def __await__(self):
        yield asyncio.core._io_queue.queue_read(self._events)
        return self._events.get()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        pass

```
and used to just "await" the next event:
```py
async def key_task():
    print("waiting for keypresses")
    with keypad.KeyMatrix([board.D4], [board.D5]) as keys, AsyncEventQueue(keys.events) as ev:
        while True:
            print(await ev)
```

Because checking the empty status of the EventQueue does not enter
CircuitPython bytecode, it's assumed (but not measured) that this is
more efficient than an equivalent loop with an `await async.sleep(0)`
yield and introduces less latency than any non-zero sleep value.
2022-08-09 21:48:27 -05:00
..
Event.c Make MP_PROPERTY_GETTER / _GETSET fully declare the property 2022-05-03 08:48:53 -05:00
Event.h keypad: Event: add timestamp. 2021-09-16 21:08:05 -05:00
EventQueue.c Make keypad select/poll'able for better async 2022-08-09 21:48:27 -05:00
EventQueue.h many renamings; add overflowed flag to EventQuque 2021-06-23 09:57:15 -04:00
KeyMatrix.c fix the keypad doc 2022-04-15 21:51:40 +02:00
KeyMatrix.h refactor keypad to share more code 2022-04-05 14:50:30 -05:00
Keys.c refactor keypad to share more code 2022-04-05 14:50:30 -05:00
Keys.h refactor keypad to share more code 2022-04-05 14:50:30 -05:00
ShiftRegisterKeys.c refactor keypad to share more code 2022-04-05 14:50:30 -05:00
ShiftRegisterKeys.h refactor keypad to share more code 2022-04-05 14:50:30 -05:00
__init__.c adding links in docs 2022-07-11 11:04:06 -05:00
__init__.h refactor keypad to share more code 2022-04-05 14:50:30 -05:00