From c5a929e51bb5b1b392561de4c09083c3152d7ca0 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 19 Nov 2024 17:26:24 -0500 Subject: [PATCH 1/2] fix keys.*.reset() behavior to send pressed instead of released events --- shared-module/keypad/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/keypad/__init__.c b/shared-module/keypad/__init__.c index e43c7bce4fb0..80e61f3ec7b6 100644 --- a/shared-module/keypad/__init__.c +++ b/shared-module/keypad/__init__.c @@ -140,7 +140,7 @@ void keypad_never_reset(keypad_scanner_obj_t *self) { void common_hal_keypad_generic_reset(void *self_in) { keypad_scanner_obj_t *self = self_in; size_t key_count = common_hal_keypad_generic_get_key_count(self); - memset(self->debounce_counter, self->debounce_threshold, key_count); + memset(self->debounce_counter, -self->debounce_threshold, key_count); keypad_scan_now(self, port_get_raw_ticks(NULL)); } From d08cecfeb82b7d13027d0275f0c2dc52886614e3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 19 Nov 2024 17:45:25 -0500 Subject: [PATCH 2/2] keypad: add doc that reset() can be used to determine keys held down at startup --- shared-bindings/keypad/KeyMatrix.c | 3 +++ shared-bindings/keypad/Keys.c | 3 +++ shared-bindings/keypad/ShiftRegisterKeys.c | 3 +++ shared-bindings/keypad_demux/DemuxKeyMatrix.c | 3 +++ 4 files changed, 12 insertions(+) diff --git a/shared-bindings/keypad/KeyMatrix.c b/shared-bindings/keypad/KeyMatrix.c index 7a8bb97247a5..b832d74bded4 100644 --- a/shared-bindings/keypad/KeyMatrix.c +++ b/shared-bindings/keypad/KeyMatrix.c @@ -159,6 +159,9 @@ static void check_for_deinit(keypad_keymatrix_obj_t *self) { //| """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 immediately cause //| a new key-pressed event to occur. +//| For instance, if you call `reset()` immediately after creating a `KeyMatrix` object +//| at the beginning of your program, the events it generates will let you determine which keys +//| were being held down at program start. //| """ //| ... diff --git a/shared-bindings/keypad/Keys.c b/shared-bindings/keypad/Keys.c index 208bc0a62d49..996f13d8a13c 100644 --- a/shared-bindings/keypad/Keys.c +++ b/shared-bindings/keypad/Keys.c @@ -147,6 +147,9 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(keypad_keys___exit___obj, 4, 4, keypa //| """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 immediately cause //| a new key-pressed event to occur. +//| For instance, if you call `reset()` immediately after creating a `Keys` object +//| at the beginning of your program, the events it generates will let you determine which keys +//| were being held down at program start. //| """ //| ... diff --git a/shared-bindings/keypad/ShiftRegisterKeys.c b/shared-bindings/keypad/ShiftRegisterKeys.c index e74dce0ac237..8508619d9874 100644 --- a/shared-bindings/keypad/ShiftRegisterKeys.c +++ b/shared-bindings/keypad/ShiftRegisterKeys.c @@ -201,6 +201,9 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(keypad_shiftregisterkeys___exit___obj //| """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 immediately cause //| a new key-pressed event to occur. +//| For instance, if you call `reset()` immediately after creating a `ShiftRegisterKeys` object +//| at the beginning of your program, the events it generates will let you determine which keys +//| were being held down at program start. //| """ //| ... diff --git a/shared-bindings/keypad_demux/DemuxKeyMatrix.c b/shared-bindings/keypad_demux/DemuxKeyMatrix.c index 9f6d65c3dd33..8c867aecee08 100644 --- a/shared-bindings/keypad_demux/DemuxKeyMatrix.c +++ b/shared-bindings/keypad_demux/DemuxKeyMatrix.c @@ -147,6 +147,9 @@ static void check_for_deinit(keypad_demux_demuxkeymatrix_obj_t *self) { //| """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 immediately cause //| a new key-pressed event to occur. +//| For instance, if you call `reset()` immediately after creating a `DemuxKeyMatrix` object +//| at the beginning of your program, the events it generates will let you determine which keys +//| were being held down at program start. //| """ //| ...