#9623 resolved a local shadow of next_key by converting it to int. (#9665)

This commit is contained in:
Thomas Göttgens
2026-02-16 19:39:43 +01:00
committed by GitHub
parent 6b44b5786e
commit a227fd7028
10 changed files with 29 additions and 32 deletions
+4 -5
View File
@@ -106,8 +106,8 @@ static unsigned char HackadayCommunicatorTapMap[_TCA8418_NUM_KEYS][2] = {{},
{}}; {}};
HackadayCommunicatorKeyboard::HackadayCommunicatorKeyboard() HackadayCommunicatorKeyboard::HackadayCommunicatorKeyboard()
: TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), modifierFlag(0), last_modifier_time(0), last_key(-1), next_key(-1), : TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), modifierFlag(0), last_modifier_time(0), last_key(UINT8_MAX),
last_tap(0L), char_idx(0), tap_interval(0) next_key(UINT8_MAX), last_tap(0L), char_idx(0), tap_interval(0)
{ {
reset(); reset();
} }
@@ -147,7 +147,6 @@ void HackadayCommunicatorKeyboard::pressed(uint8_t key)
modifierFlag = 0; modifierFlag = 0;
} }
uint8_t next_key = 0;
int row = (key - 1) / 10; int row = (key - 1) / 10;
int col = (key - 1) % 10; int col = (key - 1) % 10;
if (row >= _TCA8418_ROWS || col >= _TCA8418_COLS) { if (row >= _TCA8418_ROWS || col >= _TCA8418_COLS) {
@@ -187,8 +186,8 @@ void HackadayCommunicatorKeyboard::released()
return; return;
} }
if (last_key < 0 || last_key >= _TCA8418_NUM_KEYS) { if (last_key >= _TCA8418_NUM_KEYS) {
last_key = -1; last_key = UINT8_MAX;
state = Idle; state = Idle;
return; return;
} }
+2 -2
View File
@@ -18,8 +18,8 @@ class HackadayCommunicatorKeyboard : public TCA8418KeyboardBase
private: private:
uint8_t modifierFlag; // Flag to indicate if a modifier key is pressed uint8_t modifierFlag; // Flag to indicate if a modifier key is pressed
uint32_t last_modifier_time; // Timestamp of the last modifier key press uint32_t last_modifier_time; // Timestamp of the last modifier key press
int8_t last_key; uint8_t last_key;
int8_t next_key; uint8_t next_key;
uint32_t last_tap; uint32_t last_tap;
uint8_t char_idx; uint8_t char_idx;
int32_t tap_interval; int32_t tap_interval;
+3 -3
View File
@@ -91,7 +91,7 @@ MPR121Keyboard::MPR121Keyboard() : m_wire(nullptr), m_addr(0), readCallback(null
{ {
// LOG_DEBUG("MPR121 @ %02x", m_addr); // LOG_DEBUG("MPR121 @ %02x", m_addr);
state = Init; state = Init;
last_key = -1; last_key = UINT8_MAX;
last_tap = 0L; last_tap = 0L;
char_idx = 0; char_idx = 0;
queue = ""; queue = "";
@@ -359,8 +359,8 @@ void MPR121Keyboard::released()
return; return;
} }
// would clear longpress callback... later. // would clear longpress callback... later.
if (last_key < 0 || last_key > _NUM_KEYS) { // reset to idle if last_key out of bounds if (last_key >= _NUM_KEYS) { // reset to idle if last_key out of bounds
last_key = -1; last_key = UINT8_MAX;
state = Idle; state = Idle;
return; return;
} }
+1 -1
View File
@@ -14,7 +14,7 @@ class MPR121Keyboard
MPR121States state; MPR121States state;
int8_t last_key; uint8_t last_key;
uint32_t last_tap; uint32_t last_tap;
uint8_t char_idx; uint8_t char_idx;
+5 -5
View File
@@ -43,8 +43,8 @@ static unsigned char TCA8418LongPressMap[_TCA8418_NUM_KEYS] = {
}; };
TCA8418Keyboard::TCA8418Keyboard() TCA8418Keyboard::TCA8418Keyboard()
: TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), last_key(-1), next_key(-1), last_tap(0L), char_idx(0), tap_interval(0), : TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), last_key(UINT8_MAX), next_key(UINT8_MAX), last_tap(0L), char_idx(0),
should_backspace(false) tap_interval(0), should_backspace(false)
{ {
} }
@@ -71,7 +71,7 @@ void TCA8418Keyboard::pressed(uint8_t key)
} }
// Compute key index based on dynamic row/column // Compute key index based on dynamic row/column
next_key = (int8_t)(row * _TCA8418_COLS + col); next_key = (uint8_t)(row * _TCA8418_COLS + col);
// LOG_DEBUG("TCA8418: Key %u -> Next Key %u", key, next_key); // LOG_DEBUG("TCA8418: Key %u -> Next Key %u", key, next_key);
@@ -105,8 +105,8 @@ void TCA8418Keyboard::released()
return; return;
} }
if (last_key < 0 || last_key > _TCA8418_NUM_KEYS) { // reset to idle if last_key out of bounds if (last_key >= _TCA8418_NUM_KEYS) { // reset to idle if last_key out of bounds
last_key = -1; last_key = UINT8_MAX;
state = Idle; state = Idle;
return; return;
} }
+2 -2
View File
@@ -14,8 +14,8 @@ class TCA8418Keyboard : public TCA8418KeyboardBase
void pressed(uint8_t key) override; void pressed(uint8_t key) override;
void released(void) override; void released(void) override;
int8_t last_key; uint8_t last_key;
int8_t next_key; uint8_t next_key;
uint32_t last_tap; uint32_t last_tap;
uint8_t char_idx; uint8_t char_idx;
int32_t tap_interval; int32_t tap_interval;
+4 -5
View File
@@ -62,8 +62,8 @@ static unsigned char TDeckProTapMap[_TCA8418_NUM_KEYS][5] = {
}; };
TDeckProKeyboard::TDeckProKeyboard() TDeckProKeyboard::TDeckProKeyboard()
: TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), modifierFlag(0), last_modifier_time(0), last_key(-1), next_key(-1), : TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), modifierFlag(0), last_modifier_time(0), last_key(UINT8_MAX),
last_tap(0L), char_idx(0), tap_interval(0) next_key(UINT8_MAX), last_tap(0L), char_idx(0), tap_interval(0)
{ {
} }
@@ -101,7 +101,6 @@ void TDeckProKeyboard::pressed(uint8_t key)
modifierFlag = 0; modifierFlag = 0;
} }
uint8_t next_key = 0;
int row = (key - 1) / 10; int row = (key - 1) / 10;
int col = (key - 1) % 10; int col = (key - 1) % 10;
@@ -142,8 +141,8 @@ void TDeckProKeyboard::released()
return; return;
} }
if (last_key < 0 || last_key >= _TCA8418_NUM_KEYS) { if (last_key >= _TCA8418_NUM_KEYS) {
last_key = -1; last_key = UINT8_MAX;
state = Idle; state = Idle;
return; return;
} }
+2 -2
View File
@@ -19,8 +19,8 @@ class TDeckProKeyboard : public TCA8418KeyboardBase
private: private:
uint8_t modifierFlag; // Flag to indicate if a modifier key is pressed uint8_t modifierFlag; // Flag to indicate if a modifier key is pressed
uint32_t last_modifier_time; // Timestamp of the last modifier key press uint32_t last_modifier_time; // Timestamp of the last modifier key press
int8_t last_key; uint8_t last_key;
int8_t next_key; uint8_t next_key;
uint32_t last_tap; uint32_t last_tap;
uint8_t char_idx; uint8_t char_idx;
int32_t tap_interval; int32_t tap_interval;
+4 -5
View File
@@ -65,8 +65,8 @@ static unsigned char TLoraPagerTapMap[_TCA8418_NUM_KEYS][3] = {{'q', 'Q', '1'},
{' ', 0x00, Key::BL_TOGGLE}}; {' ', 0x00, Key::BL_TOGGLE}};
TLoraPagerKeyboard::TLoraPagerKeyboard() TLoraPagerKeyboard::TLoraPagerKeyboard()
: TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), modifierFlag(0), last_modifier_time(0), last_key(-1), next_key(-1), : TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), modifierFlag(0), last_modifier_time(0), last_key(UINT8_MAX),
last_tap(0L), char_idx(0), tap_interval(0) next_key(UINT8_MAX), last_tap(0L), char_idx(0), tap_interval(0)
{ {
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
ledcAttach(KB_BL_PIN, LEDC_BACKLIGHT_FREQ, LEDC_BACKLIGHT_BIT_WIDTH); ledcAttach(KB_BL_PIN, LEDC_BACKLIGHT_FREQ, LEDC_BACKLIGHT_BIT_WIDTH);
@@ -129,7 +129,6 @@ void TLoraPagerKeyboard::pressed(uint8_t key)
modifierFlag = 0; modifierFlag = 0;
} }
uint8_t next_key = 0;
int row = (key - 1) / 10; int row = (key - 1) / 10;
int col = (key - 1) % 10; int col = (key - 1) % 10;
@@ -170,8 +169,8 @@ void TLoraPagerKeyboard::released()
return; return;
} }
if (last_key < 0 || last_key >= _TCA8418_NUM_KEYS) { if (last_key >= _TCA8418_NUM_KEYS) {
last_key = -1; last_key = UINT8_MAX;
state = Idle; state = Idle;
return; return;
} }
+2 -2
View File
@@ -21,8 +21,8 @@ class TLoraPagerKeyboard : public TCA8418KeyboardBase
private: private:
uint8_t modifierFlag; // Flag to indicate if a modifier key is pressed uint8_t modifierFlag; // Flag to indicate if a modifier key is pressed
uint32_t last_modifier_time; // Timestamp of the last modifier key press uint32_t last_modifier_time; // Timestamp of the last modifier key press
int8_t last_key; uint8_t last_key;
int8_t next_key; uint8_t next_key;
uint32_t last_tap; uint32_t last_tap;
uint8_t char_idx; uint8_t char_idx;
int32_t tap_interval; int32_t tap_interval;