File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 2323//|
2424
2525//| def get(self) -> Optional[Event]:
26- //| """Return the next key transition event. Return ``None`` if no events are pending.
26+ //| """Remove the next key transition event from the `EventQueue` and return it.
27+ //| Return ``None`` if no events are pending.
2728//|
2829//| Note that the queue size is limited; see ``max_events`` in the constructor of
2930//| a scanner such as `Keys` or `KeyMatrix`.
@@ -43,7 +44,7 @@ static mp_obj_t keypad_eventqueue_get(mp_obj_t self_in) {
4344MP_DEFINE_CONST_FUN_OBJ_1 (keypad_eventqueue_get_obj , keypad_eventqueue_get );
4445
4546//| def get_into(self, event: Event) -> bool:
46- //| """Store the next key transition event in the supplied event, if available ,
47+ //| """Remove the next key transition event from the ``EventQueue`, store it in ``event`` ,
4748//| and return ``True``.
4849//| If there are no queued events, do not touch ``event`` and return ``False``.
4950//|
Original file line number Diff line number Diff line change 1313#define EVENT_PRESSED (1 << 15)
1414#define EVENT_KEY_NUM_MASK ((1 << 15) - 1)
1515
16+ #define EVENT_SIZE_BYTES (sizeof(uint16_t) + sizeof(mp_obj_t))
17+
1618void common_hal_keypad_eventqueue_construct (keypad_eventqueue_obj_t * self , size_t max_events ) {
1719 // Event queue is 16-bit values.
18- ringbuf_alloc (& self -> encoded_events , max_events * ( sizeof ( uint16_t ) + sizeof ( mp_obj_t )) );
20+ ringbuf_alloc (& self -> encoded_events , max_events * EVENT_SIZE_BYTES );
1921 self -> overflowed = false;
2022 self -> event_handler = NULL ;
2123}
@@ -63,7 +65,7 @@ void common_hal_keypad_eventqueue_clear(keypad_eventqueue_obj_t *self) {
6365}
6466
6567size_t common_hal_keypad_eventqueue_get_length (keypad_eventqueue_obj_t * self ) {
66- return ringbuf_num_filled (& self -> encoded_events );
68+ return ringbuf_num_filled (& self -> encoded_events ) / EVENT_SIZE_BYTES ;
6769}
6870
6971void common_hal_keypad_eventqueue_set_event_handler (keypad_eventqueue_obj_t * self , void (* event_handler )(keypad_eventqueue_obj_t * )) {
You can’t perform that action at this time.
0 commit comments