mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-21 09:13:42 +00:00
bug fix fast pressing multiple buttons + clean up scanI2CTwoWire.cpp
This commit is contained in:
parent
7415b25e2f
commit
92b3b208c4
@ -10,11 +10,6 @@
|
||||
#include "meshUtils.h" // vformat
|
||||
#endif
|
||||
|
||||
// AXP192 and AXP2101 have the same device address, we just need to identify it in Power.cpp
|
||||
//#ifndef XPOWERS_AXP192_AXP2101_ADDRESS
|
||||
//#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
|
||||
//#endif
|
||||
|
||||
bool in_array(uint8_t *array, int size, uint8_t lookfor)
|
||||
{
|
||||
int i;
|
||||
@ -230,9 +225,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||
#ifdef HAS_NCP5623
|
||||
SCAN_SIMPLE_CASE(NCP5623_ADDR, NCP5623, "NCP5623", (uint8_t)addr.address);
|
||||
#endif
|
||||
//#ifdef HAS_PMU
|
||||
// SCAN_SIMPLE_CASE(XPOWERS_AXP192_AXP2101_ADDRESS, PMU_AXP192_AXP2101, "AXP192/AXP2101", (uint8_t)addr.address)
|
||||
//#endif
|
||||
|
||||
case BME_ADDR:
|
||||
case BME_ADDR_ALTERNATE:
|
||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xD0), 1); // GET_ID
|
||||
|
@ -134,7 +134,7 @@ unsigned char TCA8418LongPressMap[_TCA8418_NUM_KEYS] = {
|
||||
_TCA8418_NONE, // 7
|
||||
_TCA8418_DOWN, // 8
|
||||
_TCA8418_NONE, // 9
|
||||
_TCA8418_NONE, // *
|
||||
_TCA8418_BSP, // *
|
||||
_TCA8418_NONE, // 0
|
||||
_TCA8418_NONE, // #
|
||||
};
|
||||
@ -142,14 +142,13 @@ unsigned char TCA8418LongPressMap[_TCA8418_NUM_KEYS] = {
|
||||
#define _TCA8418_LONG_PRESS_THRESHOLD 2000
|
||||
#define _TCA8418_MULTI_TAP_THRESHOLD 750
|
||||
|
||||
// #define LAYOUT Adafruit3x4
|
||||
|
||||
|
||||
|
||||
TCA8418Keyboard::TCA8418Keyboard() : m_wire(nullptr), m_addr(0), readCallback(nullptr), writeCallback(nullptr)
|
||||
{
|
||||
state = Init;
|
||||
last_key = -1;
|
||||
next_key = -1;
|
||||
should_backspace = false;
|
||||
last_tap = 0L;
|
||||
char_idx = 0;
|
||||
tap_interval = 0;
|
||||
@ -330,8 +329,10 @@ void TCA8418Keyboard::pressed(uint8_t key)
|
||||
// Check if the key is the same as the last one or if the time interval has passed
|
||||
if (next_key != last_key || tap_interval > _TCA8418_MULTI_TAP_THRESHOLD) {
|
||||
char_idx = 0; // Reset char index if new key or long press
|
||||
should_backspace = false; // dont backspace on new key
|
||||
} else {
|
||||
char_idx += 1; // Cycle through characters if same key pressed
|
||||
should_backspace = true; // allow backspace on same key
|
||||
}
|
||||
|
||||
// Store the current key as the last key
|
||||
@ -354,7 +355,7 @@ void TCA8418Keyboard::released()
|
||||
uint32_t now = millis();
|
||||
int32_t held_interval = now - last_tap;
|
||||
last_tap = now;
|
||||
if (tap_interval < _TCA8418_MULTI_TAP_THRESHOLD) {
|
||||
if (tap_interval < _TCA8418_MULTI_TAP_THRESHOLD && should_backspace) {
|
||||
queueEvent(_TCA8418_BSP);
|
||||
}
|
||||
if (held_interval > _TCA8418_LONG_PRESS_THRESHOLD) {
|
||||
|
@ -21,6 +21,8 @@ class TCA8418Keyboard
|
||||
|
||||
KeyState state;
|
||||
int8_t last_key;
|
||||
int8_t next_key;
|
||||
bool should_backspace;
|
||||
uint32_t last_tap;
|
||||
uint8_t char_idx;
|
||||
int32_t tap_interval;
|
||||
|
Loading…
Reference in New Issue
Block a user