From 92b3b208c4c54ae4a36974d955653aa5855b4d55 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Tue, 25 Mar 2025 14:19:19 +0000 Subject: [PATCH] bug fix fast pressing multiple buttons + clean up scanI2CTwoWire.cpp --- src/detect/ScanI2CTwoWire.cpp | 9 +-------- src/input/TCA8418Keyboard.cpp | 11 ++++++----- src/input/TCA8418Keyboard.h | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 50c01f86a..e8506f07c 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -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 diff --git a/src/input/TCA8418Keyboard.cpp b/src/input/TCA8418Keyboard.cpp index b3d2911ee..aa7ffcfd5 100644 --- a/src/input/TCA8418Keyboard.cpp +++ b/src/input/TCA8418Keyboard.cpp @@ -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) { diff --git a/src/input/TCA8418Keyboard.h b/src/input/TCA8418Keyboard.h index cbf30d402..c7f3c1f28 100644 --- a/src/input/TCA8418Keyboard.h +++ b/src/input/TCA8418Keyboard.h @@ -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;