feat: complete Cascade Indicator companion support

Add native-resolution Indicator UI, touch navigation, SD-backed pixel and emoji fonts, LoRa radio support, dual-slot WiFi Companion provisioning, and mesh clock fallback. Harden radio recovery and build defaults, normalize ESP32 setup-AP protocols, and document/test the operator workflows.
This commit is contained in:
mikecarper committed 2026-08-25 18:37:17 -07:00
1 parent 1792acda6a
commit 9d57a3a4f8
55 files changed
+4185 -175

No files matched your search

+13 -3
View File
@@ -13,6 +13,10 @@
#include "NodePrefs.h"
#ifndef UI_USB_AUTO_OFF_MULTIPLIER
#define UI_USB_AUTO_OFF_MULTIPLIER 5UL
#endif
enum class UIEventType {
none,
contactMessage,
@@ -35,11 +39,14 @@ protected:
bool isDisplayAutoOffDue(unsigned long configured_deadline,
unsigned long configured_timeout_millis) const {
unsigned long deadline = configured_deadline;
#if UI_USB_AUTO_OFF_MULTIPLIER > 1
if (_board->isUsbHostConnected()) {
// The configured deadline already includes the first timeout period.
// Add four more periods for a total of 5x while attached to a computer.
deadline += configured_timeout_millis * 4UL;
// Add the remaining periods while attached to a computer.
deadline += configured_timeout_millis
* (UI_USB_AUTO_OFF_MULTIPLIER - 1UL);
}
#endif
return static_cast<int32_t>(millis() - deadline) > 0;
}
@@ -59,7 +66,10 @@ public:
void enableBluetooth() { _interfaceManager->enableBluetooth(); }
void disableBluetooth() { _interfaceManager->disableBluetooth(); }
virtual void msgRead(int msgcount) = 0;
virtual void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) = 0;
virtual void newMsg(uint8_t path_len, const char* from_name,
const char* text, int msgcount,
int channel_idx = -1,
const char* channel_name = nullptr) = 0;
virtual void notify(UIEventType t = UIEventType::none) = 0;
virtual void loop() = 0;
};
+53 -9
View File
@@ -847,9 +847,26 @@ bool MyMesh::filterRecvFloodPacket(mesh::Packet* packet) {
}
bool MyMesh::allowPacketForward(const mesh::Packet* packet) {
return _prefs.isRepeatEn();
if (!_prefs.isRepeatEn()) return false;
#ifdef COMPANION_MESH_CLOCK_SYNC
_clock_sync.observeAcceptedFlood(packet);
#endif
return true;
}
#ifdef COMPANION_MESH_CLOCK_SYNC
void MyMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
uint32_t timestamp, const uint8_t* app_data,
size_t app_data_len) {
BaseChatMesh::onAdvertRecv(packet, id, timestamp, app_data, app_data_len);
_clock_sync.observeVerifiedAdvert(packet, id, timestamp);
}
void MyMesh::onGroupPacketRecv(mesh::Packet* packet) {
_clock_sync.observeGroupPacket(packet);
}
#endif
bool MyMesh::allowFloodRetry(const mesh::Packet* packet) const {
if (packet == NULL) return false;
// A companion may retry its own advert once, using the core's deliberately
@@ -982,7 +999,13 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
if (getChannel(channel_idx, channel_details)) {
channel_name = channel_details.name;
}
if (_ui) _ui->newMsg(path_len, channel_name, text, offline_queue_len);
char channel_label[64];
snprintf(channel_label, sizeof(channel_label), "Ch %u %s",
(unsigned int)channel_idx, channel_name);
if (_ui) {
_ui->newMsg(path_len, channel_label, text, offline_queue_len,
channel_idx, channel_name);
}
#endif
if (pkt->isRouteFlood() && is_emergency_channel) {
@@ -1357,6 +1380,10 @@ void MyMesh::onSendTimeout() {
MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui)
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables),
#ifdef COMPANION_MESH_CLOCK_SYNC
_clock_sync(radio, _clock_sync_millis, rtc, _clock_sync_acl, sensors,
_prefs.airtime_factor),
#endif
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store), _ui(ui), _iter(0) {
_iter_started = false;
_cli_rescue = false;
@@ -1606,6 +1633,12 @@ void MyMesh::begin(bool has_display, bool radio_available) {
_store->saveChannels(this);
}
#ifdef COMPANION_MESH_CLOCK_SYNC
// Fixed fallback policy for this Companion build. A successful host time
// update below suppresses mesh correction for the remainder of the boot.
_clock_sync.begin(nullptr);
#endif
configureRadioFromPrefs();
#if defined(WITH_MQTT_BRIDGE) && defined(ESP32_PLATFORM) && defined(WIFI_SSID)
@@ -1808,9 +1841,10 @@ void MyMesh::scheduleNormalRadio(char* reply, size_t reply_size) {
_temp_radio_failures = 0;
snprintf(reply, reply_size, "OK - normal radio restore scheduled");
}
#endif
bool MyMesh::handleFullOtaCommand(const char* command, char* reply,
size_t reply_size) {
bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
size_t reply_size) {
if (!command || !reply || reply_size == 0) return false;
while (*command == ' ') command++;
@@ -1971,6 +2005,7 @@ bool MyMesh::handleFullOtaCommand(const char* command, char* reply,
}
#endif
#if defined(COMPANION_RADIO_FULL)
if (strcmp(command, "tempradio") == 0) {
if (_temp_radio_set_at) {
snprintf(reply, reply_size, "TempRadio pending: %.3f,%.2f,%u,%u",
@@ -2021,10 +2056,12 @@ bool MyMesh::handleFullOtaCommand(const char* command, char* reply,
snprintf(reply, reply_size, "%s", ota_reply);
return true;
}
#endif
return false;
}
#if defined(COMPANION_RADIO_FULL)
void MyMesh::serviceTempRadio() {
const unsigned long now = _ms->getMillis();
const bool retry_ready = !_temp_radio_retry_at
@@ -2964,6 +3001,9 @@ void MyMesh::handleCmdFrame(size_t len) {
uint32_t curr = getRTCClock()->getCurrentTime();
if (secs >= curr) {
getRTCClock()->setCurrentTime(secs);
#ifdef COMPANION_MESH_CLOCK_SYNC
_clock_sync.onManualClockSet();
#endif
writeOKFrame();
} else {
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
@@ -4753,13 +4793,11 @@ void MyMesh::handleTerminalCommand(char* command) {
if (*command == 0) return;
mesh::cli::normalizeCommandVerb(command);
#if defined(COMPANION_RADIO_FULL)
char full_reply[160];
if (handleFullOtaCommand(command, full_reply, sizeof(full_reply))) {
terminalOutput().printf(" %s\r\n", full_reply);
char local_reply[160];
if (handleLocalControlCommand(command, local_reply, sizeof(local_reply))) {
terminalOutput().printf(" %s\r\n", local_reply);
return;
}
#endif
mesh::cli::TerminalChannelMessage channel_message;
const mesh::cli::TerminalChannelCommandMatch channel_match =
@@ -4869,6 +4907,9 @@ void MyMesh::handleTerminalCommand(char* command) {
uint32_t current = getRTCClock()->getCurrentTime();
if (timestamp >= current) {
getRTCClock()->setCurrentTime(timestamp);
#ifdef COMPANION_MESH_CLOCK_SYNC
_clock_sync.onManualClockSet();
#endif
terminalOutput().print(" OK - clock set\r\n");
} else {
terminalOutput().print(" ERROR: clock cannot go backwards\r\n");
@@ -5518,6 +5559,9 @@ void MyMesh::loop() {
serviceTempRadio();
#endif
BaseChatMesh::loop();
#ifdef COMPANION_MESH_CLOCK_SYNC
_clock_sync.loop();
#endif
#ifdef ENABLE_USB_INTERFACE
serviceTerminalLogin();
serviceTerminalCommand();
+20 -5
View File
@@ -47,6 +47,11 @@
#include <helpers/TerminalDisplayFilter.h>
#include <target.h>
#ifdef COMPANION_MESH_CLOCK_SYNC
#include <helpers/ClientACL.h>
#include <helpers/MeshClockSync.h>
#endif
/* ---------------------------------- CONFIGURATION ------------------------------------- */
#ifndef LORA_FREQ
@@ -171,11 +176,10 @@ public:
#endif
#endif
#if defined(COMPANION_RADIO_FULL)
// Local-only control surface shared by the USB terminal and WiFi port 5002.
// Supports bounded TempRadio windows plus the serve-only `ota ...` CLI.
bool handleFullOtaCommand(const char* command, char* reply, size_t reply_size);
#endif
// Local control shared by every USB terminal. ESP32 WiFi companions expose
// setup/status commands here; Full builds add TempRadio and OTA commands.
bool handleLocalControlCommand(const char* command, char* reply,
size_t reply_size);
int getRecentlyHeard(AdvertPath dest[], int max_num);
@@ -200,6 +204,12 @@ protected:
bool filterRecvFloodPacket(mesh::Packet* packet) override;
bool allowPacketForward(const mesh::Packet* packet) override;
bool allowFloodRetry(const mesh::Packet* packet) const override;
#ifdef COMPANION_MESH_CLOCK_SYNC
void onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
uint32_t timestamp, const uint8_t* app_data,
size_t app_data_len) override;
void onGroupPacketRecv(mesh::Packet* packet) override;
#endif
bool sendFloodScoped(const TransportKey& scope, mesh::Packet* pkt, uint32_t delay_millis);
bool sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis=0) override;
@@ -362,6 +372,11 @@ private:
DataStore* _store;
CompanionNodePrefs _prefs;
#ifdef COMPANION_MESH_CLOCK_SYNC
ArduinoMillis _clock_sync_millis;
ClientACL _clock_sync_acl;
mesh::MeshClockSync _clock_sync;
#endif
#if defined(WITH_MQTT_BRIDGE) && defined(ESP32_PLATFORM) && defined(WIFI_SSID)
MQTTPrefs _mqtt_prefs;
MQTTBridge* _mqtt_bridge;
+2 -2
View File
@@ -370,7 +370,7 @@ static void resetUsbMotaMode() {
static void leaveUsbMotaMode(bool acknowledge) {
char reply[160] = {0};
the_mesh.handleFullOtaCommand("ota folder off", reply, sizeof(reply));
the_mesh.handleLocalControlCommand("ota folder off", reply, sizeof(reply));
if (acknowledge) {
Serial.print("\r\n");
Serial.print(reply);
@@ -388,7 +388,7 @@ static void enterUsbMotaMode() {
usb_mota_disconnect_armed = isUsbTerminalDataConnected();
char reply[160] = {0};
if (!the_mesh.handleFullOtaCommand("ota folder on", reply, sizeof(reply))
if (!the_mesh.handleLocalControlCommand("ota folder on", reply, sizeof(reply))
|| strncmp(reply, "ERR", 3) == 0) {
Serial.print("\r\n");
Serial.print(reply[0] ? reply : "ERR could not enter mOTA seeder mode");
+278 -44
View File
@@ -18,6 +18,9 @@
#ifndef USB_MESSAGE_PREVIEW_MILLIS
#define USB_MESSAGE_PREVIEW_MILLIS 15000UL
#endif
#ifndef UI_RADIO_REFRESH_MILLIS
#define UI_RADIO_REFRESH_MILLIS 2000UL
#endif
#ifndef BLE_PAIRING_DISPLAY_MILLIS
#define BLE_PAIRING_DISPLAY_MILLIS 120000UL
#endif
@@ -126,7 +129,7 @@ class HomeScreen : public UIScreen {
AdvertPath recent[UI_RECENT_LIST_SIZE];
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
int renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
// Convert millivolts to percentage
#ifndef BATT_MIN_MILLIVOLTS
#define BATT_MIN_MILLIVOLTS 3000
@@ -136,14 +139,19 @@ class HomeScreen : public UIScreen {
#endif
const int minMilliVolts = BATT_MIN_MILLIVOLTS;
const int maxMilliVolts = BATT_MAX_MILLIVOLTS;
int batteryPercentage = ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts);
const bool showBattery = batteryMilliVolts != 0;
int batteryPercentage = showBattery
? ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts)
: 0;
if (batteryPercentage < 0) batteryPercentage = 0; // Clamp to 0%
if (batteryPercentage > 100) batteryPercentage = 100; // Clamp to 100%
// battery icon
int iconWidth = 24;
int iconHeight = 10;
int iconX = display.width() - iconWidth - 5; // Position the icon near the top-right corner
int iconX = showBattery
? display.width() - iconWidth - 5
: display.width() - 5;
int iconY = 0;
display.setColor(UIColor::title_txt);
@@ -178,25 +186,28 @@ class HomeScreen : public UIScreen {
#ifdef PIN_BUZZER
if (muted) statusWidth += 9;
#endif
display.setCursor(iconX - statusWidth - uptimeWidth - spaceWidth, iconY);
int statusStartX = iconX - statusWidth - uptimeWidth - spaceWidth;
display.setCursor(statusStartX, iconY);
display.print(uptime);
// battery outline
display.drawRect(iconX, iconY, iconWidth, iconHeight);
if (showBattery) {
// battery outline
display.drawRect(iconX, iconY, iconWidth, iconHeight);
// battery "cap"
display.fillRect(iconX + iconWidth, iconY + (iconHeight / 4), 3, iconHeight / 2);
// battery "cap"
display.fillRect(iconX + iconWidth, iconY + (iconHeight / 4), 3, iconHeight / 2);
// fill the battery based on the percentage
int fillWidth = (batteryPercentage * (iconWidth - 4)) / 100;
display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4);
// fill the battery based on the percentage
int fillWidth = (batteryPercentage * (iconWidth - 4)) / 100;
display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4);
}
// Show external power beside the battery. Most boards have no
// charge-complete signal, so use a high percentage band for the plug.
if (charging) {
static constexpr int BATT_FULL_PCT = 95;
const uint8_t* symbol =
batteryPercentage >= BATT_FULL_PCT ? plug_icon : charging_icon;
!showBattery || batteryPercentage >= BATT_FULL_PCT ? plug_icon : charging_icon;
display.setColor(UIColor::title_txt);
display.drawXbm(iconX - 9, iconY + 1, symbol, 8, 8);
}
@@ -208,6 +219,8 @@ class HomeScreen : public UIScreen {
display.drawXbm(iconX - (charging ? 18 : 9), iconY + 1, muted_icon, 8, 8);
}
#endif
return statusStartX;
}
CayenneLPP sensors_lpp;
@@ -255,16 +268,18 @@ public:
display.setColor(UIColor::title_bkg);
display.fillRect(0, 0, display.width(), 12);
char tmp[80];
// node name
// status indicators
display.setTextSize(1);
display.setColor(UIColor::title_txt);
int statusStartX = renderBatteryIndicator(display, _task->getBattMilliVolts());
// node name
char filtered_name[sizeof(_node_prefs->node_name)];
display.translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name));
display.setCursor(0, 2);
display.print(filtered_name);
// battery voltage
renderBatteryIndicator(display, _task->getBattMilliVolts());
int availableNameWidth = statusStartX - 2;
if (availableNameWidth > 0) {
display.drawTextEllipsized(0, 2, availableNameWidth, filtered_name);
}
// curr page indicator
if (UIColor::title_bkg == UIColor::window_bkg) {
@@ -285,8 +300,12 @@ public:
if (_page == HomePage::FIRST) {
display.setColor(UIColor::primary_txt);
display.setTextSize(2);
sprintf(tmp, "MSG: %d", _task->getMsgCount());
sprintf(tmp, "INBOX: %d", _task->getPreviewCount());
display.drawTextCentered(display.width() / 2, 22, tmp);
display.setTextSize(1);
display.setColor(UIColor::secondary_txt);
display.drawTextCentered(display.width() / 2, 43,
"tap center: inbox");
#ifdef UI_SHOW_CLOCK
display.setTextSize(3);
@@ -371,7 +390,12 @@ public:
sprintf(tmp, "TX: %ddBm", _node_prefs->tx_power_dbm);
display.print(tmp);
display.setCursor(0, 53);
sprintf(tmp, "Noise floor: %d", radio_driver.getNoiseFloor());
float noise_floor = radio_driver.getNoiseFloorDbm();
if (noise_floor == 0.0f) {
strcpy(tmp, "Noise floor: measuring");
} else {
snprintf(tmp, sizeof(tmp), "Noise floor: %.1f", noise_floor);
}
display.print(tmp);
} else if (_page == HomePage::BLUETOOTH) {
display.setColor(UIColor::corp_blue);
@@ -522,7 +546,7 @@ public:
}
#endif
}
return 5000; // next render after 5000 ms
return _page == HomePage::RADIO ? UI_RADIO_REFRESH_MILLIS : 5000;
}
bool handleInput(char c) override {
@@ -545,6 +569,10 @@ public:
}
return true;
}
if (c == KEY_ENTER && _page == HomePage::FIRST) {
_task->showMessages();
return true;
}
if (c == KEY_ENTER && _page == HomePage::ADVERT) {
_task->notify(UIEventType::ack);
if (the_mesh.advert()) {
@@ -585,42 +613,184 @@ class MsgPreviewScreen : public UIScreen {
UITask* _task;
mesh::RTCClock* _rtc;
static constexpr int CHANNEL_FILTER_ALL = -2;
static constexpr int CHANNEL_FILTER_DIRECT = -1;
struct MsgEntry {
uint32_t timestamp;
int channel_idx;
char channel_name[32];
char origin[62];
char msg[UI_MSG_PREVIEW_SIZE];
};
#define MAX_UNREAD_MSGS 32
int num_unread;
int view_offset;
int channel_filter;
int head = MAX_UNREAD_MSGS - 1; // index of latest unread message
MsgEntry unread[MAX_UNREAD_MSGS];
public:
MsgPreviewScreen(UITask* task, mesh::RTCClock* rtc) : _task(task), _rtc(rtc) { num_unread = 0; }
bool matchesFilter(const MsgEntry& entry) const {
return channel_filter == CHANNEL_FILTER_ALL
|| entry.channel_idx == channel_filter;
}
void addPreview(uint8_t path_len, const char* from_name, const char* msg) {
int filteredCount() const {
int count = 0;
for (int age = 0; age < num_unread; ++age) {
int index = (head + MAX_UNREAD_MSGS - age) % MAX_UNREAD_MSGS;
if (matchesFilter(unread[index])) ++count;
}
return count;
}
const MsgEntry* filteredEntry(int offset) const {
int match = 0;
for (int age = 0; age < num_unread; ++age) {
int index = (head + MAX_UNREAD_MSGS - age) % MAX_UNREAD_MSGS;
if (!matchesFilter(unread[index])) continue;
if (match++ == offset) return &unread[index];
}
return nullptr;
}
int buildChannelFilters(int* filters, int capacity) const {
int count = 0;
if (count < capacity) filters[count++] = CHANNEL_FILTER_ALL;
for (int channel_idx = 0;
channel_idx < MAX_GROUP_CHANNELS && count < capacity;
++channel_idx) {
ChannelDetails details;
if (the_mesh.getChannel(channel_idx, details)
&& details.name[0] != 0) {
filters[count++] = channel_idx;
}
}
if (count < capacity) filters[count++] = CHANNEL_FILTER_DIRECT;
return count;
}
void cycleChannelFilter(int direction) {
int filters[MAX_GROUP_CHANNELS + 2];
int count = buildChannelFilters(
filters, sizeof(filters) / sizeof(filters[0]));
if (count == 0) return;
int selected = 0;
while (selected < count && filters[selected] != channel_filter) {
++selected;
}
if (selected == count) selected = 0;
selected = (selected + direction + count) % count;
channel_filter = filters[selected];
view_offset = 0;
}
void channelFilterLabel(char* label, size_t size) const {
if (channel_filter == CHANNEL_FILTER_ALL) {
StrHelper::strncpy(label, "All channels", size);
return;
}
if (channel_filter == CHANNEL_FILTER_DIRECT) {
StrHelper::strncpy(label, "Direct", size);
return;
}
ChannelDetails details;
if (the_mesh.getChannel(channel_filter, details)
&& details.name[0] != 0) {
snprintf(label, size, "Ch %d %s", channel_filter, details.name);
return;
}
for (int age = 0; age < num_unread; ++age) {
int index = (head + MAX_UNREAD_MSGS - age) % MAX_UNREAD_MSGS;
if (unread[index].channel_idx == channel_filter
&& unread[index].channel_name[0] != 0) {
snprintf(label, size, "Ch %d %s", channel_filter,
unread[index].channel_name);
return;
}
}
snprintf(label, size, "Ch %d", channel_filter);
}
void renderChannelFilter(DisplayDriver& display) const {
const int bar_height = 24;
const int bar_y = display.height() - bar_height;
display.setColor(UIColor::window_bkg);
display.fillRect(0, bar_y, display.width(), bar_height);
display.setColor(UIColor::corp_blue);
display.drawRect(0, bar_y, display.width(), 1);
char channel[48];
channelFilterLabel(channel, sizeof(channel));
display.setTextSize(1);
const int text_y = bar_y + 8;
display.setCursor(8, text_y);
display.print("<");
display.drawTextCentered(display.width() / 2, text_y, channel);
display.setCursor(display.width() - display.getTextWidth(">") - 8,
text_y);
display.print(">");
}
public:
MsgPreviewScreen(UITask* task, mesh::RTCClock* rtc)
: _task(task), _rtc(rtc), num_unread(0), view_offset(0),
channel_filter(CHANNEL_FILTER_ALL) {}
bool hasMessages() const { return num_unread > 0; }
int messageCount() const { return num_unread; }
void clear() {
num_unread = 0;
view_offset = 0;
channel_filter = CHANNEL_FILTER_ALL;
}
void addPreview(uint8_t path_len, const char* from_name, const char* msg,
int channel_idx, const char* channel_name) {
head = (head + 1) % MAX_UNREAD_MSGS;
if (num_unread < MAX_UNREAD_MSGS) num_unread++;
view_offset = 0;
channel_filter = channel_idx;
auto p = &unread[head];
p->timestamp = _rtc->getCurrentTime();
p->channel_idx = channel_idx;
StrHelper::strncpy(p->channel_name,
channel_name == nullptr ? "" : channel_name,
sizeof(p->channel_name));
if (path_len == 0xFF) {
sprintf(p->origin, "(D) %s:", from_name);
snprintf(p->origin, sizeof(p->origin), "%s [direct]:", from_name);
} else {
sprintf(p->origin, "(%d) %s:", (uint32_t) path_len, from_name);
snprintf(p->origin, sizeof(p->origin), "%s [%uh]:", from_name,
(unsigned int)path_len);
}
StrHelper::strncpy(p->msg, msg, sizeof(p->msg));
}
int render(DisplayDriver& display) override {
char tmp[16];
char tmp[24];
int filtered_count = filteredCount();
if (view_offset >= filtered_count) view_offset = 0;
display.setCursor(0, 0);
display.setTextSize(1);
display.setColor(UIColor::corp_blue);
sprintf(tmp, "Unread: %d", num_unread);
snprintf(tmp, sizeof(tmp), "Message %d/%d",
filtered_count == 0 ? 0 : view_offset + 1, filtered_count);
display.print(tmp);
auto p = &unread[head];
const MsgEntry* p = filteredEntry(view_offset);
if (p == nullptr) {
display.drawRect(0, 11, display.width(), 1);
display.setColor(UIColor::secondary_txt);
display.drawTextCentered(display.width() / 2, 40,
"No buffered messages");
renderChannelFilter(display);
return 5000;
}
int secs = _rtc->getCurrentTime() - p->timestamp;
if (secs < 60) {
@@ -647,6 +817,8 @@ public:
display.translateUTF8ToBlocks(filtered_msg, p->msg, sizeof(filtered_msg));
display.printWordWrap(filtered_msg, display.width());
renderChannelFilter(display);
#if AUTO_OFF_MILLIS==0 // probably e-ink
return 10000; // 10 s
#else
@@ -656,15 +828,22 @@ public:
bool handleInput(char c) override {
if (c == KEY_NEXT || c == KEY_RIGHT) {
head = (head + MAX_UNREAD_MSGS - 1) % MAX_UNREAD_MSGS;
num_unread--;
if (num_unread == 0) {
_task->gotoHomeScreen();
}
if (view_offset + 1 < filteredCount()) ++view_offset;
return true;
}
if (c == KEY_PREV || c == KEY_LEFT) {
if (view_offset > 0) --view_offset;
return true;
}
if (c == KEY_DOWN) {
cycleChannelFilter(1);
return true;
}
if (c == KEY_UP) {
cycleChannelFilter(-1);
return true;
}
if (c == KEY_ENTER) {
num_unread = 0; // clear unread queue
_task->gotoHomeScreen();
return true;
}
@@ -727,6 +906,14 @@ void UITask::showAlert(const char* text, int duration_millis) {
_alert_expiry = millis() + duration_millis;
}
void UITask::showMessages() {
setCurrScreen(msg_preview);
}
int UITask::getPreviewCount() const {
return static_cast<const MsgPreviewScreen*>(msg_preview)->messageCount();
}
void UITask::notify(UIEventType t) {
#if defined(PIN_BUZZER)
switch(t){
@@ -763,14 +950,20 @@ void UITask::msgRead(int msgcount) {
_deferred_msg_preview = false;
const bool holding_usb_preview = curr == msg_preview && _msg_preview_until != 0
&& static_cast<int32_t>(millis() - _msg_preview_until) < 0;
if (!holding_usb_preview) gotoHomeScreen();
if (!holding_usb_preview) {
static_cast<MsgPreviewScreen*>(msg_preview)->clear();
gotoHomeScreen();
}
}
}
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) {
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
int msgcount, int channel_idx,
const char* channel_name) {
_msgcount = msgcount;
((MsgPreviewScreen *) msg_preview)->addPreview(path_len, from_name, text);
((MsgPreviewScreen *)msg_preview)
->addPreview(path_len, from_name, text, channel_idx, channel_name);
if (isPairingScreenActive()) {
// Keep the PIN visible, but retain the preview so it can be shown after
// pairing completes or the pairing display window expires.
@@ -781,7 +974,8 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
// A connected app drains the offline queue almost immediately, which calls
// msgRead(0). While attached to a computer, retain the actual message screen
// for 15 seconds even though the app has already consumed the message.
// for the configured preview interval even though the app has already
// consumed the message.
_msg_preview_until = _board->isUsbHostConnected()
? millis() + USB_MESSAGE_PREVIEW_MILLIS
: 0;
@@ -955,11 +1149,17 @@ void UITask::loop() {
if (ev == BUTTON_EVENT_CLICK) {
c = checkDisplayOn(KEY_NEXT);
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
c = handleLongPress(KEY_ENTER);
c = (_display != NULL && !_display->isOn())
? checkDisplayOn(KEY_ENTER)
: handleLongPress(KEY_ENTER);
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
c = handleDoubleClick(KEY_PREV);
c = (_display != NULL && !_display->isOn())
? checkDisplayOn(KEY_ENTER)
: handleDoubleClick(KEY_PREV);
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
c = handleTripleClick(KEY_SELECT);
c = (_display != NULL && !_display->isOn())
? checkDisplayOn(KEY_ENTER)
: handleTripleClick(KEY_SELECT);
}
#endif
#endif
@@ -988,6 +1188,39 @@ void UITask::loop() {
_analogue_pin_read_millis = millis();
}
#endif
#ifdef HAS_TOUCH
if (_display != NULL
&& (int32_t)(millis() - next_touch_check) >= 0) {
next_touch_check = millis() + 25;
int touch_x = -1;
int touch_y = -1;
const bool touched = _display->getTouch(&touch_x, &touch_y);
const mesh::ui::TouchAction action = touch_input.update(
touched, touch_x, touch_y, _display->width(), _display->height(),
curr == msg_preview);
if (c == 0) {
switch (action) {
case mesh::ui::TouchAction::Previous:
c = checkDisplayOn(KEY_PREV);
break;
case mesh::ui::TouchAction::Next:
c = checkDisplayOn(KEY_NEXT);
break;
case mesh::ui::TouchAction::Select:
c = checkDisplayOn(KEY_ENTER);
break;
case mesh::ui::TouchAction::VerticalPrevious:
c = checkDisplayOn(KEY_UP);
break;
case mesh::ui::TouchAction::VerticalNext:
c = checkDisplayOn(KEY_DOWN);
break;
case mesh::ui::TouchAction::None:
break;
}
}
}
#endif
#if defined(BACKLIGHT_BTN)
if (millis() > next_backlight_btn_check) {
bool touch_state = digitalRead(PIN_BUTTON2);
@@ -1021,10 +1254,11 @@ void UITask::loop() {
if (curr) curr->poll();
if (curr == msg_preview && _msgcount == 0 && _msg_preview_until != 0
if (_msgcount == 0 && _msg_preview_until != 0
&& static_cast<int32_t>(millis() - _msg_preview_until) >= 0) {
_msg_preview_until = 0;
gotoHomeScreen();
static_cast<MsgPreviewScreen*>(msg_preview)->clear();
if (curr == msg_preview) gotoHomeScreen();
}
if (_display != NULL && _display->isOn()) {
+24 -1
View File
@@ -7,6 +7,9 @@
#include <helpers/MultiSerialInterface.h>
#include <Arduino.h>
#include <helpers/sensors/LPPDataHelpers.h>
#ifdef HAS_TOUCH
#include <helpers/ui/TouchInput.h>
#endif
#ifndef LED_STATE_ON
#define LED_STATE_ON 1
@@ -41,6 +44,22 @@ class UITask : public AbstractUITask {
int _msgcount;
unsigned long ui_started_at, next_batt_chck;
int next_backlight_btn_check = 0;
#ifdef HAS_TOUCH
#ifndef TOUCH_CENTER_ZONE_PERCENT
#define TOUCH_CENTER_ZONE_PERCENT 34
#endif
#if defined(TOUCH_REVERSE_SWIPE) \
&& defined(TOUCH_SEPARATE_VERTICAL_SWIPES)
mesh::ui::TouchInput touch_input{true, true, TOUCH_CENTER_ZONE_PERCENT};
#elif defined(TOUCH_REVERSE_SWIPE)
mesh::ui::TouchInput touch_input{true, false, TOUCH_CENTER_ZONE_PERCENT};
#elif defined(TOUCH_SEPARATE_VERTICAL_SWIPES)
mesh::ui::TouchInput touch_input{false, true, TOUCH_CENTER_ZONE_PERCENT};
#else
mesh::ui::TouchInput touch_input{false, false, TOUCH_CENTER_ZONE_PERCENT};
#endif
unsigned long next_touch_check = 0;
#endif
#ifdef PIN_STATUS_LED
int led_state = 0;
int next_led_change = 0;
@@ -83,8 +102,10 @@ public:
void serviceWiFiToggleButton();
void gotoHomeScreen() { setCurrScreen(home); }
void showMessages();
void showAlert(const char* text, int duration_millis);
int getMsgCount() const { return _msgcount; }
int getPreviewCount() const;
bool hasDisplay() const { return _display != NULL; }
bool isButtonPressed() const;
@@ -103,7 +124,9 @@ public:
// from AbstractUITask
void msgRead(int msgcount) override;
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
void newMsg(uint8_t path_len, const char* from_name, const char* text,
int msgcount, int channel_idx = -1,
const char* channel_name = nullptr) override;
void notify(UIEventType t = UIEventType::none) override;
void loop() override;
+5 -1
View File
@@ -156,7 +156,11 @@ void UITask::clearMsgPreview() {
_need_refresh = true;
}
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) {
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
int msgcount, int channel_idx,
const char* channel_name) {
(void)channel_idx;
(void)channel_name;
_msgcount = msgcount;
#ifdef HAS_DRV2605
+3 -1
View File
@@ -78,7 +78,9 @@ public:
// from AbstractUITask
void msgRead(int msgcount) override;
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
void newMsg(uint8_t path_len, const char* from_name, const char* text,
int msgcount, int channel_idx = -1,
const char* channel_name = nullptr) override;
void notify(UIEventType t = UIEventType::none) override;
void loop() override;
+5 -1
View File
@@ -515,7 +515,11 @@ void UITask::msgRead(int msgcount) {
}
}
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) {
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
int msgcount, int channel_idx,
const char* channel_name) {
(void)channel_idx;
(void)channel_name;
_msgcount = msgcount;
if (_display != NULL) {
+3 -1
View File
@@ -106,7 +106,9 @@ public:
// from AbstractUITask
void msgRead(int msgcount) override;
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
void newMsg(uint8_t path_len, const char* from_name, const char* text,
int msgcount, int channel_idx = -1,
const char* channel_name = nullptr) override;
void notify(UIEventType t = UIEventType::none) override;
void loop() override;