add a .clang-format file (#9154)

This commit is contained in:
Jorropo
2026-01-03 14:19:24 -06:00
committed by GitHub
parent abab6ce815
commit 0d11331d18
771 changed files with 77733 additions and 83165 deletions
+76 -82
View File
@@ -44,94 +44,88 @@ static unsigned char TCA8418LongPressMap[_TCA8418_NUM_KEYS] = {
TCA8418Keyboard::TCA8418Keyboard()
: TCA8418KeyboardBase(_TCA8418_ROWS, _TCA8418_COLS), last_key(-1), next_key(-1), last_tap(0L), char_idx(0), tap_interval(0),
should_backspace(false)
{
should_backspace(false) {}
void TCA8418Keyboard::reset() {
TCA8418KeyboardBase::reset();
// Set COL9 as GPIO output
writeRegister(TCA8418_REG_GPIO_DIR_3, 0x02);
// Switch off keyboard backlight (COL9 = LOW)
writeRegister(TCA8418_REG_GPIO_DAT_OUT_3, 0x00);
}
void TCA8418Keyboard::reset()
{
TCA8418KeyboardBase::reset();
void TCA8418Keyboard::pressed(uint8_t key) {
if (state == Init || state == Busy) {
return;
}
uint8_t next_key = 0;
int row = (key - 1) / 10;
int col = (key - 1) % 10;
// Set COL9 as GPIO output
writeRegister(TCA8418_REG_GPIO_DIR_3, 0x02);
// Switch off keyboard backlight (COL9 = LOW)
writeRegister(TCA8418_REG_GPIO_DAT_OUT_3, 0x00);
if (row >= _TCA8418_ROWS || col >= _TCA8418_COLS) {
return; // Invalid key
}
// Compute key index based on dynamic row/column
next_key = row * _TCA8418_COLS + col;
// LOG_DEBUG("TCA8418: Key %u -> Next Key %u", key, next_key);
state = Held;
uint32_t now = millis();
tap_interval = now - last_tap;
if (tap_interval < 0) {
// Long running, millis has overflowed.
last_tap = 0;
state = Busy;
return;
}
// 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
last_key = next_key;
last_tap = now;
}
void TCA8418Keyboard::pressed(uint8_t key)
{
if (state == Init || state == Busy) {
return;
}
uint8_t next_key = 0;
int row = (key - 1) / 10;
int col = (key - 1) % 10;
void TCA8418Keyboard::released() {
if (state != Held) {
return;
}
if (row >= _TCA8418_ROWS || col >= _TCA8418_COLS) {
return; // Invalid key
}
// Compute key index based on dynamic row/column
next_key = row * _TCA8418_COLS + col;
// LOG_DEBUG("TCA8418: Key %u -> Next Key %u", key, next_key);
state = Held;
uint32_t now = millis();
tap_interval = now - last_tap;
if (tap_interval < 0) {
// Long running, millis has overflowed.
last_tap = 0;
state = Busy;
return;
}
// 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
last_key = next_key;
last_tap = now;
if (last_key < 0 || last_key > _TCA8418_NUM_KEYS) { // reset to idle if last_key out of bounds
last_key = -1;
state = Idle;
return;
}
uint32_t now = millis();
int32_t held_interval = now - last_tap;
last_tap = now;
if (tap_interval < _TCA8418_MULTI_TAP_THRESHOLD && should_backspace) {
queueEvent(BSP);
}
if (held_interval > _TCA8418_LONG_PRESS_THRESHOLD) {
queueEvent(TCA8418LongPressMap[last_key]);
// LOG_DEBUG("Long Press Key: %i Map: %i", last_key, TCA8418LongPressMap[last_key]);
} else {
queueEvent(TCA8418TapMap[last_key][(char_idx % TCA8418TapMod[last_key])]);
// LOG_DEBUG("Key Press: %i Index:%i if %i Map: %c", last_key, char_idx, TCA8418TapMod[last_key],
// TCA8418TapMap[last_key][(char_idx % TCA8418TapMod[last_key])]);
}
}
void TCA8418Keyboard::released()
{
if (state != Held) {
return;
}
if (last_key < 0 || last_key > _TCA8418_NUM_KEYS) { // reset to idle if last_key out of bounds
last_key = -1;
state = Idle;
return;
}
uint32_t now = millis();
int32_t held_interval = now - last_tap;
last_tap = now;
if (tap_interval < _TCA8418_MULTI_TAP_THRESHOLD && should_backspace) {
queueEvent(BSP);
}
if (held_interval > _TCA8418_LONG_PRESS_THRESHOLD) {
queueEvent(TCA8418LongPressMap[last_key]);
// LOG_DEBUG("Long Press Key: %i Map: %i", last_key, TCA8418LongPressMap[last_key]);
} else {
queueEvent(TCA8418TapMap[last_key][(char_idx % TCA8418TapMod[last_key])]);
// LOG_DEBUG("Key Press: %i Index:%i if %i Map: %c", last_key, char_idx, TCA8418TapMod[last_key],
// TCA8418TapMap[last_key][(char_idx % TCA8418TapMod[last_key])]);
}
}
void TCA8418Keyboard::setBacklight(bool on)
{
if (on) {
digitalWrite(TCA8418_COL9, HIGH);
} else {
digitalWrite(TCA8418_COL9, LOW);
}
void TCA8418Keyboard::setBacklight(bool on) {
if (on) {
digitalWrite(TCA8418_COL9, HIGH);
} else {
digitalWrite(TCA8418_COL9, LOW);
}
}