diff --git a/examples/companion_radio/DataStore.h b/examples/companion_radio/DataStore.h index e0a145ca..b2100fed 100644 --- a/examples/companion_radio/DataStore.h +++ b/examples/companion_radio/DataStore.h @@ -3,7 +3,7 @@ #include #include #include -#include "NodePrefs.h" +#include class DataStoreHost { public: diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index cd6966e8..9dcb9d05 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -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; diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 846708b5..228f049e 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -23,7 +23,7 @@ #endif #include "DataStore.h" -#include "NodePrefs.h" +#include #include #include @@ -68,6 +68,7 @@ #include #include +#include /* -------------------------------------------------------------------------------------- */ @@ -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; diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 3e7ec6dc..1093efc1 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -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); diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index 835384b7..b6aa79a8 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -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(); }; diff --git a/examples/companion_radio/NodePrefs.h b/src/helpers/CompanionNodePrefs.h similarity index 100% rename from examples/companion_radio/NodePrefs.h rename to src/helpers/CompanionNodePrefs.h diff --git a/src/helpers/MeshEventListener.h b/src/helpers/MeshEventListener.h new file mode 100644 index 00000000..86c4e03f --- /dev/null +++ b/src/helpers/MeshEventListener.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +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() { } +}; diff --git a/examples/companion_radio/AbstractUITask.h b/src/helpers/ui/AbstractUITask.h similarity index 89% rename from examples/companion_radio/AbstractUITask.h rename to src/helpers/ui/AbstractUITask.h index d927c1a3..fa2449a8 100644 --- a/examples/companion_radio/AbstractUITask.h +++ b/src/helpers/ui/AbstractUITask.h @@ -5,15 +5,14 @@ #include #include #include +#include +#include #include #ifdef PIN_BUZZER #include #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; diff --git a/examples/companion_radio/ui-new/UITask.cpp b/src/helpers/ui/companion-new/UITask.cpp similarity index 95% rename from examples/companion_radio/ui-new/UITask.cpp rename to src/helpers/ui/companion-new/UITask.cpp index ee225341..714daa28 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/src/helpers/ui/companion-new/UITask.cpp @@ -1,8 +1,8 @@ #include "UITask.h" #include -#include "../MyMesh.h" #include "target.h" #include +#include #ifdef ENABLE_WIFI_INTERFACE #include #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 diff --git a/examples/companion_radio/ui-new/UITask.h b/src/helpers/ui/companion-new/UITask.h similarity index 89% rename from examples/companion_radio/ui-new/UITask.h rename to src/helpers/ui/companion-new/UITask.h index 045b1060..288a8245 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/src/helpers/ui/companion-new/UITask.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -19,8 +20,8 @@ #include #endif -#include "../AbstractUITask.h" -#include "../NodePrefs.h" +#include +#include #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; diff --git a/examples/companion_radio/ui-new/icons.h b/src/helpers/ui/companion-new/icons.h similarity index 100% rename from examples/companion_radio/ui-new/icons.h rename to src/helpers/ui/companion-new/icons.h diff --git a/examples/companion_radio/ui-orig/Button.cpp b/src/helpers/ui/companion-orig/Button.cpp similarity index 100% rename from examples/companion_radio/ui-orig/Button.cpp rename to src/helpers/ui/companion-orig/Button.cpp diff --git a/examples/companion_radio/ui-orig/Button.h b/src/helpers/ui/companion-orig/Button.h similarity index 100% rename from examples/companion_radio/ui-orig/Button.h rename to src/helpers/ui/companion-orig/Button.h diff --git a/examples/companion_radio/ui-orig/UITask.cpp b/src/helpers/ui/companion-orig/UITask.cpp similarity index 96% rename from examples/companion_radio/ui-orig/UITask.cpp rename to src/helpers/ui/companion-orig/UITask.cpp index c2fd80fb..144e4d60 100644 --- a/examples/companion_radio/ui-orig/UITask.cpp +++ b/src/helpers/ui/companion-orig/UITask.cpp @@ -1,7 +1,7 @@ #include "UITask.h" #include #include -#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(); } diff --git a/examples/companion_radio/ui-orig/UITask.h b/src/helpers/ui/companion-orig/UITask.h similarity index 88% rename from examples/companion_radio/ui-orig/UITask.h rename to src/helpers/ui/companion-orig/UITask.h index d5f79898..21070528 100644 --- a/examples/companion_radio/ui-orig/UITask.h +++ b/src/helpers/ui/companion-orig/UITask.h @@ -3,14 +3,15 @@ #include #include #include +#include #include #ifdef PIN_BUZZER #include #endif -#include "../AbstractUITask.h" -#include "../NodePrefs.h" +#include +#include #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; diff --git a/examples/companion_radio/ui-tiny/ScrollingStatusBar.h b/src/helpers/ui/companion-tiny/ScrollingStatusBar.h similarity index 100% rename from examples/companion_radio/ui-tiny/ScrollingStatusBar.h rename to src/helpers/ui/companion-tiny/ScrollingStatusBar.h diff --git a/examples/companion_radio/ui-tiny/UITask.cpp b/src/helpers/ui/companion-tiny/UITask.cpp similarity index 93% rename from examples/companion_radio/ui-tiny/UITask.cpp rename to src/helpers/ui/companion-tiny/UITask.cpp index 1b48cca8..f9f06aea 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/src/helpers/ui/companion-tiny/UITask.cpp @@ -1,6 +1,5 @@ #include "UITask.h" #include -#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 diff --git a/examples/companion_radio/ui-tiny/UITask.h b/src/helpers/ui/companion-tiny/UITask.h similarity index 87% rename from examples/companion_radio/ui-tiny/UITask.h rename to src/helpers/ui/companion-tiny/UITask.h index 084919aa..ea581edb 100644 --- a/examples/companion_radio/ui-tiny/UITask.h +++ b/src/helpers/ui/companion-tiny/UITask.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -22,12 +23,14 @@ #include #endif -#include "../AbstractUITask.h" -#include "../NodePrefs.h" +#include +#include 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; diff --git a/examples/companion_radio/ui-tiny/u8g2_icons.h b/src/helpers/ui/companion-tiny/u8g2_icons.h similarity index 100% rename from examples/companion_radio/ui-tiny/u8g2_icons.h rename to src/helpers/ui/companion-tiny/u8g2_icons.h diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index a5978c3e..ef9ba10b 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -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} + + +<../examples/companion_radio/*.cpp> - +<../examples/companion_radio/ui-new/*.cpp> +<../variants/heltec_v3/target-companion.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} diff --git a/variants/heltec_v3/target-companion.cpp b/variants/heltec_v3/target-companion.cpp index 571abbb9..3e31880c 100644 --- a/variants/heltec_v3/target-companion.cpp +++ b/variants/heltec_v3/target-companion.cpp @@ -2,8 +2,11 @@ #include "target.h" #ifdef DISPLAY_CLASS + #include + extern MultiSerialInterface interface_manager; + DISPLAY_CLASS display; MomentaryButton user_btn(PIN_USER_BTN, 1000, true); - // TODO: UITask + UITask ui_task(&board, &interface_manager); #endif diff --git a/variants/lilygo_techo_card/platformio.ini b/variants/lilygo_techo_card/platformio.ini index 17ba8d1b..b76eed9a 100644 --- a/variants/lilygo_techo_card/platformio.ini +++ b/variants/lilygo_techo_card/platformio.ini @@ -21,11 +21,13 @@ build_flags = ${nrf52_base.build_flags} -D PIN_OLED_RESET=-1 build_src_filter = ${nrf52_base.build_src_filter} + - + + +<../variants/lilygo_techo_card/TechoCardBoard.cpp> + + + - +<../variants/lilygo_techo_card> + +<../variants/lilygo_techo_card/target.cpp> + +<../variants/lilygo_techo_card/variant.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} + + +<../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} + + +<../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} + + + +<../examples/companion_radio/*.cpp> - +<../examples/companion_radio/ui-tiny/*.cpp> + +<../variants/lilygo_techo_card/target-companion.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} + + +<../examples/companion_radio/*.cpp> - +<../examples/companion_radio/ui-tiny/*.cpp> + +<../variants/lilygo_techo_card/target-companion.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 diff --git a/variants/lilygo_techo_card/target-companion.cpp b/variants/lilygo_techo_card/target-companion.cpp new file mode 100644 index 00000000..481a1a4f --- /dev/null +++ b/variants/lilygo_techo_card/target-companion.cpp @@ -0,0 +1,13 @@ +#include +#include "target.h" + +#ifdef DISPLAY_CLASS + #include + 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 + diff --git a/variants/lilygo_techo_card/target-other.cpp b/variants/lilygo_techo_card/target-other.cpp new file mode 100644 index 00000000..0522b18e --- /dev/null +++ b/variants/lilygo_techo_card/target-other.cpp @@ -0,0 +1,10 @@ +#include +#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 diff --git a/variants/lilygo_techo_card/target.cpp b/variants/lilygo_techo_card/target.cpp index ea74bd0c..6d1e1510 100644 --- a/variants/lilygo_techo_card/target.cpp +++ b/variants/lilygo_techo_card/target.cpp @@ -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); diff --git a/variants/lilygo_techo_card/target.h b/variants/lilygo_techo_card/target.h index f394f7da..bd76e0b7 100644 --- a/variants/lilygo_techo_card/target.h +++ b/variants/lilygo_techo_card/target.h @@ -12,6 +12,7 @@ #ifdef DISPLAY_CLASS #include #include + #include // 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(); diff --git a/variants/meshtracker_x1/platformio.ini b/variants/meshtracker_x1/platformio.ini index 80286460..51a52778 100644 --- a/variants/meshtracker_x1/platformio.ini +++ b/variants/meshtracker_x1/platformio.ini @@ -31,7 +31,9 @@ build_flags = ${nrf52_base.build_flags} -D ENV_INCLUDE_GPS=1 build_src_filter = ${nrf52_base.build_src_filter} + - +<../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} + + + + + +<../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} + + + + + +<../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 diff --git a/variants/meshtracker_x1/target-companion.cpp b/variants/meshtracker_x1/target-companion.cpp new file mode 100644 index 00000000..ed46ebcc --- /dev/null +++ b/variants/meshtracker_x1/target-companion.cpp @@ -0,0 +1,10 @@ +#include +#include "target.h" + +#ifdef DISPLAY_CLASS + #include + extern MultiSerialInterface interface_manager; + + NullDisplayDriver display; + UITask ui_task(&board, &interface_manager); +#endif diff --git a/variants/meshtracker_x1/target.cpp b/variants/meshtracker_x1/target.cpp index 84e0870e..2c1703bc 100644 --- a/variants/meshtracker_x1/target.cpp +++ b/variants/meshtracker_x1/target.cpp @@ -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); } diff --git a/variants/meshtracker_x1/target.h b/variants/meshtracker_x1/target.h index e678e29c..27110343 100644 --- a/variants/meshtracker_x1/target.h +++ b/variants/meshtracker_x1/target.h @@ -11,6 +11,7 @@ #include #ifdef DISPLAY_CLASS #include "NullDisplayDriver.h" + #include // 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;