Skip to content

Fix keypad EventQueue len(); improve doc #10184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions shared-bindings/keypad/EventQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
//|

//| def get(self) -> Optional[Event]:
//| """Return the next key transition event. Return ``None`` if no events are pending.
//| """Remove the next key transition event from the `EventQueue` and return it.
//| Return ``None`` if no events are pending.
//|
//| Note that the queue size is limited; see ``max_events`` in the constructor of
//| a scanner such as `Keys` or `KeyMatrix`.
Expand All @@ -43,7 +44,7 @@ static mp_obj_t keypad_eventqueue_get(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(keypad_eventqueue_get_obj, keypad_eventqueue_get);

//| def get_into(self, event: Event) -> bool:
//| """Store the next key transition event in the supplied event, if available,
//| """Remove the next key transition event from the ``EventQueue`, store it in ``event``,
//| and return ``True``.
//| If there are no queued events, do not touch ``event`` and return ``False``.
//|
Expand Down
6 changes: 4 additions & 2 deletions shared-module/keypad/EventQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#define EVENT_PRESSED (1 << 15)
#define EVENT_KEY_NUM_MASK ((1 << 15) - 1)

#define EVENT_SIZE_BYTES (sizeof(uint16_t) + sizeof(mp_obj_t))

void common_hal_keypad_eventqueue_construct(keypad_eventqueue_obj_t *self, size_t max_events) {
// Event queue is 16-bit values.
ringbuf_alloc(&self->encoded_events, max_events * (sizeof(uint16_t) + sizeof(mp_obj_t)));
ringbuf_alloc(&self->encoded_events, max_events * EVENT_SIZE_BYTES);
self->overflowed = false;
self->event_handler = NULL;
}
Expand Down Expand Up @@ -63,7 +65,7 @@ void common_hal_keypad_eventqueue_clear(keypad_eventqueue_obj_t *self) {
}

size_t common_hal_keypad_eventqueue_get_length(keypad_eventqueue_obj_t *self) {
return ringbuf_num_filled(&self->encoded_events);
return ringbuf_num_filled(&self->encoded_events) / EVENT_SIZE_BYTES;
}

void common_hal_keypad_eventqueue_set_event_handler(keypad_eventqueue_obj_t *self, void (*event_handler)(keypad_eventqueue_obj_t *)) {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy