* companion UI's moved/refactored to src/helpers/ui

* only select variants .ini config refactored so far (Heltec V3, MeshTracker V1, LilyGo T-Echo Card)
This commit is contained in:
Scott Powell committed 2026-11-18 22:00:04 +11:00
1 parent 0b38bfd81a
commit d05ed2122c
30 files changed
+260 -163

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
#include <helpers/IdentityStore.h>
#include <helpers/ContactInfo.h>
#include <helpers/ChannelDetails.h>
#include "NodePrefs.h"
#include <helpers/CompanionNodePrefs.h>
class DataStoreHost {
public:
-29
View File
@@ -392,20 +392,6 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[]
}
static int sort_by_recent(const void *a, const void *b) {
return ((AdvertPath *) b)->recv_timestamp - ((AdvertPath *) a)->recv_timestamp;
}
int MyMesh::getRecentlyHeard(AdvertPath dest[], int max_num) {
if (max_num > ADVERT_PATH_TABLE_SIZE) max_num = ADVERT_PATH_TABLE_SIZE;
qsort(advert_paths, ADVERT_PATH_TABLE_SIZE, sizeof(advert_paths[0]), sort_by_recent);
for (int i = 0; i < max_num; i++) {
dest[i] = advert_paths[i];
}
return max_num;
}
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
out_frame[0] = PUSH_CODE_PATH_UPDATED;
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
@@ -2625,21 +2611,6 @@ void MyMesh::loop() {
}
}
bool MyMesh::advert() {
mesh::Packet* pkt;
if (_prefs.advert_loc_policy == ADVERT_LOC_NONE) {
pkt = createSelfAdvert(_prefs.node_name);
} else {
pkt = createSelfAdvert(_prefs.node_name, sensors.node_lat, sensors.node_lon);
}
if (pkt) {
sendZeroHop(pkt);
return true;
} else {
return false;
}
}
// To check if there is pending work
bool MyMesh::hasPendingWork() const {
return _mgr->getOutboundTotal() > 0 || dirty_contacts_expiry != 0;
+11 -36
View File
@@ -23,7 +23,7 @@
#endif
#include "DataStore.h"
#include "NodePrefs.h"
#include <helpers/CompanionNodePrefs.h>
#include <RTClib.h>
#include <helpers/ArduinoHelpers.h>
@@ -68,6 +68,7 @@
#include <helpers/BaseChatMesh.h>
#include <helpers/TransportKeyStore.h>
#include <helpers/MeshEventListener.h>
/* -------------------------------------------------------------------------------------- */
@@ -75,10 +76,6 @@
#define REQ_TYPE_KEEP_ALIVE 0x02
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
// Copied from simple_repeater
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
struct AdvertPath {
uint8_t pubkey_prefix[7];
uint8_t path_len;
@@ -89,30 +86,11 @@ struct AdvertPath {
class MyMesh : public BaseChatMesh, public DataStoreHost {
public:
class Listener {
public:
virtual void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) = 0;
virtual void onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_details, const char* text) = 0;
virtual void onQueueSizeChanged(int msgcount) = 0;
virtual void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) { }
virtual void onControlDataRecv(const mesh::Packet* pkt) { }
virtual void onChannelDataRecv(mesh::Packet *pkt, const mesh::GroupChannel &channel, uint16_t data_type,
const uint8_t *data, size_t data_len) { }
virtual void onACKRecv(uint32_t ack_crc) { }
virtual uint8_t onUnhandledRequest(const ContactInfo &contact, uint32_t sender_timestamp, const uint8_t *data,
uint8_t len, uint8_t *reply) { return 0; /* unknown request type */ }
virtual bool onUnhandledResponse(const ContactInfo &from, uint32_t tag, const uint8_t* data, uint8_t len) { return false; /* not handled */ }
virtual void onTraceRecv(mesh::Packet *pkt, uint32_t tag, uint32_t auth_code, uint8_t flags,
const uint8_t *path_snrs, const uint8_t *path_hashes, uint8_t path_len) { }
virtual void onRawDataRecv(mesh::Packet *pkt) { }
virtual ~Listener() { }
};
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store);
void begin();
void startInterface(BaseSerialInterface &serial);
void setListener(Listener* listener) { _listener = listener; }
void setListener(MeshEventListener* listener) { _listener = listener; }
const char *getNodeName();
NodePrefs *getNodePrefs();
@@ -121,10 +99,14 @@ public:
void loop();
void handleCmdFrame(size_t len);
bool advert();
void enterCLIRescue();
int getRecentlyHeard(AdvertPath dest[], int max_num);
void enterCLIRescue() override;
void savePrefs() override {
_prefs.node_lat = sensors.node_lat;
_prefs.node_lon = sensors.node_lon;
_store->savePrefs(_prefs);
_prefs.clearDirty();
}
protected:
float getAirtimeBudgetFactor() const override;
@@ -194,13 +176,6 @@ protected:
}
public:
void savePrefs() {
_prefs.node_lat = sensors.node_lat;
_prefs.node_lon = sensors.node_lon;
_store->savePrefs(_prefs);
_prefs.clearDirty();
}
#if ENV_INCLUDE_GPS == 1
void applyGpsPrefs() {
if (_prefs.gps_interval > 0 &&
@@ -247,7 +222,7 @@ private:
uint32_t pending_telemetry, pending_discovery; // pending _TELEMETRY_REQ
uint32_t pending_req; // pending _BINARY_REQ
BaseSerialInterface *_serial;
Listener* _listener;
MeshEventListener* _listener;
ContactsIterator _iter;
uint32_t _iter_filter_since;
+1 -6
View File
@@ -112,11 +112,6 @@ MultiSerialInterface interface_manager;
#endif
/* GLOBAL OBJECTS */
#ifdef DISPLAY_CLASS
#include "UITask.h"
UITask ui_task(&board, &interface_manager);
#endif
StdRNG fast_rng;
SimpleMeshTables tables;
MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables, store);
@@ -327,7 +322,7 @@ void setup() {
#endif
#ifdef DISPLAY_CLASS
ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved
ui_task.begin(disp, &sensors, the_mesh.getNodePrefs(), &the_mesh, the_mesh.getBLEPin(), FIRMWARE_VERSION, FIRMWARE_BUILD_DATE);
the_mesh.setListener(&ui_task);
#ifdef EINK_REFRESH_LOOP
if (disp != NULL) disp->setBusyHook(loopDuringDisplayRefresh);
+3
View File
@@ -182,5 +182,8 @@ public:
bool setChannel(int idx, const ChannelDetails& src);
int findChannelIdx(const mesh::GroupChannel& ch);
virtual void savePrefs() { }
virtual void enterCLIRescue() { }
void loop();
};
File renamed without changes.
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#include <MeshCore.h>
#include <helpers/ContactInfo.h>
#include <helpers/ChannelDetails.h>
class MeshEventListener {
public:
virtual void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) = 0;
virtual void onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_details, const char* text) = 0;
virtual void onQueueSizeChanged(int msgcount) = 0;
virtual void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) { }
virtual void onControlDataRecv(const mesh::Packet* pkt) { }
virtual void onChannelDataRecv(mesh::Packet *pkt, const mesh::GroupChannel &channel, uint16_t data_type,
const uint8_t *data, size_t data_len) { }
virtual void onACKRecv(uint32_t ack_crc) { }
virtual uint8_t onUnhandledRequest(const ContactInfo &contact, uint32_t sender_timestamp, const uint8_t *data,
uint8_t len, uint8_t *reply) { return 0; /* unknown request type */ }
virtual bool onUnhandledResponse(const ContactInfo &from, uint32_t tag, const uint8_t* data, uint8_t len) { return false; /* not handled */ }
virtual void onTraceRecv(mesh::Packet *pkt, uint32_t tag, uint32_t auth_code, uint8_t flags,
const uint8_t *path_snrs, const uint8_t *path_hashes, uint8_t path_len) { }
virtual void onRawDataRecv(mesh::Packet *pkt) { }
virtual ~MeshEventListener() { }
};
@@ -5,15 +5,14 @@
#include <helpers/ui/UIScreen.h>
#include <helpers/SensorManager.h>
#include <helpers/MultiSerialInterface.h>
#include <helpers/MeshEventListener.h>
#include <helpers/CompanionNodePrefs.h>
#include <Arduino.h>
#ifdef PIN_BUZZER
#include <helpers/ui/buzzer.h>
#endif
#include "NodePrefs.h"
#include "MyMesh.h"
enum class UIEventType {
none,
contactMessage,
@@ -23,7 +22,7 @@ enum class UIEventType {
ack
};
class AbstractUITask : public MyMesh::Listener {
class AbstractUITask : public MeshEventListener {
protected:
mesh::MainBoard* _board;
MultiSerialInterface* _interfaceManager;
@@ -1,8 +1,8 @@
#include "UITask.h"
#include <helpers/TxtDataHelpers.h>
#include "../MyMesh.h"
#include "target.h"
#include <time.h>
#include <RTClib.h>
#ifdef ENABLE_WIFI_INTERFACE
#include <WiFi.h>
#endif
@@ -31,18 +31,22 @@
#define PRESS_LABEL "long press"
#endif
// Copied from simple_repeater
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
#include "icons.h"
class SplashScreen : public UIScreen {
UITask* _task;
unsigned long dismiss_after;
char _version_info[12];
const char* _build_date;
public:
SplashScreen(UITask* task) : _task(task) {
SplashScreen(UITask* task, const char* ver, const char* build_date) : _task(task) {
// strip off dash and commit hash by changing dash to null terminator
// e.g: v1.2.3-abcdef -> v1.2.3
const char *ver = FIRMWARE_VERSION;
const char *dash = strchr(ver, '-');
int len = dash ? dash - ver : strlen(ver);
@@ -50,6 +54,8 @@ public:
memcpy(_version_info, ver, len);
_version_info[len] = 0;
_build_date = build_date;
dismiss_after = millis() + BOOT_SCREEN_MILLIS;
}
@@ -74,7 +80,7 @@ public:
display.setColor(UIColor::secondary_txt);
display.setTextSize(1);
display.drawTextCentered(display.width()/2, 48, FIRMWARE_BUILD_DATE);
display.drawTextCentered(display.width()/2, 48, _build_date);
return 1000;
}
@@ -110,6 +116,11 @@ static void formatFixAge(char* buf, size_t size, uint32_t seconds) {
}
#endif
struct AdvertPath {
char name[32];
uint32_t recv_timestamp;
};
class HomeScreen : public UIScreen {
enum HomePage {
FIRST,
@@ -140,6 +151,7 @@ class HomeScreen : public UIScreen {
NodePrefs* _node_prefs;
uint8_t _page;
bool _shutdown_init;
int recent_next_idx;
AdvertPath recent[UI_RECENT_LIST_SIZE];
#if UI_DISCOVER_SCREEN
DiscoveredNode discovered[DISCOVERED_NODES_TABLE_SIZE]; // not circular, latest discovered nodes are not kept
@@ -230,19 +242,31 @@ class HomeScreen : public UIScreen {
public:
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs)
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
_shutdown_init(false), sensors_lpp(200) { }
_shutdown_init(false), sensors_lpp(200)
{
memset(recent, 0, sizeof(recent));
recent_next_idx = 0;
}
void addToRecents(ContactInfo &contact) {
auto p = &recent[recent_next_idx];
recent_next_idx = (recent_next_idx + 1) % UI_RECENT_LIST_SIZE;
strcpy(p->name, contact.name);
p->recv_timestamp = _rtc->getCurrentTime();
}
#if UI_DISCOVER_SCREEN
bool sendDiscoverRequest() {
uint8_t cmd_bytes[6];
cmd_bytes[0] = CTL_TYPE_NODE_DISCOVER_REQ | 1; // DISCOVER_REQ | prefix only
cmd_bytes[1] = 0xFF; // Repeaters
the_mesh.getRNG()->random((uint8_t *) &disc_node_req_tag, 4); // generate random tag
_task->getMesh()->getRNG()->random((uint8_t *) &disc_node_req_tag, 4); // generate random tag
memcpy(&cmd_bytes[2], &disc_node_req_tag, 4);
disc_nodes_count = 0;
mesh::Packet* req = the_mesh.createControlData(cmd_bytes, sizeof(cmd_bytes));
mesh::Packet* req = _task->getMesh()->createControlData(cmd_bytes, sizeof(cmd_bytes));
if (req) {
the_mesh.sendZeroHop(req);
_task->getMesh()->sendZeroHop(req);
discovery_req_time = millis();
return true;
}
@@ -256,7 +280,7 @@ public:
d->type = packet->payload[0] & 0xF;
d->snr_out = ((int8_t)packet->payload[1]) / 4.0;
d->snr_in = radio_driver.getLastSNR();
ContactInfo* c = the_mesh.lookupContactByPubKey(&packet->payload[6], 8);
ContactInfo* c = _task->getMesh()->lookupContactByPubKey(&packet->payload[6], 8);
if (c != NULL) {
strncpy(d->name, c->name, 32);
} else {
@@ -340,9 +364,9 @@ public:
display.drawTextCentered(display.width() / 2, 110, "< Connected >");
else
display.drawTextCentered(display.width() / 2, 43, "< Connected >");
} else if (the_mesh.getBLEPin() != 0) { // BT pin
} else if (_task->getBLEPin() != 0) { // BT pin
display.setColor(UIColor::warning_txt);
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
sprintf(tmp, "Pin:%d", _task->getBLEPin());
if (_node_prefs->ui_show_clock) {
display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 110, tmp);
@@ -352,11 +376,10 @@ public:
}
}
} else if (_page == HomePage::RECENT) {
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
display.setColor(UIColor::primary_txt);
int y = 20;
for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) {
auto a = &recent[i];
for (int i = 0, k = recent_next_idx; i < UI_RECENT_LIST_SIZE; i++, y += 11, k = (k + 1) % UI_RECENT_LIST_SIZE) {
auto a = &recent[k];
if (a->name[0] == 0) continue; // empty slot
int secs = _rtc->getCurrentTime() - a->recv_timestamp;
if (secs < 60) {
@@ -623,7 +646,15 @@ public:
#endif
if (c == KEY_ENTER && _page == HomePage::ADVERT) {
_task->notify(UIEventType::ack);
if (the_mesh.advert()) {
mesh::Packet* pkt;
if (_node_prefs->advert_loc_policy == ADVERT_LOC_NONE) {
pkt = _task->getMesh()->createSelfAdvert(_node_prefs->node_name);
} else {
pkt = _task->getMesh()->createSelfAdvert(_node_prefs->node_name, sensors.node_lat, sensors.node_lon);
}
if (pkt) {
_task->getMesh()->sendZeroHop(pkt);
_task->showAlert("Advert sent!", 1000);
} else {
_task->showAlert("Advert failed..", 1000);
@@ -756,9 +787,11 @@ public:
}
};
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date) {
_display = display;
_sensors = sensors;
the_mesh = mesh;
_ble_pin = ble_pin;
#if defined(PIN_USER_BTN)
user_btn.begin();
@@ -791,7 +824,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
ui_started_at = millis();
_alert_expiry = 0;
splash = new SplashScreen(this);
splash = new SplashScreen(this, ver, build_date);
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs);
msg_preview = new MsgPreviewScreen(this, &rtc_clock);
setCurrScreen(splash);
@@ -888,6 +921,8 @@ void UITask::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
if (!hasConnection()) {
notify(UIEventType::newContactMessage);
}
((HomeScreen *) home)->addToRecents(contact);
}
void UITask::onControlDataRecv(const mesh::Packet* packet) {
@@ -1178,7 +1213,7 @@ char UITask::checkDisplayOn(char c) {
char UITask::handleLongPress(char c) {
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue
the_mesh.enterCLIRescue();
the_mesh->enterCLIRescue();
c = 0; // consume event
}
return c;
@@ -1223,7 +1258,7 @@ void UITask::toggleGPS() {
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, true);
notify(UIEventType::ack);
}
the_mesh.savePrefs();
the_mesh->savePrefs();
showAlert(_node_prefs->getGpsPrefs()->isGpsEnabled() ? "GPS: Enabled" : "GPS: Disabled", 800);
_next_refresh = 0;
break;
@@ -1251,7 +1286,7 @@ void UITask::toggleBuzzer() {
buzzer.quiet(true);
}
_node_prefs->buzzer_quiet = buzzer.isQuiet();
the_mesh.savePrefs();
the_mesh->savePrefs();
showAlert(buzzer.isQuiet() ? "Buzzer: OFF" : "Buzzer: ON", 800);
_next_refresh = 0; // trigger refresh
#endif
@@ -4,6 +4,7 @@
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/UIScreen.h>
#include <helpers/SensorManager.h>
#include <helpers/BaseChatMesh.h>
#include <helpers/MultiSerialInterface.h>
#include <Arduino.h>
#include <helpers/sensors/LPPDataHelpers.h>
@@ -19,8 +20,8 @@
#include <helpers/ui/GenericVibration.h>
#endif
#include "../AbstractUITask.h"
#include "../NodePrefs.h"
#include <helpers/ui/AbstractUITask.h>
#include <helpers/CompanionNodePrefs.h>
#ifdef UI_NO_DISCOVER_SCREEN
#error "UI_NO_DISCOVER_SCREEN is obsolete - use -D UI_DISCOVER_SCREEN=0 instead"
@@ -49,6 +50,8 @@ struct DiscoveredNode {
class UITask : public AbstractUITask {
DisplayDriver* _display;
SensorManager* _sensors;
BaseChatMesh* the_mesh;
uint32_t _ble_pin;
#ifdef PIN_BUZZER
genericBuzzer buzzer;
#endif
@@ -95,7 +98,7 @@ public:
ui_started_at = 0;
curr = NULL;
}
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date);
void gotoHomeScreen() { setCurrScreen(home); }
void showAlert(const char* text, int duration_millis);
@@ -103,6 +106,9 @@ public:
bool hasDisplay() const { return _display != NULL; }
bool isButtonPressed() const;
BaseChatMesh* getMesh() const { return the_mesh; }
uint32_t getBLEPin() const { return _ble_pin; }
bool isBuzzerQuiet() {
#ifdef PIN_BUZZER
return buzzer.isQuiet();
@@ -116,7 +122,7 @@ public:
void toggleGPS();
void triggerGPS();
// MyMesh::Listener
// MeshEventListener
void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) override;
void onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_details, const char* text) override;
void onQueueSizeChanged(int offline_queue_size) override;
File renamed without changes.
@@ -1,7 +1,7 @@
#include "UITask.h"
#include <Arduino.h>
#include <helpers/TxtDataHelpers.h>
#include "../MyMesh.h"
#include "target.h"
#define AUTO_OFF_MILLIS 15000 // 15 seconds
#define BOOT_SCREEN_MILLIS 3000 // 3 seconds
@@ -40,9 +40,12 @@ static const uint8_t meshcore_logo [] PROGMEM = {
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8,
};
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date) {
_display = display;
_sensors = sensors;
the_mesh = mesh;
_ble_pin = ble_pin;
_auto_off = millis() + AUTO_OFF_MILLIS;
clearMsgPreview();
_node_prefs = node_prefs;
@@ -52,14 +55,14 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
// strip off dash and commit hash by changing dash to null terminator
// e.g: v1.2.3-abcdef -> v1.2.3
char *version = strdup(FIRMWARE_VERSION);
char *version = strdup(ver);
char *dash = strchr(version, '-');
if (dash) {
*dash = 0;
}
// v1.2.3 (1 Jan 2025)
sprintf(_version_info, "%s (%s)", version, FIRMWARE_BUILD_DATE);
sprintf(_version_info, "%s (%s)", version, build_date);
#ifdef PIN_BUZZER
buzzer.begin();
@@ -300,11 +303,11 @@ void UITask::renderCurrScreen() {
_display->print(tmp);
// BT pin
if (!hasConnection() && the_mesh.getBLEPin() != 0) {
if (!hasConnection() && _ble_pin != 0) {
_display->setColor(UIColor::warning_txt);
_display->setTextSize(2);
_display->setCursor(0, 43);
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
sprintf(tmp, "Pin:%d", _ble_pin);
_display->print(tmp);
_display->setColor(UIColor::primary_txt);
} else {
@@ -555,7 +558,14 @@ void UITask::handleButtonDoublePress() {
#ifdef PIN_BUZZER
notify(UIEventType::ack);
#endif
if (the_mesh.advert()) {
mesh::Packet* pkt;
if (_node_prefs->advert_loc_policy == ADVERT_LOC_NONE) {
pkt = the_mesh->createSelfAdvert(_node_prefs->node_name);
} else {
pkt = the_mesh->createSelfAdvert(_node_prefs->node_name, sensors.node_lat, sensors.node_lon);
}
if (pkt) {
the_mesh->sendZeroHop(pkt);
MESH_DEBUG_PRINTLN("Advert sent!");
sprintf(_alert, "Advert sent!");
} else {
@@ -584,7 +594,7 @@ void UITask::handleButtonTriplePress() {
case 2: sprintf(_alert, "Alerts: Vibe only"); break;
default: sprintf(_alert, "Alerts: Silent"); break;
}
the_mesh.savePrefs();
the_mesh->savePrefs();
_need_refresh = true;
#elif defined(PIN_BUZZER)
if (buzzer.isQuiet()) {
@@ -596,7 +606,7 @@ void UITask::handleButtonTriplePress() {
sprintf(_alert, "Buzzer: OFF");
}
_node_prefs->buzzer_quiet = buzzer.isQuiet();
the_mesh.savePrefs();
the_mesh->savePrefs();
_need_refresh = true;
#endif
}
@@ -617,7 +627,7 @@ void UITask::handleButtonQuadruplePress() {
notify(UIEventType::ack);
sprintf(_alert, "GPS: Enabled");
}
the_mesh.savePrefs();
the_mesh->savePrefs();
break;
}
}
@@ -628,7 +638,7 @@ void UITask::handleButtonQuadruplePress() {
void UITask::handleButtonLongPress() {
MESH_DEBUG_PRINTLN("UITask: long press triggered");
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue
the_mesh.enterCLIRescue();
the_mesh->enterCLIRescue();
} else {
shutdown();
}
@@ -3,14 +3,15 @@
#include <MeshCore.h>
#include <helpers/ui/DisplayDriver.h>
#include <helpers/SensorManager.h>
#include <helpers/BaseChatMesh.h>
#include <stddef.h>
#ifdef PIN_BUZZER
#include <helpers/ui/buzzer.h>
#endif
#include "../AbstractUITask.h"
#include "../NodePrefs.h"
#include <helpers/ui/AbstractUITask.h>
#include <helpers/CompanionNodePrefs.h>
#include "Button.h"
@@ -21,6 +22,8 @@
class UITask : public AbstractUITask {
DisplayDriver* _display;
SensorManager* _sensors;
BaseChatMesh* the_mesh;
uint32_t _ble_pin;
#ifdef PIN_BUZZER
genericBuzzer buzzer;
#endif
@@ -57,7 +60,6 @@ class UITask : public AbstractUITask {
void handleButtonTriplePress();
void handleButtonQuadruplePress();
void handleButtonLongPress();
public:
@@ -65,12 +67,12 @@ public:
_next_refresh = 0;
ui_started_at = 0;
}
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date);
bool hasDisplay() const { return _display != NULL; }
void clearMsgPreview();
// MyMesh::Listener
// MeshEventListener
void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) override;
void onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_details, const char* text) override;
void onQueueSizeChanged(int offline_queue_size) override;
@@ -1,6 +1,5 @@
#include "UITask.h"
#include <helpers/TxtDataHelpers.h>
#include "../MyMesh.h"
#include "target.h"
#include "u8g2_icons.h"
@@ -36,12 +35,12 @@ class SplashScreen : public UIScreen {
unsigned long dismiss_after;
unsigned long version_after;
char _version_info[12];
const char* _build_date;
public:
SplashScreen(UITask* task) : _task(task) {
SplashScreen(UITask* task, const char* ver, const char* build_date) : _task(task) {
// strip off dash and commit hash by changing dash to null terminator
// e.g: v1.2.3-abcdef -> v1.2.3
const char *ver = FIRMWARE_VERSION;
const char *dash = strchr(ver, '-');
int len = dash ? dash - ver : strlen(ver);
@@ -49,6 +48,8 @@ public:
memcpy(_version_info, ver, len);
_version_info[len] = 0;
_build_date = build_date;
version_after = millis() + BOOT_SCREEN_MILLIS / 2;
dismiss_after = millis() + BOOT_SCREEN_MILLIS;
}
@@ -75,7 +76,7 @@ public:
display.setColor(UIColor::secondary_txt);
display.setTextSize(1);
display.drawTextCentered(display.width()/2, 27, FIRMWARE_BUILD_DATE);
display.drawTextCentered(display.width()/2, 27, _build_date);
}
return 1000;
}
@@ -87,6 +88,11 @@ public:
}
};
struct AdvertPath {
char name[32];
uint32_t recv_timestamp;
};
class HomeScreen : public UIScreen {
enum HomePage {
FIRST,
@@ -110,6 +116,7 @@ class HomeScreen : public UIScreen {
NodePrefs* _node_prefs;
uint8_t _page;
bool _shutdown_init;
int recent_next_idx;
AdvertPath recent[UI_RECENT_LIST_SIZE];
CayenneLPP sensors_lpp;
@@ -142,7 +149,19 @@ class HomeScreen : public UIScreen {
public:
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs)
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
_shutdown_init(false), sensors_lpp(200) { }
_shutdown_init(false), sensors_lpp(200)
{
memset(recent, 0, sizeof(recent));
recent_next_idx = 0;
}
void addToRecents(ContactInfo &contact) {
auto p = &recent[recent_next_idx];
recent_next_idx = (recent_next_idx + 1) % UI_RECENT_LIST_SIZE;
strcpy(p->name, contact.name);
p->recv_timestamp = _rtc->getCurrentTime();
}
void poll() override {
if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released
@@ -184,18 +203,17 @@ public:
display.setTextSize(1);
display.drawTextCentered(display.width() / 2, display.height()-8, "< Connected >");
} else if (the_mesh.getBLEPin() != 0) { // BT pin
} else if (_task->getBLEPin() != 0) { // BT pin
display.setColor(UIColor::warning_txt);
display.setTextSize(2);
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
sprintf(tmp, "Pin:%d", _task->getBLEPin());
display.drawTextCentered(display.width() / 2, display.height()-8, tmp);
}
} else if (_page == HomePage::RECENT) {
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
display.setColor(UIColor::primary_txt);
int y = 8;
for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) {
auto a = &recent[i];
for (int i = 0, k = recent_next_idx; i < UI_RECENT_LIST_SIZE; i++, y += 11, k = (k + 1) % UI_RECENT_LIST_SIZE) {
auto a = &recent[k];
if (a->name[0] == 0) continue; // empty slot
int secs = _rtc->getCurrentTime() - a->recv_timestamp;
if (secs < 60) {
@@ -400,7 +418,14 @@ public:
}
if (c == KEY_ENTER && _page == HomePage::ADVERT) {
_task->notify(UIEventType::ack);
if (the_mesh.advert()) {
mesh::Packet* pkt;
if (_node_prefs->advert_loc_policy == ADVERT_LOC_NONE) {
pkt = _task->getMesh()->createSelfAdvert(_node_prefs->node_name);
} else {
pkt = _task->getMesh()->createSelfAdvert(_node_prefs->node_name, sensors.node_lat, sensors.node_lon);
}
if (pkt) {
_task->getMesh()->sendZeroHop(pkt);
_task->showAlert("Advert sent!", 1000);
} else {
_task->showAlert("Advert failed..", 1000);
@@ -429,9 +454,11 @@ public:
};
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date) {
_display = display;
_sensors = sensors;
the_mesh = mesh;
_ble_pin = ble_pin;
_auto_off = millis() + AUTO_OFF_MILLIS;
_cached_batt_mv = getBattMilliVolts();
@@ -463,7 +490,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
ui_started_at = millis();
_alert_expiry = 0;
splash = new SplashScreen(this);
splash = new SplashScreen(this, ver, build_date);
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs);
setCurrScreen(splash);
}
@@ -547,6 +574,7 @@ void UITask::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
if (!hasConnection()) {
notify(UIEventType::newContactMessage);
}
((HomeScreen *) home)->addToRecents(contact);
}
void UITask::userLedHandler() {
@@ -794,7 +822,7 @@ char UITask::checkDisplayOn(char c) {
char UITask::handleLongPress(char c) {
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue
the_mesh.enterCLIRescue();
the_mesh->enterCLIRescue();
c = 0; // consume event
}
return c;
@@ -839,7 +867,7 @@ void UITask::toggleGPS() {
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, true);
notify(UIEventType::ack);
}
the_mesh.savePrefs();
the_mesh->savePrefs();
showAlert(_node_prefs->getGpsPrefs()->isGpsEnabled() ? "GPS: Enabled" : "GPS: Disabled", 800);
_next_refresh = 0;
break;
@@ -858,7 +886,7 @@ void UITask::toggleBuzzer() {
buzzer.quiet(true);
}
_node_prefs->buzzer_quiet = buzzer.isQuiet();
the_mesh.savePrefs();
the_mesh->savePrefs();
showAlert(buzzer.isQuiet() ? "Buzzer: OFF" : "Buzzer: ON", 800);
_next_refresh = 0; // trigger refresh
#endif
@@ -4,6 +4,7 @@
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/UIScreen.h>
#include <helpers/SensorManager.h>
#include <helpers/BaseChatMesh.h>
#include <helpers/MultiSerialInterface.h>
#include <Arduino.h>
#include <helpers/sensors/LPPDataHelpers.h>
@@ -22,12 +23,14 @@
#include <helpers/ui/GenericVibration.h>
#endif
#include "../AbstractUITask.h"
#include "../NodePrefs.h"
#include <helpers/ui/AbstractUITask.h>
#include <helpers/CompanionNodePrefs.h>
class UITask : public AbstractUITask {
DisplayDriver* _display;
SensorManager* _sensors;
BaseChatMesh* the_mesh;
uint32_t _ble_pin;
ScrollingStatusBar _statusBar;
#ifdef PIN_BUZZER
genericBuzzer buzzer;
@@ -77,7 +80,7 @@ public:
ui_started_at = 0;
curr = NULL;
}
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date);
void gotoHomeScreen() { setCurrScreen(home); }
void showAlert(const char* text, int duration_millis);
@@ -86,6 +89,9 @@ public:
bool hasDisplay() const { return _display != NULL; }
bool isButtonPressed() const;
BaseChatMesh* getMesh() const { return the_mesh; }
uint32_t getBLEPin() const { return _ble_pin; }
bool isBuzzerQuiet() {
#ifdef PIN_BUZZER
return buzzer.isQuiet();
@@ -98,7 +104,7 @@ public:
bool getGPSState();
void toggleGPS();
// MyMesh::Listener
// MeshEventListener
void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) override;
void onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_details, const char* text) override;
void onQueueSizeChanged(int offline_queue_size) override;
+1 -2
View File
@@ -173,7 +173,7 @@ lib_deps =
extends = Heltec_lora32_v3
build_flags =
${Heltec_lora32_v3.build_flags}
; -I examples/companion_radio/ui-new
-I src/helpers/ui/companion-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D DISPLAY_CLASS=SSD1306Display
@@ -191,7 +191,6 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter}
+<helpers/esp32/*.cpp>
+<helpers/wifi/*.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
+<../variants/heltec_v3/target-companion.cpp>
lib_deps =
${Heltec_lora32_v3.lib_deps}
+4 -1
View File
@@ -2,8 +2,11 @@
#include "target.h"
#ifdef DISPLAY_CLASS
#include <helpers/MultiSerialInterface.h>
extern MultiSerialInterface interface_manager;
DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
// TODO: UITask
UITask ui_task(&board, &interface_manager);
#endif
+19 -6
View File
@@ -21,11 +21,13 @@ build_flags = ${nrf52_base.build_flags}
-D PIN_OLED_RESET=-1
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<TechoCardBoard.cpp>
+<../variants/lilygo_techo_card/TechoCardBoard.cpp>
+<helpers/sensors/EnvironmentSensorManager.cpp>
+<helpers/ui/U8g2Display.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<../variants/lilygo_techo_card>
+<../variants/lilygo_techo_card/target.cpp>
+<../variants/lilygo_techo_card/variant.cpp>
+<helpers/ui/BaseUITask.cpp>
lib_deps =
${nrf52_base.lib_deps}
stevemarple/MicroNMEA @ ^2.0.6
@@ -38,9 +40,12 @@ upload_protocol = nrfutil
[env:LilyGo_T-Echo_Card_repeater]
extends = LilyGo_T-Echo_Card
build_src_filter = ${LilyGo_T-Echo_Card.build_src_filter}
+<helpers/ui/server>
+<../examples/simple_repeater>
+<../variants/lilygo_techo_card/target-other.cpp>
build_flags =
${LilyGo_T-Echo_Card.build_flags}
-I src/helpers/ui/server
-D ADVERT_NAME='"T-Echo Card Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
@@ -52,9 +57,12 @@ build_flags =
[env:LilyGo_T-Echo_Card_room_server]
extends = LilyGo_T-Echo_Card
build_src_filter = ${LilyGo_T-Echo_Card.build_src_filter}
+<helpers/ui/server>
+<../examples/simple_room_server>
+<../variants/lilygo_techo_card/target-other.cpp>
build_flags =
${LilyGo_T-Echo_Card.build_flags}
-I src/helpers/ui/server
-D ADVERT_NAME='"T-Echo Card Room"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
@@ -69,7 +77,7 @@ board_upload.maximum_size = 712704
build_flags =
${LilyGo_T-Echo_Card.build_flags}
-I src/helpers/ui
-I examples/companion_radio/ui-tiny
-I src/helpers/ui/companion-tiny
-D PIN_BUZZER=38
-D QSPIFLASH=1
-D MAX_CONTACTS=350
@@ -84,8 +92,9 @@ build_flags =
-D AUTO_SHUTDOWN_MILLIVOLTS=3300
build_src_filter = ${LilyGo_T-Echo_Card.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<helpers/ui/companion-tiny>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-tiny/*.cpp>
+<../variants/lilygo_techo_card/target-companion.cpp>
+<helpers/ui/buzzer.cpp>
lib_deps =
${LilyGo_T-Echo_Card.lib_deps}
@@ -99,7 +108,7 @@ board_upload.maximum_size = 712704
build_flags =
${LilyGo_T-Echo_Card.build_flags}
-I src/helpers/ui
-I examples/companion_radio/ui-tiny
-I src/helpers/ui/companion-tiny
-D PIN_BUZZER=38
-D QSPIFLASH=1
-D MAX_CONTACTS=350
@@ -112,8 +121,9 @@ build_flags =
-D AUTO_SHUTDOWN_MILLIVOLTS=3300
-D ENABLE_USB_INTERFACE
build_src_filter = ${LilyGo_T-Echo_Card.build_src_filter}
+<helpers/ui/companion-tiny>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-tiny/*.cpp>
+<../variants/lilygo_techo_card/target-companion.cpp>
+<helpers/ui/buzzer.cpp>
lib_deps =
${LilyGo_T-Echo_Card.lib_deps}
@@ -124,3 +134,6 @@ lib_deps =
extends = LilyGo_T-Echo_Card
build_src_filter = ${LilyGo_T-Echo_Card.build_src_filter}
+<../examples/kiss_modem/>
build_flags =
${LilyGo_T-Echo_Card.build_flags}
-U DISPLAY_CLASS
@@ -0,0 +1,13 @@
#include <Arduino.h>
#include "target.h"
#ifdef DISPLAY_CLASS
#include <helpers/MultiSerialInterface.h>
extern MultiSerialInterface interface_manager;
DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
MomentaryButton back_btn(PIN_BUTTON2, 1000, true);
UITask ui_task(&board, &interface_manager);
#endif
@@ -0,0 +1,10 @@
#include <Arduino.h>
#include "target.h"
#ifdef DISPLAY_CLASS
DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
MomentaryButton back_btn(PIN_BUTTON2, 1000, true);
UITask ui_task(board, display);
#endif
-7
View File
@@ -20,13 +20,6 @@ EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
EnvironmentSensorManager sensors = EnvironmentSensorManager();
#endif
#ifdef DISPLAY_CLASS
DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
MomentaryButton back_btn(PIN_BUTTON2, 1000, true);
#endif
bool radio_init() {
rtc_clock.begin(Wire);
+2
View File
@@ -12,6 +12,7 @@
#ifdef DISPLAY_CLASS
#include <helpers/ui/U8g2Display.h>
#include <helpers/ui/MomentaryButton.h>
#include <UITask.h> // needs -I(nclude) path setting
#endif
extern TechoCardBoard board;
@@ -23,6 +24,7 @@ extern EnvironmentSensorManager sensors;
extern DISPLAY_CLASS display;
extern MomentaryButton user_btn;
extern MomentaryButton back_btn;
extern UITask ui_task;
#endif
bool radio_init();
+9 -7
View File
@@ -31,7 +31,9 @@ build_flags = ${nrf52_base.build_flags}
-D ENV_INCLUDE_GPS=1
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<../variants/meshtracker_x1>
+<../variants/meshtracker_x1/MeshTrackerX1Board.cpp>
+<../variants/meshtracker_x1/target.cpp>
+<../variants/meshtracker_x1/variant.cpp>
lib_deps = ${nrf52_base.lib_deps}
https://github.com/adafruit/Adafruit_SPA06_003/archive/refs/tags/1.0.2.zip
stevemarple/MicroNMEA @ ^2.0.6
@@ -41,7 +43,6 @@ upload_protocol = nrfutil
[env:MeshTracker_X1_repeater]
extends = MeshTracker_X1
build_flags = ${MeshTracker_X1.build_flags}
-I examples/companion_radio/ui-orig
-D ADVERT_NAME='"MeshTracker X1 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
@@ -56,7 +57,6 @@ lib_deps = ${MeshTracker_X1.lib_deps}
[env:MeshTracker_X1_room_server]
extends = MeshTracker_X1
build_flags = ${MeshTracker_X1.build_flags}
-I examples/companion_radio/ui-orig
-D ADVERT_NAME='"MeshTracker X1 Room"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
@@ -73,7 +73,7 @@ extends = MeshTracker_X1
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags = ${MeshTracker_X1.build_flags}
-I examples/companion_radio/ui-orig
-I src/helpers/ui/companion-orig
-D QSPIFLASH=1
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
@@ -89,8 +89,9 @@ build_src_filter = ${MeshTracker_X1.build_src_filter}
+<helpers/ui/buzzer.cpp>
+<helpers/ui/NullDisplayDriver.cpp>
+<helpers/ui/DRV2605Vibration.cpp>
+<helpers/ui/companion-orig>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
+<../variants/meshtracker_x1/target-companion.cpp>
lib_deps = ${MeshTracker_X1.lib_deps}
densaugeo/base64 @ ~1.4.0
end2endzone/NonBlockingRTTTL@^1.3.0
@@ -101,7 +102,7 @@ extends = MeshTracker_X1
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags = ${MeshTracker_X1.build_flags}
-I examples/companion_radio/ui-orig
-I src/helpers/ui/companion-orig
-D QSPIFLASH=1
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
@@ -121,8 +122,9 @@ build_src_filter = ${MeshTracker_X1.build_src_filter}
+<helpers/ui/buzzer.cpp>
+<helpers/ui/NullDisplayDriver.cpp>
+<helpers/ui/DRV2605Vibration.cpp>
+<helpers/ui/companion-orig>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
+<../variants/meshtracker_x1/target-companion.cpp>
lib_deps = ${MeshTracker_X1.lib_deps}
densaugeo/base64 @ ~1.4.0
end2endzone/NonBlockingRTTTL@^1.3.0
@@ -0,0 +1,10 @@
#include <Arduino.h>
#include "target.h"
#ifdef DISPLAY_CLASS
#include <helpers/MultiSerialInterface.h>
extern MultiSerialInterface interface_manager;
NullDisplayDriver display;
UITask ui_task(&board, &interface_manager);
#endif
-4
View File
@@ -14,10 +14,6 @@ AirohaGpsDriver gps_driver(Serial1);
MicroNMEALocationProvider nmea(gps_driver, &rtc_clock);
MeshTrackerX1SensorManager sensors = MeshTrackerX1SensorManager(nmea);
#ifdef DISPLAY_CLASS
NullDisplayDriver display;
#endif
bool radio_init() {
return radio.std_init(&SPI);
}
+2
View File
@@ -11,6 +11,7 @@
#include <Adafruit_SPA06_003.h>
#ifdef DISPLAY_CLASS
#include "NullDisplayDriver.h"
#include <UITask.h> // needs -I(nclude) path setting
#endif
class MeshTrackerX1SensorManager: public SensorManager {
@@ -34,6 +35,7 @@ public:
#ifdef DISPLAY_CLASS
extern NullDisplayDriver display;
extern UITask ui_task;
#endif
extern MeshTrackerX1Board board;