keypad: scan immediately on construct, .reset()
This commit is contained in:
parent
47d3d0d7f8
commit
203dad11bf
@ -37,6 +37,8 @@
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
static void keypad_keymatrix_scan_now(keypad_keymatrix_obj_t *self, uint64_t now);
|
||||
|
||||
static mp_uint_t row_column_to_key_number(keypad_keymatrix_obj_t *self, mp_uint_t row, mp_uint_t column) {
|
||||
return row * self->column_digitalinouts->len + column;
|
||||
}
|
||||
@ -74,10 +76,10 @@ void common_hal_keypad_keymatrix_construct(keypad_keymatrix_obj_t *self, mp_uint
|
||||
self->events = events;
|
||||
|
||||
self->interval_ticks = (mp_uint_t)(interval * 1024); // interval * 1000 * (1024/1000)
|
||||
self->last_scan_ticks = port_get_raw_ticks(NULL);
|
||||
|
||||
// Add self to the list of active keypad scanners.
|
||||
keypad_register_scanner((keypad_scanner_obj_t *)self);
|
||||
keypad_keymatrix_scan_now(self, port_get_raw_ticks(NULL));
|
||||
}
|
||||
|
||||
void common_hal_keypad_keymatrix_deinit(keypad_keymatrix_obj_t *self) {
|
||||
@ -132,10 +134,9 @@ mp_obj_t common_hal_keypad_keymatrix_get_events(keypad_keymatrix_obj_t *self) {
|
||||
void common_hal_keypad_keymatrix_reset(keypad_keymatrix_obj_t *self) {
|
||||
const size_t key_count = common_hal_keypad_keymatrix_get_key_count(self);
|
||||
|
||||
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
|
||||
memset(self->previously_pressed, false, key_count);
|
||||
memset(self->currently_pressed, false, key_count);
|
||||
supervisor_release_lock(&keypad_scanners_linked_list_lock);
|
||||
keypad_keymatrix_scan_now(self, port_get_raw_ticks(NULL));
|
||||
}
|
||||
|
||||
void keypad_keymatrix_scan(keypad_keymatrix_obj_t *self) {
|
||||
@ -145,6 +146,10 @@ void keypad_keymatrix_scan(keypad_keymatrix_obj_t *self) {
|
||||
return;
|
||||
}
|
||||
|
||||
keypad_keymatrix_scan_now(self, now);
|
||||
}
|
||||
|
||||
static void keypad_keymatrix_scan_now(keypad_keymatrix_obj_t *self, uint64_t now) {
|
||||
self->last_scan_ticks = now;
|
||||
|
||||
mp_obj_t timestamp = supervisor_ticks_ms();
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
static void keypad_keys_scan_now(keypad_keys_obj_t *self, uint64_t now);
|
||||
|
||||
void common_hal_keypad_keys_construct(keypad_keys_obj_t *self, mp_uint_t num_pins, const mcu_pin_obj_t *pins[], bool value_when_pressed, bool pull, mp_float_t interval, size_t max_events) {
|
||||
mp_obj_t dios[num_pins];
|
||||
|
||||
@ -64,6 +66,7 @@ void common_hal_keypad_keys_construct(keypad_keys_obj_t *self, mp_uint_t num_pin
|
||||
|
||||
// Add self to the list of active keypad scanners.
|
||||
keypad_register_scanner((keypad_scanner_obj_t *)self);
|
||||
keypad_keys_scan_now(self, port_get_raw_ticks(NULL));
|
||||
}
|
||||
|
||||
void common_hal_keypad_keys_deinit(keypad_keys_obj_t *self) {
|
||||
@ -96,10 +99,9 @@ mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self) {
|
||||
void common_hal_keypad_keys_reset(keypad_keys_obj_t *self) {
|
||||
const size_t key_count = common_hal_keypad_keys_get_key_count(self);
|
||||
|
||||
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
|
||||
memset(self->previously_pressed, false, key_count);
|
||||
memset(self->currently_pressed, false, key_count);
|
||||
supervisor_release_lock(&keypad_scanners_linked_list_lock);
|
||||
keypad_keys_scan_now(self, port_get_raw_ticks(NULL));
|
||||
}
|
||||
|
||||
void keypad_keys_scan(keypad_keys_obj_t *self) {
|
||||
@ -109,6 +111,10 @@ void keypad_keys_scan(keypad_keys_obj_t *self) {
|
||||
return;
|
||||
}
|
||||
|
||||
keypad_keys_scan_now(self, now);
|
||||
}
|
||||
|
||||
static void keypad_keys_scan_now(keypad_keys_obj_t *self, uint64_t now) {
|
||||
self->last_scan_ticks = now;
|
||||
|
||||
const size_t key_count = common_hal_keypad_keys_get_key_count(self);
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
static void keypad_shiftregisterkeys_scan_now(keypad_shiftregisterkeys_obj_t *self, uint64_t now);
|
||||
|
||||
void common_hal_keypad_shiftregisterkeys_construct(keypad_shiftregisterkeys_obj_t *self, const mcu_pin_obj_t *clock_pin, const mcu_pin_obj_t *data_pin, const mcu_pin_obj_t *latch_pin, bool value_to_latch, size_t key_count, bool value_when_pressed, mp_float_t interval, size_t max_events) {
|
||||
|
||||
digitalio_digitalinout_obj_t *clock = m_new_obj(digitalio_digitalinout_obj_t);
|
||||
@ -63,7 +65,6 @@ void common_hal_keypad_shiftregisterkeys_construct(keypad_shiftregisterkeys_obj_
|
||||
self->key_count = key_count;
|
||||
|
||||
self->interval_ticks = (mp_uint_t)(interval * 1024); // interval * 1000 * (1024/1000)
|
||||
self->last_scan_ticks = port_get_raw_ticks(NULL);
|
||||
|
||||
keypad_eventqueue_obj_t *events = m_new_obj(keypad_eventqueue_obj_t);
|
||||
events->base.type = &keypad_eventqueue_type;
|
||||
@ -72,6 +73,7 @@ void common_hal_keypad_shiftregisterkeys_construct(keypad_shiftregisterkeys_obj_
|
||||
|
||||
// Add self to the list of active keypad scanners.
|
||||
keypad_register_scanner((keypad_scanner_obj_t *)self);
|
||||
keypad_shiftregisterkeys_scan_now(self, port_get_raw_ticks(NULL));
|
||||
}
|
||||
|
||||
void common_hal_keypad_shiftregisterkeys_deinit(keypad_shiftregisterkeys_obj_t *self) {
|
||||
@ -108,10 +110,9 @@ mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys
|
||||
void common_hal_keypad_shiftregisterkeys_reset(keypad_shiftregisterkeys_obj_t *self) {
|
||||
const size_t key_count = common_hal_keypad_shiftregisterkeys_get_key_count(self);
|
||||
|
||||
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
|
||||
memset(self->previously_pressed, false, key_count);
|
||||
memset(self->currently_pressed, false, key_count);
|
||||
supervisor_release_lock(&keypad_scanners_linked_list_lock);
|
||||
keypad_shiftregisterkeys_scan_now(self, port_get_raw_ticks(NULL));
|
||||
}
|
||||
|
||||
void keypad_shiftregisterkeys_scan(keypad_shiftregisterkeys_obj_t *self) {
|
||||
@ -121,6 +122,10 @@ void keypad_shiftregisterkeys_scan(keypad_shiftregisterkeys_obj_t *self) {
|
||||
return;
|
||||
}
|
||||
|
||||
keypad_shiftregisterkeys_scan_now(self, now);
|
||||
}
|
||||
|
||||
static void keypad_shiftregisterkeys_scan_now(keypad_shiftregisterkeys_obj_t *self, uint64_t now) {
|
||||
self->last_scan_ticks = now;
|
||||
|
||||
mp_obj_t timestamp = supervisor_ticks_ms();
|
||||
|
Loading…
Reference in New Issue
Block a user