File tree 2 files changed +7
-4
lines changed
2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 23
23
//|
24
24
25
25
//| 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.
27
28
//|
28
29
//| Note that the queue size is limited; see ``max_events`` in the constructor of
29
30
//| a scanner such as `Keys` or `KeyMatrix`.
@@ -43,7 +44,7 @@ static mp_obj_t keypad_eventqueue_get(mp_obj_t self_in) {
43
44
MP_DEFINE_CONST_FUN_OBJ_1 (keypad_eventqueue_get_obj , keypad_eventqueue_get );
44
45
45
46
//| 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`` ,
47
48
//| and return ``True``.
48
49
//| If there are no queued events, do not touch ``event`` and return ``False``.
49
50
//|
Original file line number Diff line number Diff line change 13
13
#define EVENT_PRESSED (1 << 15)
14
14
#define EVENT_KEY_NUM_MASK ((1 << 15) - 1)
15
15
16
+ #define EVENT_SIZE_BYTES (sizeof(uint16_t) + sizeof(mp_obj_t))
17
+
16
18
void common_hal_keypad_eventqueue_construct (keypad_eventqueue_obj_t * self , size_t max_events ) {
17
19
// 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 );
19
21
self -> overflowed = false;
20
22
self -> event_handler = NULL ;
21
23
}
@@ -63,7 +65,7 @@ void common_hal_keypad_eventqueue_clear(keypad_eventqueue_obj_t *self) {
63
65
}
64
66
65
67
size_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 ;
67
69
}
68
70
69
71
void 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