Rebase onto main, move CARDKB_I2C out of class body, resolve via platformio.ini

This commit is contained in:
tchellow
2026-08-28 10:55:52 -03:00
parent 55203c2ddd
commit 8fdb03bd9a
4 changed files with 62 additions and 29 deletions
@@ -61,6 +61,7 @@ class SettingsScreen : public UIScreen {
CUSTOM_FREQ, CUSTOM_SF, CUSTOM_BW, CUSTOM_CR,
POWER_SAVE,
TX_APC,
SCOPE_NAME,
// System section
SECTION_SYSTEM,
DEVICE_NAME,
@@ -555,6 +556,11 @@ class SettingsScreen : public UIScreen {
// Suppressed (and locked) while repeating — a repeater holds full TX power.
if (p && p->client_repeat) display.print("--");
else display.print((p && p->tx_apc) ? "ON" : "OFF");
} else if (item == SCOPE_NAME) {
display.print("Scope");
int vx = valCol(display);
display.drawTextEllipsized(vx, y, display.width() - vx - _reserve,
(p && p->default_scope_name[0]) ? p->default_scope_name : "(none)");
#if AUTO_OFF_MILLIS > 0
} else if (item == AUTO_OFF) {
display.print("AutoOff");
@@ -678,6 +684,7 @@ class SettingsScreen : public UIScreen {
// Keyboard state for editing message slots
int _edit_slot = -1; // -1 = not editing, 0..9 = slot being edited
bool _edit_name = false; // editing DEVICE_NAME via the keyboard
bool _edit_scope = false; // editing SCOPE_NAME via the keyboard
KeyboardWidget* _kb;
// Radio preset picker — names are too long for the value column, so Enter on
@@ -701,6 +708,7 @@ public:
void onShow() override {
_dirty = false;
_edit_name = false;
_edit_scope = false;
resetList();
_editor.freq.active = false;
}
@@ -708,7 +716,7 @@ public:
int render(DisplayDriver& display) override {
display.setTextSize(1);
if (_edit_slot >= 0 || _edit_name || _picker.saving) {
if (_edit_slot >= 0 || _edit_name || _edit_scope || _picker.saving) {
return _kb->render(display);
}
@@ -771,6 +779,19 @@ public:
return true;
}
// Keyboard editing mode for the scope name
if (_edit_scope) {
auto res = _kb->handleInput(c);
if (res == KeyboardWidget::DONE) {
the_mesh.setPrimaryScope(_kb->buf);
_dirty = true;
_edit_scope = false;
} else if (res == KeyboardWidget::CANCELLED) {
_edit_scope = false;
}
return true;
}
// Digit-by-digit Freq editor
if (_editor.active()) {
if (_editor.handleFreqInput(c) && p) { _task->applyRadioParams(); _dirty = true; }
@@ -966,6 +987,12 @@ public:
_kb->clearPlaceholders(); // a device name is literal, not a message
return true;
}
if (_selected == SCOPE_NAME && p && enter) {
_edit_scope = true;
_kb->begin(p->default_scope_name, (int)sizeof(p->default_scope_name) - 1);
_kb->clearPlaceholders(); // a scope name is literal, not a message
return true;
}
if (_selected == REBOOT && enter) {
_task->savePrefsIfDirty(_dirty); // don't lose pending edits across the restart
_task->showAlert("Rebooting...", 800);
+5 -5
View File
@@ -1398,11 +1398,11 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
_auto_off = millis() + (aoff > 0 ? aoff : AUTO_OFF_MILLIS);
#if defined(CARDKB_I2C)
// On the ENV_PIN_SDA/SCL path, Wire1 is already brought up by
// On the ENV_PIN_SDA/SCL path, CARDKB_I2C is Wire1, already brought up by
// sensors.begin() (EnvironmentSensorManager), which runs before this. On
// the CARDKB_USE_PRIMARY_WIRE path, Wire is already brought up by the
// board's own begin() (display/RTC), also before this -- either way, just
// probe for a CardKB sitting on the bus.
// boards that set CARDKB_I2C=Wire directly in platformio.ini, that bus is
// brought up by the board's own begin() instead -- also before this.
// Either way, just probe for a CardKB sitting on it.
CARDKB_I2C.beginTransmission(0x5F);
_has_cardkb = (CARDKB_I2C.endTransmission() == 0);
#endif
@@ -2120,7 +2120,7 @@ static const char CARDKB_FN_BASE[48] = {
};
#endif
// Poll an optional CardKB (I2C keyboard, addr 0x5F) on Wire1/Grove, feeding
// Poll an optional CardKB (I2C keyboard, addr 0x5F) on CARDKB_I2C, feeding
// the same key queue as every physical button. Most of its output needs no
// translation at all: CardKB's own arrow/Enter/Esc byte codes are already
// identical to this UI's KEY_LEFT/UP/DOWN/RIGHT/ENTER/CANCEL (0xB4-0xB7, 13,
+17 -14
View File
@@ -23,6 +23,21 @@
#include "../AbstractUITask.h"
#include "../NodePrefs.h"
#include "../Trail.h"
// Optional M5Stack CardKB (I2C keyboard, addr 0x5F). CARDKB_I2C names which
// TwoWire it lives on -- set at file scope (not inside the class body, and
// not resolved via an #elif ladder) so both this header and SettingsScreen.h
// see a fully-resolved macro no matter which one gets included first.
// - Boards with a free second I2C bus define ENV_PIN_SDA/ENV_PIN_SCL
// (already brought up for EnvironmentSensorManager) and get Wire1 here,
// same as before.
// - Boards without a free second bus set -D CARDKB_I2C=Wire directly in
// platformio.ini, sharing whatever bus the display/RTC already use.
// Either way it's a no-op on boards that define neither, or when nothing
// ACKs 0x5F at boot.
#if !defined(CARDKB_I2C) && defined(ENV_PIN_SDA) && defined(ENV_PIN_SCL)
#define CARDKB_I2C Wire1
#endif
#include "../Waypoint.h"
#include "../LiveTrack.h"
#include "KeyboardWidget.h"
@@ -193,20 +208,8 @@ class UITask : public AbstractUITask {
void enqueueKey(char c);
bool dequeueKey(char& c);
// Optional M5Stack CardKB (I2C keyboard, addr 0x5F). Two ways to reach it:
// - ENV_PIN_SDA/ENV_PIN_SCL defined -> CardKB rides the dedicated second
// I2C bus (Wire1) that EnvironmentSensorManager already brings up.
// - CARDKB_USE_PRIMARY_WIRE defined instead -> CardKB shares the board's
// main Wire bus (whatever the display/RTC already use), for boards
// where no second bus is free. Mutually exclusive with the above.
// Either way it's a no-op on boards with neither define, or when nothing
// ACKs 0x5F at boot.
#if defined(ENV_PIN_SDA) && defined(ENV_PIN_SCL)
#define CARDKB_I2C Wire1
#elif defined(CARDKB_USE_PRIMARY_WIRE)
#define CARDKB_I2C Wire
#endif
// Optional M5Stack CardKB (I2C keyboard, addr 0x5F). See the CARDKB_I2C
// definition near the top of this file for which bus it's on and why.
#if defined(CARDKB_I2C)
bool _has_cardkb = false;
// CardKB is level-triggered, not edge-triggered -- it keeps returning the