From 489bcaffc983352be98198604ced5530230a2e4d Mon Sep 17 00:00:00 2001 From: recrof Date: Sun, 31 Aug 2025 16:23:21 +0200 Subject: [PATCH 01/48] raised max contacts for esp32 classic companions to 160 and 170; set to 300 for WSL3 --- variants/heltec_v2/platformio.ini | 6 ++--- variants/heltec_v3/platformio.ini | 6 ++--- variants/lilygo_tbeam_SX1262/platformio.ini | 4 ++-- variants/lilygo_tbeam_SX1276/platformio.ini | 4 ++-- variants/lilygo_tlora_v2_1/platformio.ini | 26 ++++++++++++++++++--- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/variants/heltec_v2/platformio.ini b/variants/heltec_v2/platformio.ini index ea41f845..352ea34d 100644 --- a/variants/heltec_v2/platformio.ini +++ b/variants/heltec_v2/platformio.ini @@ -64,7 +64,7 @@ lib_deps = extends = Heltec_lora32_v2 build_flags = ${Heltec_lora32_v2.build_flags} - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=170 -D MAX_GROUP_CHANNELS=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -80,7 +80,7 @@ build_flags = ${Heltec_lora32_v2.build_flags} -I examples/companion_radio/ui-new -D DISPLAY_CLASS=SSD1306Display - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=170 -D MAX_GROUP_CHANNELS=8 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 @@ -100,7 +100,7 @@ build_flags = ${Heltec_lora32_v2.build_flags} -I examples/companion_radio/ui-new -D DISPLAY_CLASS=SSD1306Display - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=170 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index ba34cead..d667a576 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -87,7 +87,7 @@ extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 -D DISPLAY_CLASS=SSD1306Display ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 @@ -130,7 +130,7 @@ extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 -D DISPLAY_CLASS=SSD1306Display -D WIFI_DEBUG_LOGGING=1 @@ -207,7 +207,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 diff --git a/variants/lilygo_tbeam_SX1262/platformio.ini b/variants/lilygo_tbeam_SX1262/platformio.ini index 7bb008ac..ea8872de 100644 --- a/variants/lilygo_tbeam_SX1262/platformio.ini +++ b/variants/lilygo_tbeam_SX1262/platformio.ini @@ -24,7 +24,7 @@ build_src_filter = ${esp32_base.build_src_filter} +<../variants/lilygo_tbeam_SX1262> + + - + + + board_build.partitions = min_spiffs.csv ; get around 4mb flash limit lib_deps = ${esp32_base.lib_deps} @@ -38,7 +38,7 @@ board_build.upload.maximum_ram_size=2000000 build_flags = ${LilyGo_TBeam_SX1262.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 diff --git a/variants/lilygo_tbeam_SX1276/platformio.ini b/variants/lilygo_tbeam_SX1276/platformio.ini index e0391f1d..782b74c7 100644 --- a/variants/lilygo_tbeam_SX1276/platformio.ini +++ b/variants/lilygo_tbeam_SX1276/platformio.ini @@ -22,7 +22,7 @@ build_src_filter = ${esp32_base.build_src_filter} +<../variants/lilygo_tbeam_SX1276> + + - + + + board_build.partitions = min_spiffs.csv ; get around 4mb flash limit lib_deps = ${esp32_base.lib_deps} @@ -37,7 +37,7 @@ board_build.upload.maximum_ram_size=2000000 build_flags = ${LilyGo_TBeam_SX1276.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 diff --git a/variants/lilygo_tlora_v2_1/platformio.ini b/variants/lilygo_tlora_v2_1/platformio.ini index 0ed06856..05a87d70 100644 --- a/variants/lilygo_tlora_v2_1/platformio.ini +++ b/variants/lilygo_tlora_v2_1/platformio.ini @@ -68,7 +68,7 @@ lib_deps = extends = LilyGo_TLora_V2_1_1_6 build_flags = ${LilyGo_TLora_V2_1_1_6.build_flags} - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -84,7 +84,7 @@ extends = LilyGo_TLora_V2_1_1_6 build_flags = ${LilyGo_TLora_V2_1_1_6.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 @@ -102,7 +102,7 @@ extends = LilyGo_TLora_V2_1_1_6 build_flags = ${LilyGo_TLora_V2_1_1_6.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 + -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 @@ -136,3 +136,23 @@ build_flags = lib_deps = ${LilyGo_TLora_V2_1_1_6.lib_deps} ${esp32_ota.lib_deps} + +[env:LilyGo_TLora_V2_1_1_6_companion_radio_wifi] +extends = LilyGo_TLora_V2_1_1_6 +build_flags = + ${LilyGo_TLora_V2_1_1_6.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=160 + -D MAX_GROUP_CHANNELS=8 + -D WIFI_SSID='"ssid"' + -D WIFI_PWD='"password"' + -D WIFI_DEBUG_LOGGING=1 +build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${LilyGo_TLora_V2_1_1_6.lib_deps} + densaugeo/base64 @ ~1.4.0 From fae3c284d3491da77564e2e158fbbd149864db9c Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 31 Aug 2025 18:09:05 +0200 Subject: [PATCH 02/48] techo: use EnvironmentSensor to get BME280 data --- variants/techo/platformio.ini | 8 ++++ variants/techo/target.cpp | 84 +++-------------------------------- variants/techo/target.h | 20 +-------- 3 files changed, 17 insertions(+), 95 deletions(-) diff --git a/variants/techo/platformio.ini b/variants/techo/platformio.ini index 76712178..e5cfacd4 100644 --- a/variants/techo/platformio.ini +++ b/variants/techo/platformio.ini @@ -22,13 +22,21 @@ build_flags = ${nrf52840_techo.build_flags} -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 -D P_LORA_TX_LED=LED_GREEN + -D DISABLE_DIAGNOSTIC_OUTPUT + -D ENV_INCLUDE_GPS=1 + -D ENV_INCLUDE_BME280=1 + -D GPS_BAUD_RATE=9600 + -D PIN_GPS_EN=GPS_EN + -D TELEM_BME280_ADDRESS=0x77 build_src_filter = ${nrf52840_techo.build_src_filter} + + + + +<../variants/techo> lib_deps = ${nrf52840_techo.lib_deps} stevemarple/MicroNMEA @ ^2.0.6 + adafruit/Adafruit BME280 Library @ ^2.3.0 debug_tool = jlink upload_protocol = nrfutil diff --git a/variants/techo/target.cpp b/variants/techo/target.cpp index 9a10491d..be9a698d 100644 --- a/variants/techo/target.cpp +++ b/variants/techo/target.cpp @@ -11,8 +11,14 @@ WRAPPER_CLASS radio_driver(radio, board); VolatileRTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#ifdef ENV_INCLUDE_GPS MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1); -TechoSensorManager sensors = TechoSensorManager(nmea); +EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); +#else +EnvironmentSensorManager sensors = EnvironmentSensorManager(); +#endif + #ifdef DISPLAY_CLASS DISPLAY_CLASS display; @@ -45,79 +51,3 @@ mesh::LocalIdentity radio_new_identity() { return mesh::LocalIdentity(&rng); // create new random identity } -void TechoSensorManager::start_gps() { - if (!gps_active) { - gps_active = true; - _location->begin(); - } -} - -void TechoSensorManager::stop_gps() { - if (gps_active) { - gps_active = false; - _location->stop(); - } -} - -bool TechoSensorManager::begin() { - Serial1.begin(9600); - - // GPS enabled pin - pinMode(GPS_EN, OUTPUT); - - return true; -} - -bool TechoSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { - if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission? - telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); - } - return true; -} - -void TechoSensorManager::loop() { - static long next_gps_update = 0; - - if (!gps_active) { - return; // GPS is not active, skip further processing - } - - _location->loop(); - - if (millis() > next_gps_update) { - if (_location->isValid()) { - node_lat = ((double)_location->getLatitude())/1000000.; - node_lon = ((double)_location->getLongitude())/1000000.; - node_altitude = ((double)_location->getAltitude()) / 1000.0; - MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon); - } - next_gps_update = millis() + 1000; - } -} - -int TechoSensorManager::getNumSettings() const { - return 1; // always show GPS setting -} - -const char* TechoSensorManager::getSettingName(int i) const { - return (i == 0) ? "gps" : NULL; -} - -const char* TechoSensorManager::getSettingValue(int i) const { - if (i == 0) { - return gps_active ? "1" : "0"; - } - return NULL; -} - -bool TechoSensorManager::setSettingValue(const char* name, const char* value) { - if (strcmp(name, "gps") == 0) { - if (strcmp(value, "0") == 0) { - stop_gps(); - } else { - start_gps(); - } - return true; - } - return false; // not supported -} diff --git a/variants/techo/target.h b/variants/techo/target.h index 58fba687..134f13b5 100644 --- a/variants/techo/target.h +++ b/variants/techo/target.h @@ -7,33 +7,17 @@ #include #include #include +#include #include #ifdef DISPLAY_CLASS #include #include #endif -class TechoSensorManager : public SensorManager { - bool gps_active = false; - LocationProvider* _location; - - void start_gps(); - void stop_gps(); -public: - TechoSensorManager(LocationProvider &location): _location(&location) { } - bool begin() override; - bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; - void loop() override; - int getNumSettings() const override; - const char* getSettingName(int i) const override; - const char* getSettingValue(int i) const override; - bool setSettingValue(const char* name, const char* value) override; -}; - extern TechoBoard board; extern WRAPPER_CLASS radio_driver; extern AutoDiscoverRTCClock rtc_clock; -extern TechoSensorManager sensors; +extern EnvironmentSensorManager sensors; #ifdef DISPLAY_CLASS extern DISPLAY_CLASS display; From 76711f54ce08cc81d8b2552e439b9396dfe5808b Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 31 Aug 2025 21:45:47 +0200 Subject: [PATCH 03/48] techo: let location_manager set clock --- variants/techo/target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/techo/target.cpp b/variants/techo/target.cpp index be9a698d..2ebc0641 100644 --- a/variants/techo/target.cpp +++ b/variants/techo/target.cpp @@ -13,7 +13,7 @@ VolatileRTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); #ifdef ENV_INCLUDE_GPS -MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1); +MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock); EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); #else EnvironmentSensorManager sensors = EnvironmentSensorManager(); From c28001d1e2a04adb7eee2e4ddab42b3510855945 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 1 Sep 2025 14:29:40 +1000 Subject: [PATCH 04/48] * ESP platform ver > 6.11.0 seems to break Github Actions --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index c7d4eff8..1c89465f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -53,7 +53,7 @@ build_src_filter = [esp32_base] extends = arduino_base -platform = platformio/espressif32@^6.11.0 +platform = platformio/espressif32@6.11.0 monitor_filters = esp32_exception_decoder extra_scripts = merge-bin.py build_flags = ${arduino_base.build_flags} From ee194a7b197984ee4b7adc207bb0979e19c6297d Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 1 Sep 2025 15:22:11 +1000 Subject: [PATCH 05/48] * added CommonCLI::saveIdentity() --- examples/simple_repeater/main.cpp | 14 ++++++++++++++ examples/simple_room_server/main.cpp | 14 ++++++++++++++ examples/simple_sensor/SensorMesh.cpp | 14 ++++++++++++++ examples/simple_sensor/SensorMesh.h | 1 + src/helpers/CommonCLI.cpp | 4 +++- src/helpers/CommonCLI.h | 1 + 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 2fda6b85..309be201 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -732,6 +732,20 @@ public: mesh::LocalIdentity& getSelfId() override { return self_id; } + void saveIdentity(const mesh::LocalIdentity& new_id) override { + self_id = new_id; +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + IdentityStore store(*_fs, ""); +#elif defined(ESP32) + IdentityStore store(*_fs, "/identity"); +#elif defined(RP2040_PLATFORM) + IdentityStore store(*_fs, "/identity"); +#else + #error "need to define saveIdentity()" +#endif + store.save("_main", self_id); + } + void clearStats() override { radio_driver.resetStats(); resetStats(); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 77e59d99..76961e22 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -865,6 +865,20 @@ public: mesh::LocalIdentity& getSelfId() override { return self_id; } + void saveIdentity(const mesh::LocalIdentity& new_id) override { + self_id = new_id; +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + IdentityStore store(*_fs, ""); +#elif defined(ESP32) + IdentityStore store(*_fs, "/identity"); +#elif defined(RP2040_PLATFORM) + IdentityStore store(*_fs, "/identity"); +#else + #error "need to define saveIdentity()" +#endif + store.save("_main", self_id); + } + void clearStats() override { radio_driver.resetStats(); resetStats(); diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index ad295501..72c0d97b 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -837,6 +837,20 @@ bool SensorMesh::formatFileSystem() { #endif } +void SensorMesh::saveIdentity(const mesh::LocalIdentity& new_id) { + self_id = new_id; +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + IdentityStore store(*_fs, ""); +#elif defined(ESP32) + IdentityStore store(*_fs, "/identity"); +#elif defined(RP2040_PLATFORM) + IdentityStore store(*_fs, "/identity"); +#else + #error "need to define saveIdentity()" +#endif + store.save("_main", self_id); +} + void SensorMesh::applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) { set_radio_at = futureMillis(2000); // give CLI reply some time to be sent back, before applying temp radio params pending_freq = freq; diff --git a/examples/simple_sensor/SensorMesh.h b/examples/simple_sensor/SensorMesh.h index ddcdf685..89f2ee88 100644 --- a/examples/simple_sensor/SensorMesh.h +++ b/examples/simple_sensor/SensorMesh.h @@ -89,6 +89,7 @@ public: strcpy(reply, "not supported"); } mesh::LocalIdentity& getSelfId() override { return self_id; } + void saveIdentity(const mesh::LocalIdentity& new_id) override; void clearStats() override { } void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override; diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 45dfe29b..7125e5b0 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -305,7 +305,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch uint8_t prv_key[PRV_KEY_SIZE]; bool success = mesh::Utils::fromHex(prv_key, PRV_KEY_SIZE, &config[8]); if (success) { - _callbacks->getSelfId().readFrom(prv_key, PRV_KEY_SIZE); + mesh::LocalIdentity new_id; + new_id.readFrom(prv_key, PRV_KEY_SIZE); + _callbacks->saveIdentity(new_id); strcpy(reply, "OK"); } else { strcpy(reply, "Error, invalid key"); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index d1e49873..ff8ff50e 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -47,6 +47,7 @@ public: // no op by default }; virtual mesh::LocalIdentity& getSelfId() = 0; + virtual void saveIdentity(const mesh::LocalIdentity& new_id) = 0; virtual void clearStats() = 0; virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0; }; From 81afd83099c41a47a41d292e18551cf650ba1538 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 1 Sep 2025 16:10:45 +1000 Subject: [PATCH 06/48] * Meshadventurer companion USB build fix --- variants/meshadventurer/platformio.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variants/meshadventurer/platformio.ini b/variants/meshadventurer/platformio.ini index 3ea09ba7..1b881c1a 100644 --- a/variants/meshadventurer/platformio.ini +++ b/variants/meshadventurer/platformio.ini @@ -80,6 +80,8 @@ extends = Meshadventurer build_src_filter = ${Meshadventurer.build_src_filter} +<../examples/companion_radio/*.cpp> + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> build_flags = ${Meshadventurer.build_flags} -I examples/companion_radio/ui-new From b8223e9d07a967870720319fb68f2244759851e3 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 1 Sep 2025 16:28:53 +1000 Subject: [PATCH 07/48] * reverting HeltecV3 _CURRENT_LIMIT change --- variants/heltec_v3/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index d667a576..f545d898 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -17,7 +17,7 @@ build_flags = -D PIN_VEXT_EN=36 -D SX126X_DIO2_AS_RF_SWITCH=true -D SX126X_DIO3_TCXO_VOLTAGE=1.8 - -D SX126X_CURRENT_LIMIT=160 + -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 -D PIN_GPS_RX=47 -D PIN_GPS_TX=48 From 74722c24b8b0052ed17b4613866247cb35728e0f Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 1 Sep 2025 17:11:55 +1000 Subject: [PATCH 08/48] * MomentaryButton: added support for analog button (with threshold) * RAK: support for PIN_USER_BTN_ANA --- examples/companion_radio/ui-new/UITask.cpp | 11 +++++++++++ src/helpers/ui/MomentaryButton.cpp | 22 +++++++++++++++++++--- src/helpers/ui/MomentaryButton.h | 2 ++ variants/rak4631/target.cpp | 4 ++++ variants/rak4631/target.h | 3 +++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 22f394e7..c751eaf5 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -354,6 +354,9 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no #if defined(PIN_USER_BTN) user_btn.begin(); #endif +#if defined(PIN_USER_BTN_ANA) + analog_btn.begin(); +#endif _node_prefs = node_prefs; if (_display != NULL) { @@ -508,6 +511,14 @@ void UITask::loop() { c = handleLongPress(KEY_RIGHT); } #endif +#if defined(PIN_USER_BTN_ANA) + ev = analog_btn.check(); + if (ev == BUTTON_EVENT_CLICK) { + c = checkDisplayOn(KEY_SELECT); + } else if (ev == BUTTON_EVENT_LONG_PRESS) { + c = handleLongPress(KEY_ENTER); + } +#endif if (c != 0 && curr) { curr->handleInput(c); diff --git a/src/helpers/ui/MomentaryButton.cpp b/src/helpers/ui/MomentaryButton.cpp index 9ddf1327..36309600 100644 --- a/src/helpers/ui/MomentaryButton.cpp +++ b/src/helpers/ui/MomentaryButton.cpp @@ -8,16 +8,29 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse prev = _reverse ? HIGH : LOW; cancel = 0; _long_millis = long_press_millis; + _threshold = 0; +} + +MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, int analog_threshold) { + _pin = pin; + _reverse = false; + _pull = false; + down_at = 0; + prev = LOW; + cancel = 0; + _long_millis = long_press_millis; + _threshold = analog_threshold; } void MomentaryButton::begin() { - if (_pin >= 0) { + if (_pin >= 0 && _threshold == 0) { pinMode(_pin, _pull ? (_reverse ? INPUT_PULLUP : INPUT_PULLDOWN) : INPUT); } } bool MomentaryButton::isPressed() const { - return isPressed(digitalRead(_pin)); + int btn = _threshold > 0 ? (analogRead(_pin) < _threshold) : digitalRead(_pin); + return isPressed(btn); } void MomentaryButton::cancelClick() { @@ -25,6 +38,9 @@ void MomentaryButton::cancelClick() { } bool MomentaryButton::isPressed(int level) const { + if (_threshold > 0) { + return level; + } if (_reverse) { return level == LOW; } else { @@ -36,7 +52,7 @@ int MomentaryButton::check(bool repeat_click) { if (_pin < 0) return BUTTON_EVENT_NONE; int event = BUTTON_EVENT_NONE; - int btn = digitalRead(_pin); + int btn = _threshold > 0 ? (analogRead(_pin) < _threshold) : digitalRead(_pin); if (btn != prev) { if (isPressed(btn)) { down_at = millis(); diff --git a/src/helpers/ui/MomentaryButton.h b/src/helpers/ui/MomentaryButton.h index 0bcc776c..d002f652 100644 --- a/src/helpers/ui/MomentaryButton.h +++ b/src/helpers/ui/MomentaryButton.h @@ -11,12 +11,14 @@ class MomentaryButton { int8_t prev, cancel; bool _reverse, _pull; int _long_millis; + int _threshold; // analog mode unsigned long down_at; bool isPressed(int level) const; public: MomentaryButton(int8_t pin, int long_press_mills=0, bool reverse=false, bool pulldownup=false); + MomentaryButton(int8_t pin, int long_press_mills, int analog_threshold); void begin(); int check(bool repeat_click=false); // returns one of BUTTON_EVENT_* void cancelClick(); // suppress next BUTTON_EVENT_CLICK (if already in DOWN state) diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp index 618c9fc5..efed90aa 100644 --- a/variants/rak4631/target.cpp +++ b/variants/rak4631/target.cpp @@ -11,6 +11,10 @@ RAK4631Board board; #ifdef DISPLAY_CLASS DISPLAY_CLASS display; MomentaryButton user_btn(PIN_USER_BTN, 1000, true); + + #if defined(PIN_USER_BTN_ANA) + MomentaryButton analog_btn(PIN_USER_BTN_ANA, 1000, 20); + #endif #endif RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); diff --git a/variants/rak4631/target.h b/variants/rak4631/target.h index 5e93b7fc..aa6be664 100644 --- a/variants/rak4631/target.h +++ b/variants/rak4631/target.h @@ -13,6 +13,9 @@ extern DISPLAY_CLASS display; #include extern MomentaryButton user_btn; + #if defined(PIN_USER_BTN_ANA) + extern MomentaryButton analog_btn; + #endif #endif extern RAK4631Board board; From 3ad43431d973aeed5cae6d9b584ae895c3b19a22 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Mon, 1 Sep 2025 21:04:41 +1200 Subject: [PATCH 09/48] fixed wismesh pocket user button --- variants/rak4631/target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp index efed90aa..bc7465fd 100644 --- a/variants/rak4631/target.cpp +++ b/variants/rak4631/target.cpp @@ -10,7 +10,7 @@ RAK4631Board board; #ifdef DISPLAY_CLASS DISPLAY_CLASS display; - MomentaryButton user_btn(PIN_USER_BTN, 1000, true); + MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true); #if defined(PIN_USER_BTN_ANA) MomentaryButton analog_btn(PIN_USER_BTN_ANA, 1000, 20); From 637891b81468c2f25acd41260f2512591a1fe3cb Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 1 Sep 2025 19:32:15 +1000 Subject: [PATCH 10/48] * ver bump --- examples/companion_radio/MyMesh.h | 4 ++-- examples/simple_repeater/main.cpp | 4 ++-- examples/simple_room_server/main.cpp | 4 ++-- examples/simple_sensor/SensorMesh.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 89ee8133..e3235128 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -8,11 +8,11 @@ #define FIRMWARE_VER_CODE 7 #ifndef FIRMWARE_BUILD_DATE -#define FIRMWARE_BUILD_DATE "31 Aug 2025" +#define FIRMWARE_BUILD_DATE "1 Sep 2025" #endif #ifndef FIRMWARE_VERSION -#define FIRMWARE_VERSION "v1.8.0" +#define FIRMWARE_VERSION "v1.8.1" #endif #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 309be201..565dc04a 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -22,11 +22,11 @@ /* ------------------------------ Config -------------------------------- */ #ifndef FIRMWARE_BUILD_DATE - #define FIRMWARE_BUILD_DATE "31 Aug 2025" + #define FIRMWARE_BUILD_DATE "1 Sep 2025" #endif #ifndef FIRMWARE_VERSION - #define FIRMWARE_VERSION "v1.8.0" + #define FIRMWARE_VERSION "v1.8.1" #endif #ifndef LORA_FREQ diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 76961e22..fd9c4397 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -22,11 +22,11 @@ /* ------------------------------ Config -------------------------------- */ #ifndef FIRMWARE_BUILD_DATE - #define FIRMWARE_BUILD_DATE "31 Aug 2025" + #define FIRMWARE_BUILD_DATE "1 Sep 2025" #endif #ifndef FIRMWARE_VERSION - #define FIRMWARE_VERSION "v1.8.0" + #define FIRMWARE_VERSION "v1.8.1" #endif #ifndef LORA_FREQ diff --git a/examples/simple_sensor/SensorMesh.h b/examples/simple_sensor/SensorMesh.h index 89f2ee88..7b3b3954 100644 --- a/examples/simple_sensor/SensorMesh.h +++ b/examples/simple_sensor/SensorMesh.h @@ -49,11 +49,11 @@ struct ContactInfo { }; #ifndef FIRMWARE_BUILD_DATE - #define FIRMWARE_BUILD_DATE "31 Aug 2025" + #define FIRMWARE_BUILD_DATE "1 Sep 2025" #endif #ifndef FIRMWARE_VERSION - #define FIRMWARE_VERSION "v1.8.0" + #define FIRMWARE_VERSION "v1.8.1" #endif #define FIRMWARE_ROLE "sensor" From accacd9d744f331e0884f82d8c8d996de0a79d2a Mon Sep 17 00:00:00 2001 From: Rastislav Vysoky Date: Mon, 1 Sep 2025 12:21:03 +0200 Subject: [PATCH 11/48] fixed max_contacts to 300 for v3 --- variants/heltec_v3/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index f545d898..2e7ac80c 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -106,7 +106,7 @@ extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=160 + -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 -D DISPLAY_CLASS=SSD1306Display -D BLE_PIN_CODE=123456 ; dynamic, random PIN From c9671d7d8d00e35f1febe9016aba48fb42bce113 Mon Sep 17 00:00:00 2001 From: Quency-D Date: Tue, 2 Sep 2025 13:56:24 +0800 Subject: [PATCH 12/48] add heltec meshpocket board. --- boards/heltec_mesh_pocket.json | 53 ++++++++++++ examples/simple_repeater/main.cpp | 1 + examples/simple_room_server/main.cpp | 1 + src/helpers/ui/GxEPDDisplay.cpp | 23 +++-- src/helpers/ui/GxEPDDisplay.h | 24 ++++-- variants/mesh_pocket/MeshPocket.cpp | 72 ++++++++++++++++ variants/mesh_pocket/MeshPocket.h | 45 ++++++++++ variants/mesh_pocket/platformio.ini | 104 ++++++++++++++++++++++ variants/mesh_pocket/target.cpp | 72 ++++++++++++++++ variants/mesh_pocket/target.h | 45 ++++++++++ variants/mesh_pocket/variant.cpp | 15 ++++ variants/mesh_pocket/variant.h | 124 +++++++++++++++++++++++++++ 12 files changed, 560 insertions(+), 19 deletions(-) create mode 100644 boards/heltec_mesh_pocket.json create mode 100644 variants/mesh_pocket/MeshPocket.cpp create mode 100644 variants/mesh_pocket/MeshPocket.h create mode 100644 variants/mesh_pocket/platformio.ini create mode 100644 variants/mesh_pocket/target.cpp create mode 100644 variants/mesh_pocket/target.h create mode 100644 variants/mesh_pocket/variant.cpp create mode 100644 variants/mesh_pocket/variant.h diff --git a/boards/heltec_mesh_pocket.json b/boards/heltec_mesh_pocket.json new file mode 100644 index 00000000..6fb48a46 --- /dev/null +++ b/boards/heltec_mesh_pocket.json @@ -0,0 +1,53 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + ["0x239A", "0x4405"], + ["0x239A", "0x0029"], + ["0x239A", "0x002A"] + ], + "usb_product": "HT-n5262", + "mcu": "nrf52840", + "variant": "heltec_mesh_pocket", + "variants_dir": "variants", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "6.1.1", + "sd_fwid": "0x00B6" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": ["bluetooth"], + "debug": { + "jlink_device": "nRF52840_xxAA", + "onboard_tools": ["jlink"], + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" + }, + "frameworks": ["arduino"], + "name": "Heltec nrf (Adafruit BSP)", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": ["jlink", "nrfjprog", "nrfutil", "stlink"], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://heltec.org/project/meshpocket/", + "vendor": "Heltec" + } diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 565dc04a..3f0c0ebe 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -818,6 +818,7 @@ void setup() { #ifdef DISPLAY_CLASS if (display.begin()) { display.startFrame(); + display.setCursor(0, 0); display.print("Please wait..."); display.endFrame(); } diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index fd9c4397..aa9c8e37 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -993,6 +993,7 @@ void setup() { #ifdef DISPLAY_CLASS if (display.begin()) { display.startFrame(); + display.setCursor(0, 0); display.print("Please wait..."); display.endFrame(); } diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index ace25460..55776848 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -5,9 +5,6 @@ #define DISPLAY_ROTATION 3 #endif -#define SCALE_X 1.5625f // 200 / 128 -#define SCALE_Y 1.5625f // 200 / 128 - bool GxEPDDisplay::begin() { display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0)); SPI1.begin(); @@ -77,7 +74,7 @@ void GxEPDDisplay::setColor(Color c) { } void GxEPDDisplay::setCursor(int x, int y) { - display.setCursor(x*SCALE_X, (y+10)*SCALE_Y); + display.setCursor((x+offset_x)*scale_x, (y+offset_y)*scale_y); } void GxEPDDisplay::print(const char* str) { @@ -85,17 +82,17 @@ void GxEPDDisplay::print(const char* str) { } void GxEPDDisplay::fillRect(int x, int y, int w, int h) { - display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color); + display.fillRect(x*scale_x, y*scale_y, w*scale_x, h*scale_y, _curr_color); } void GxEPDDisplay::drawRect(int x, int y, int w, int h) { - display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color); + display.drawRect(x*scale_x, y*scale_y, w*scale_x, h*scale_y, _curr_color); } void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { // Calculate the base position in display coordinates - uint16_t startX = x * SCALE_X; - uint16_t startY = y * SCALE_Y; + uint16_t startX = x * scale_x; + uint16_t startY = y * scale_y; // Width in bytes for bitmap processing uint16_t widthInBytes = (w + 7) / 8; @@ -103,15 +100,15 @@ void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { // Process the bitmap row by row for (uint16_t by = 0; by < h; by++) { // Calculate the target y-coordinates for this logical row - int y1 = startY + (int)(by * SCALE_Y); - int y2 = startY + (int)((by + 1) * SCALE_Y); + int y1 = startY + (int)(by * scale_y); + int y2 = startY + (int)((by + 1) * scale_y); int block_h = y2 - y1; // Scan across the row bit by bit for (uint16_t bx = 0; bx < w; bx++) { // Calculate the target x-coordinates for this logical column - int x1 = startX + (int)(bx * SCALE_X); - int x2 = startX + (int)((bx + 1) * SCALE_X); + int x1 = startX + (int)(bx * scale_x); + int x2 = startX + (int)((bx + 1) * scale_x); int block_w = x2 - x1; // Get the current bit @@ -132,7 +129,7 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) { int16_t x1, y1; uint16_t w, h; display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h); - return ceil((w + 1) / SCALE_X); + return ceil((w + 1) / scale_x); } void GxEPDDisplay::endFrame() { diff --git a/src/helpers/ui/GxEPDDisplay.h b/src/helpers/ui/GxEPDDisplay.h index 49746dee..27364a3d 100644 --- a/src/helpers/ui/GxEPDDisplay.h +++ b/src/helpers/ui/GxEPDDisplay.h @@ -13,11 +13,8 @@ #include #include -#define GxEPD2_DISPLAY_CLASS GxEPD2_BW -#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1 - #include // 1.54" b/w - +#include // 2.13" b/w #include "DisplayDriver.h" //GxEPD2_BW display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)); // DEPG0150BN 200x200, SSD1681, TTGO T5 V2.4.1 @@ -25,15 +22,30 @@ class GxEPDDisplay : public DisplayDriver { +#if defined(HELTEC_MESH_POCKET) + GxEPD2_BW display; + const float scale_x = EINK_SCALE_X; + const float scale_y = EINK_SCALE_Y; + const float offset_x = EINK_X_OFFSET; + const float offset_y = EINK_Y_OFFSET; +#else GxEPD2_BW display; + const float scale_x = 1.5625f; + const float scale_y = 1.5625f; + const float offset_x = 0; + const float offset_y = 10; +#endif bool _init = false; bool _isOn = false; uint16_t _curr_color; public: // there is a margin in y... - GxEPDDisplay() : DisplayDriver(128, 128), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) { - } +#if defined(HELTEC_MESH_POCKET) + GxEPDDisplay() : DisplayDriver(128, 128), display(EINK_DISPLAY_MODEL(PIN_DISPLAY_CS, PIN_DISPLAY_DC, PIN_DISPLAY_RST, PIN_DISPLAY_BUSY)) {} +#else + GxEPDDisplay() : DisplayDriver(128, 128), display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)) {} +#endif bool begin(); diff --git a/variants/mesh_pocket/MeshPocket.cpp b/variants/mesh_pocket/MeshPocket.cpp new file mode 100644 index 00000000..0d0e8993 --- /dev/null +++ b/variants/mesh_pocket/MeshPocket.cpp @@ -0,0 +1,72 @@ +#include +#include "MeshPocket.h" +#include +#include + +static BLEDfu bledfu; + +static void connect_callback(uint16_t conn_handle) +{ + (void)conn_handle; + MESH_DEBUG_PRINTLN("BLE client connected"); +} + +static void disconnect_callback(uint16_t conn_handle, uint8_t reason) +{ + (void)conn_handle; + (void)reason; + + MESH_DEBUG_PRINTLN("BLE client disconnected"); +} + +void HeltecMeshPocket::begin() { + // for future use, sub-classes SHOULD call this from their begin() + startup_reason = BD_STARTUP_NORMAL; + Serial.begin(115200); + pinMode(PIN_VBAT_READ, INPUT); + + pinMode(PIN_USER_BTN, INPUT); +} + +bool HeltecMeshPocket::startOTAUpdate(const char* id, char reply[]) { + // Config the peripheral connection with maximum bandwidth + // more SRAM required by SoftDevice + // Note: All config***() function must be called before begin() + Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); + Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); + + Bluefruit.begin(1, 0); + // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 + Bluefruit.setTxPower(4); + // Set the BLE device name + Bluefruit.setName("MESH_POCKET_OTA"); + + Bluefruit.Periph.setConnectCallback(connect_callback); + Bluefruit.Periph.setDisconnectCallback(disconnect_callback); + + // To be consistent OTA DFU should be added first if it exists + bledfu.begin(); + + // Set up and start advertising + // Advertising packet + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.Advertising.addTxPower(); + Bluefruit.Advertising.addName(); + + /* Start Advertising + - Enable auto advertising if disconnected + - Interval: fast mode = 20 ms, slow mode = 152.5 ms + - Timeout for fast mode is 30 seconds + - Start(timeout) with timeout = 0 will advertise forever (until connected) + + For recommended advertising interval + https://developer.apple.com/library/content/qa/qa1931/_index.html + */ + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds + + strcpy(reply, "OK - started"); + return true; +} diff --git a/variants/mesh_pocket/MeshPocket.h b/variants/mesh_pocket/MeshPocket.h new file mode 100644 index 00000000..82f66dd5 --- /dev/null +++ b/variants/mesh_pocket/MeshPocket.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include + +// built-ins +#define PIN_VBAT_READ 29 +#define PIN_BAT_CTL 34 +#define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range + +class HeltecMeshPocket : public mesh::MainBoard { +protected: + uint8_t startup_reason; + +public: + void begin(); + uint8_t getStartupReason() const override { return startup_reason; } + + + + uint16_t getBattMilliVolts() override { + int adcvalue = 0; + analogReadResolution(12); + analogReference(AR_INTERNAL_3_0); + pinMode(PIN_BAT_CTL, OUTPUT); // battery adc can be read only ctrl pin set to high + pinMode(PIN_VBAT_READ, INPUT); + digitalWrite(PIN_BAT_CTL, HIGH); + + delay(10); + adcvalue = analogRead(PIN_VBAT_READ); + digitalWrite(PIN_BAT_CTL, LOW); + + return (uint16_t)((float)adcvalue * MV_LSB * 4.9); + } + + const char* getManufacturerName() const override { + return "Heltec MeshPocket"; + } + + void reboot() override { + NVIC_SystemReset(); + } + + bool startOTAUpdate(const char* id, char reply[]) override; +}; diff --git a/variants/mesh_pocket/platformio.ini b/variants/mesh_pocket/platformio.ini new file mode 100644 index 00000000..e492d515 --- /dev/null +++ b/variants/mesh_pocket/platformio.ini @@ -0,0 +1,104 @@ +[Mesh_pocket] +extends = nrf52_base +board = heltec_mesh_pocket +platform_packages = framework-arduinoadafruitnrf52 +board_build.ldscript = boards/nrf52840_s140_v6.ld +build_flags = ${nrf52_base.build_flags} + -I src/helpers/nrf52 + -I lib/nrf52/s140_nrf52_6.1.1_API/include + -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 + -I variants/mesh_pocket + -D HELTEC_MESH_POCKET + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D LORA_TX_POWER=22 + -D SX126X_CURRENT_LIMIT=140 + -D SX126X_RX_BOOSTED_GAIN=1 + -D EINK_DISPLAY_MODEL=GxEPD2_213_B74 + -D EINK_SCALE_X=1.953125f + -D EINK_SCALE_Y=1.28f + -D EINK_X_OFFSET=0 + -D EINK_Y_OFFSET=10 + -D DISPLAY_CLASS=GxEPDDisplay +build_src_filter = ${nrf52_base.build_src_filter} + + + +<../variants/mesh_pocket> + + +lib_deps = + ${nrf52_base.lib_deps} + adafruit/Adafruit EPD @ 4.6.1 + rweather/Crypto @ ^0.4.0 + stevemarple/MicroNMEA @ ^2.0.6 + zinggjm/GxEPD2 @ 1.6.2 + +debug_tool = jlink +upload_protocol = nrfutil + +[env:Mesh_pocket_repeater] +extends = Mesh_pocket +build_src_filter = ${Mesh_pocket.build_src_filter} + +<../examples/simple_repeater> + +build_flags = + ${Mesh_pocket.build_flags} + -D ADVERT_NAME='"Heltec_Mesh_Pocket Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=8 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 + +[env:Mesh_pocket_room_server] +extends = Mesh_pocket +build_src_filter = ${Mesh_pocket.build_src_filter} + +<../examples/simple_room_server> +build_flags = + ${Mesh_pocket.build_flags} + -D ADVERT_NAME='"Heltec_Mesh_Pocket Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 + +[env:Mesh_pocket_companion_radio_ble] +extends = Mesh_pocket +build_flags = + ${Mesh_pocket.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 + -D BLE_PIN_CODE=123456 + -D OFFLINE_QUEUE_SIZE=256 +; -D BLE_DEBUG_LOGGING=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 + +build_src_filter = ${Mesh_pocket.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Mesh_pocket.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:Mesh_pocket_companion_radio_usb] +extends = Mesh_pocket +build_flags = + ${Mesh_pocket.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 +; -D BLE_PIN_CODE=123456 +; -D BLE_DEBUG_LOGGING=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${Mesh_pocket.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Mesh_pocket.lib_deps} + densaugeo/base64 @ ~1.4.0 \ No newline at end of file diff --git a/variants/mesh_pocket/target.cpp b/variants/mesh_pocket/target.cpp new file mode 100644 index 00000000..0821e0e8 --- /dev/null +++ b/variants/mesh_pocket/target.cpp @@ -0,0 +1,72 @@ +#include +#include "target.h" +#include +#include + +HeltecMeshPocket board; + +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); + +WRAPPER_CLASS radio_driver(radio, board); + +MeshPocketSensorManager sensors = MeshPocketSensorManager(); + +VolatileRTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display; + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); +#endif + +bool radio_init() { + return radio.std_init(&SPI); +} + +uint32_t radio_get_rng_seed() { + return radio.random(0x7FFFFFFF); +} + +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { + radio.setFrequency(freq); + radio.setSpreadingFactor(sf); + radio.setBandwidth(bw); + radio.setCodingRate(cr); +} + +void radio_set_tx_power(uint8_t dbm) { + radio.setOutputPower(dbm); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); // create new random identity +} + +bool MeshPocketSensorManager::begin() { + return true; +} + +void MeshPocketSensorManager::loop() { + +} + +bool MeshPocketSensorManager::querySensors(uint8_t requester_permission, CayenneLPP& telemetry) { + return true; +} + +int MeshPocketSensorManager::getNumSettings() const { + return 0; +} + +const char* MeshPocketSensorManager::getSettingName(int i) const { + return NULL; +} + +const char* MeshPocketSensorManager::getSettingValue(int i) const { + return NULL; +} + +bool MeshPocketSensorManager::setSettingValue(const char* name, const char* value) { + return false; +} \ No newline at end of file diff --git a/variants/mesh_pocket/target.h b/variants/mesh_pocket/target.h new file mode 100644 index 00000000..a44c8c52 --- /dev/null +++ b/variants/mesh_pocket/target.h @@ -0,0 +1,45 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include +#include "MeshPocket.h" + +#ifdef DISPLAY_CLASS +#include +#include +#endif + +extern HeltecMeshPocket board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; + +#ifdef DISPLAY_CLASS + extern DISPLAY_CLASS display; + extern MomentaryButton user_btn; +#endif + +bool radio_init(); +uint32_t radio_get_rng_seed(); +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); +void radio_set_tx_power(uint8_t dbm); +mesh::LocalIdentity radio_new_identity(); + +class MeshPocketSensorManager : public SensorManager { +public: + MeshPocketSensorManager() {}; + bool begin() override; + bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry); + void loop(); + int getNumSettings() const override; + const char* getSettingName(int i) const override; + const char* getSettingValue(int i) const override; + bool setSettingValue(const char* name, const char* value) override; +}; + +extern MeshPocketSensorManager sensors; + diff --git a/variants/mesh_pocket/variant.cpp b/variants/mesh_pocket/variant.cpp new file mode 100644 index 00000000..cf7dd44f --- /dev/null +++ b/variants/mesh_pocket/variant.cpp @@ -0,0 +1,15 @@ +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const int MISO = PIN_SPI1_MISO; +const int MOSI = PIN_SPI1_MOSI; +const int SCK = PIN_SPI1_SCK; + +const uint32_t g_ADigitalPinMap[] = { + // P0 - pins 0 and 1 are hardwired for xtal and should never be enabled + 0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; \ No newline at end of file diff --git a/variants/mesh_pocket/variant.h b/variants/mesh_pocket/variant.h new file mode 100644 index 00000000..870d062a --- /dev/null +++ b/variants/mesh_pocket/variant.h @@ -0,0 +1,124 @@ +/* + * variant.h + * MIT License + */ + +#pragma once + +#include "WVariant.h" + +//////////////////////////////////////////////////////////////////////////////// +// Low frequency clock source + +#define USE_LFXO // 32.768 kHz crystal oscillator +#define VARIANT_MCK (64000000ul) + + +//////////////////////////////////////////////////////////////////////////////// +// Power + +#define BATTERY_PIN (0 + 29) +#define PIN_BAT_CTRL (32 + 2) +#define ADC_MULTIPLIER (4.90F) + +#define ADC_RESOLUTION (14) +#define BATTERY_SENSE_RES (12) + +#define AREF_VOLTAGE (3.0) + +//////////////////////////////////////////////////////////////////////////////// +// Number of pins + +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (1) +#define NUM_ANALOG_OUTPUTS (0) + +//////////////////////////////////////////////////////////////////////////////// +// UART pin definition + +#define PIN_SERIAL1_RX (37) +#define PIN_SERIAL1_TX (39) + +#define PIN_SERIAL2_RX (7) +#define PIN_SERIAL2_TX (8) + +//////////////////////////////////////////////////////////////////////////////// +// I2C pin definition +#define WIRE_INTERFACES_COUNT (1) + +#define PIN_WIRE_SDA (32+15) +#define PIN_WIRE_SCL (32+13) + +//////////////////////////////////////////////////////////////////////////////// +// Builtin LEDs + +#define LED_BUILTIN (13) +#define PIN_LED LED_BUILTIN +#define LED_RED LED_BUILTIN +#define LED_BLUE (-1) // No blue led, prevents Bluefruit flashing the green LED during advertising +#define PIN_STATUS_LED LED_BUILTIN + +#define LED_STATE_ON LOW + +//////////////////////////////////////////////////////////////////////////////// +// Builtin buttons + +#define PIN_BUTTON1 (32 + 10) +#define BUTTON_PIN PIN_BUTTON1 + +// #define PIN_BUTTON2 (0 + 18) +// #define BUTTON_PIN2 PIN_BUTTON2 + +#define PIN_USER_BTN BUTTON_PIN + +//////////////////////////////////////////////////////////////////////////////// + +// SPI pin definition +#define SPI_INTERFACES_COUNT (2) + +// Lora +#define USE_SX1262 +#define SX126X_CS (0 + 26) +#define SX126X_DIO1 (0 + 16) +#define SX126X_BUSY (0 + 15) +#define SX126X_RESET (0 + 12) +#define SX126X_DIO2_AS_RF_SWITCH true +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +#define PIN_SPI_MISO (32 + 9) +#define PIN_SPI_MOSI (0 + 5) +#define PIN_SPI_SCK (0 + 4) + +#define LORA_CS SX126X_CS +#define P_LORA_DIO_1 SX126X_DIO1 +#define P_LORA_NSS SX126X_CS +#define P_LORA_RESET SX126X_RESET +#define P_LORA_BUSY SX126X_BUSY +#define P_LORA_SCLK PIN_SPI_SCK +#define P_LORA_MISO PIN_SPI_MISO +#define P_LORA_MOSI PIN_SPI_MOSI + + +//////////////////////////////////////////////////////////////////////////////// +// EInk + +#define PIN_DISPLAY_CS (24) +#define PIN_DISPLAY_BUSY (32 + 6) +#define PIN_DISPLAY_DC (31) +#define PIN_DISPLAY_RST (32 + 4) + +#define PIN_SPI1_MISO (-1) +#define PIN_SPI1_MOSI (20) +#define PIN_SPI1_SCK (22) + + +// GxEPD2 needs that for a panel that is not even used ! +extern const int MISO; +extern const int MOSI; +extern const int SCK; + + +#undef HAS_GPS +#define HAS_GPS 0 +#define HAS_RTC 0 \ No newline at end of file From 3cdf2f9b4de9eaeb53f76ab5523f149dd20bc063 Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Tue, 2 Sep 2025 11:43:48 +0200 Subject: [PATCH 13/48] techo: display backlight behavior --- examples/companion_radio/ui-new/UITask.cpp | 8 ++++++++ src/helpers/ui/GxEPDDisplay.cpp | 5 +++-- variants/techo/platformio.ini | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index c751eaf5..f0f9ed1d 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -519,6 +519,14 @@ void UITask::loop() { c = handleLongPress(KEY_ENTER); } #endif +#if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN) + static int next_btn_check = 0; + if (millis() > next_btn_check) { + bool touch_state = digitalRead(PIN_BUTTON2); + digitalWrite(DISP_BACKLIGHT, !touch_state); + next_btn_check = millis() + 300; + } +#endif if (c != 0 && curr) { curr->handleInput(c); diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index ace25460..9ba7d074 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -19,6 +19,7 @@ bool GxEPDDisplay::begin() { display.fillScreen(GxEPD_WHITE); display.display(true); #if DISP_BACKLIGHT + digitalWrite(DISP_BACKLIGHT, LOW); pinMode(DISP_BACKLIGHT, OUTPUT); #endif _init = true; @@ -27,14 +28,14 @@ bool GxEPDDisplay::begin() { void GxEPDDisplay::turnOn() { if (!_init) begin(); -#if DISP_BACKLIGHT +#if defined(DISP_BACKLIGHT) && !defined(BACLIGHT_BTN) digitalWrite(DISP_BACKLIGHT, HIGH); #endif _isOn = true; } void GxEPDDisplay::turnOff() { -#if DISP_BACKLIGHT +#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN) digitalWrite(DISP_BACKLIGHT, LOW); #endif _isOn = false; diff --git a/variants/techo/platformio.ini b/variants/techo/platformio.ini index e5cfacd4..260be35f 100644 --- a/variants/techo/platformio.ini +++ b/variants/techo/platformio.ini @@ -78,6 +78,7 @@ build_flags = -D DISPLAY_CLASS=GxEPDDisplay -D OFFLINE_QUEUE_SIZE=256 -D UI_RECENT_LIST_SIZE=9 + -D BACKLIGHT_BTN=PIN_BUTTON2 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${LilyGo_Techo.build_src_filter} From 90cb1e73f9c7709a244981d7c14291330878c53a Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Tue, 2 Sep 2025 21:18:05 +1000 Subject: [PATCH 14/48] * HeltecV3: powerOff() fix --- src/helpers/HeltecV3Board.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/helpers/HeltecV3Board.h b/src/helpers/HeltecV3Board.h index b71514cc..c63ed2d8 100644 --- a/src/helpers/HeltecV3Board.h +++ b/src/helpers/HeltecV3Board.h @@ -85,8 +85,7 @@ public: } void powerOff() override { - // TODO: re-enable this when there is a definite wake-up source pin: - // enterDeepSleep(0); + enterDeepSleep(0); } uint16_t getBattMilliVolts() override { From 03358b33c22d909d2414fa4f53010f7aa6f98a2b Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 2 Sep 2025 21:30:51 +1000 Subject: [PATCH 15/48] fix: promicro: add powerOff --- variants/promicro/PromicroBoard.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/variants/promicro/PromicroBoard.h b/variants/promicro/PromicroBoard.h index 89e71755..e4b67415 100644 --- a/variants/promicro/PromicroBoard.h +++ b/variants/promicro/PromicroBoard.h @@ -60,6 +60,10 @@ public: void reboot() override { NVIC_SystemReset(); } + + void powerOff() override { + sd_power_system_off(); + } bool startOTAUpdate(const char* id, char reply[]) override; }; From ddc900c8c8675c4ebc42edc8bfdf2b50fdb02c0d Mon Sep 17 00:00:00 2001 From: recrof Date: Tue, 2 Sep 2025 22:23:32 +0200 Subject: [PATCH 16/48] renamend and refactored vision master to play better with build system --- ...sion_master_e213.json => heltec_e213.json} | 0 ...sion_master_e290.json => heltec_e290.json} | 0 ...sion_master_t190.json => heltec_t190.json} | 0 .../HeltecE213Board.cpp | 6 +- .../HeltecE213Board.h | 10 --- .../pins_arduino.h | 0 .../platformio.ini | 69 +++++++++++++------ .../target.cpp | 0 .../target.h | 0 .../HeltecE290Board.cpp | 6 +- .../HeltecE290Board.h | 9 --- .../pins_arduino.h | 0 .../platformio.ini | 69 +++++++++++++------ .../target.cpp | 0 .../target.h | 0 .../HeltecT190Board.cpp | 6 +- .../HeltecT190Board.h | 9 --- .../pins_arduino.h | 0 .../platformio.ini | 61 +++++++++++----- .../target.cpp | 0 .../target.h | 0 21 files changed, 143 insertions(+), 102 deletions(-) rename boards/{heltec_vision_master_e213.json => heltec_e213.json} (100%) rename boards/{heltec_vision_master_e290.json => heltec_e290.json} (100%) rename boards/{heltec_vision_master_t190.json => heltec_t190.json} (100%) rename variants/{heltec_vision_master_e213 => heltec_e213}/HeltecE213Board.cpp (94%) rename variants/{heltec_vision_master_e213 => heltec_e213}/HeltecE213Board.h (66%) rename variants/{heltec_vision_master_e213 => heltec_e213}/pins_arduino.h (100%) rename variants/{heltec_vision_master_e213 => heltec_e213}/platformio.ini (56%) rename variants/{heltec_vision_master_e213 => heltec_e213}/target.cpp (100%) rename variants/{heltec_vision_master_e213 => heltec_e213}/target.h (100%) rename variants/{heltec_vision_master_e290 => heltec_e290}/HeltecE290Board.cpp (94%) rename variants/{heltec_vision_master_e290 => heltec_e290}/HeltecE290Board.h (66%) rename variants/{heltec_vision_master_e290 => heltec_e290}/pins_arduino.h (100%) rename variants/{heltec_vision_master_e290 => heltec_e290}/platformio.ini (53%) rename variants/{heltec_vision_master_e290 => heltec_e290}/target.cpp (100%) rename variants/{heltec_vision_master_e290 => heltec_e290}/target.h (100%) rename variants/{heltec_vision_master_t190 => heltec_t190}/HeltecT190Board.cpp (94%) rename variants/{heltec_vision_master_t190 => heltec_t190}/HeltecT190Board.h (67%) rename variants/{heltec_vision_master_t190 => heltec_t190}/pins_arduino.h (100%) rename variants/{heltec_vision_master_t190 => heltec_t190}/platformio.ini (57%) rename variants/{heltec_vision_master_t190 => heltec_t190}/target.cpp (100%) rename variants/{heltec_vision_master_t190 => heltec_t190}/target.h (100%) diff --git a/boards/heltec_vision_master_e213.json b/boards/heltec_e213.json similarity index 100% rename from boards/heltec_vision_master_e213.json rename to boards/heltec_e213.json diff --git a/boards/heltec_vision_master_e290.json b/boards/heltec_e290.json similarity index 100% rename from boards/heltec_vision_master_e290.json rename to boards/heltec_e290.json diff --git a/boards/heltec_vision_master_t190.json b/boards/heltec_t190.json similarity index 100% rename from boards/heltec_vision_master_t190.json rename to boards/heltec_t190.json diff --git a/variants/heltec_vision_master_e213/HeltecE213Board.cpp b/variants/heltec_e213/HeltecE213Board.cpp similarity index 94% rename from variants/heltec_vision_master_e213/HeltecE213Board.cpp rename to variants/heltec_e213/HeltecE213Board.cpp index d32d274e..af115318 100644 --- a/variants/heltec_vision_master_e213/HeltecE213Board.cpp +++ b/variants/heltec_e213/HeltecE213Board.cpp @@ -23,7 +23,7 @@ void HeltecE213Board::begin() { void HeltecE213Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); - // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep + // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); @@ -44,8 +44,7 @@ void HeltecE213Board::begin() { } void HeltecE213Board::powerOff() { - // TODO: re-enable this when there is a definite wake-up source pin: - // enterDeepSleep(0); + enterDeepSleep(0); } uint16_t HeltecE213Board::getBattMilliVolts() { @@ -66,4 +65,3 @@ void HeltecE213Board::begin() { const char* HeltecE213Board::getManufacturerName() const { return "Heltec E213"; } - diff --git a/variants/heltec_vision_master_e213/HeltecE213Board.h b/variants/heltec_e213/HeltecE213Board.h similarity index 66% rename from variants/heltec_vision_master_e213/HeltecE213Board.h rename to variants/heltec_e213/HeltecE213Board.h index dd622064..2192c141 100644 --- a/variants/heltec_vision_master_e213/HeltecE213Board.h +++ b/variants/heltec_e213/HeltecE213Board.h @@ -5,15 +5,6 @@ #include #include -// LoRa radio module pins for heltec_vision_master_e213 -#define P_LORA_DIO_1 14 -#define P_LORA_NSS 8 -#define P_LORA_RESET 12 -#define P_LORA_BUSY 13 -#define P_LORA_SCLK 9 -#define P_LORA_MISO 11 -#define P_LORA_MOSI 10 - class HeltecE213Board : public ESP32Board { public: @@ -26,5 +17,4 @@ public: void powerOff() override; uint16_t getBattMilliVolts() override; const char* getManufacturerName() const override ; - }; diff --git a/variants/heltec_vision_master_e213/pins_arduino.h b/variants/heltec_e213/pins_arduino.h similarity index 100% rename from variants/heltec_vision_master_e213/pins_arduino.h rename to variants/heltec_e213/pins_arduino.h diff --git a/variants/heltec_vision_master_e213/platformio.ini b/variants/heltec_e213/platformio.ini similarity index 56% rename from variants/heltec_vision_master_e213/platformio.ini rename to variants/heltec_e213/platformio.ini index c6b68724..c8efc819 100644 --- a/variants/heltec_vision_master_e213/platformio.ini +++ b/variants/heltec_e213/platformio.ini @@ -1,14 +1,22 @@ -[Heltec_Vision_Master_E213_base] +[Heltec_E213_base] extends = esp32_base -board = heltec_vision_master_e213 +board = heltec_e213 build_flags = ${esp32_base.build_flags} - -I variants/heltec_vision_master_e213 - -D HELTEC_VISION_MASTER_E213 + -I variants/heltec_e213 + -D Vision_Master_E213 + -D ARDUINO_USB_CDC_ON_BOOT=1 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper - -D LORA_TX_POWER=22 + -D P_LORA_DIO_1=14 + -D P_LORA_NSS=8 + -D P_LORA_RESET=12 + -D P_LORA_BUSY=13 + -D P_LORA_SCLK=9 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 -D P_LORA_TX_LED=45 + -D LORA_TX_POWER=22 -D PIN_USER_BTN=0 -D PIN_VEXT_EN=18 -D PIN_VEXT_EN_ACTIVE=HIGH @@ -26,17 +34,16 @@ build_flags = -D DISP_RST=3 -D DISP_SCLK=4 -D DISP_MOSI=6 - -D Vision_Master_E213 build_src_filter = ${esp32_base.build_src_filter} - +<../variants/heltec_vision_master_e213> + +<../variants/heltec_e213> lib_deps = ${esp32_base.lib_deps} https://github.com/Quency-D/heltec-eink-modules/archive/563dd41fd850a1bc3039b8723da4f3a20fe1c800.zip -[env:Heltec_Vision_Master_E213_radio_ble] -extends = Heltec_Vision_Master_E213_base +[env:Heltec_E213_companion_radio_ble] +extends = Heltec_E213_base build_flags = - ${Heltec_Vision_Master_E213_base.build_flags} + ${Heltec_E213_base.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 @@ -44,43 +51,61 @@ build_flags = -D BLE_PIN_CODE=123456 ; dynamic, random PIN -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 -build_src_filter = ${Heltec_Vision_Master_E213_base.build_src_filter} +build_src_filter = ${Heltec_E213_base.build_src_filter} + + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${Heltec_Vision_Master_E213_base.lib_deps} + ${Heltec_E213_base.lib_deps} densaugeo/base64 @ ~1.4.0 -[env:Heltec_Vision_Master_E213_repeater] -extends = Heltec_Vision_Master_E213_base +[env:Heltec_E213_companion_radio_usb] +extends = Heltec_E213_base build_flags = - ${Heltec_Vision_Master_E213_base.build_flags} + ${Heltec_E213_base.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=300 + -D MAX_GROUP_CHANNELS=8 + -D DISPLAY_CLASS=E213Display + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${Heltec_E213_base.build_src_filter} + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Heltec_E213_base.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:Heltec_E213_repeater] +extends = Heltec_E213_base +build_flags = + ${Heltec_E213_base.build_flags} -D DISPLAY_CLASS=E213Display -D ADVERT_NAME='"Heltec E213 Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -build_src_filter = ${Heltec_Vision_Master_E213_base.build_src_filter} +build_src_filter = ${Heltec_E213_base.build_src_filter} + +<../examples/simple_repeater> lib_deps = - ${Heltec_Vision_Master_E213_base.lib_deps} + ${Heltec_E213_base.lib_deps} ${esp32_ota.lib_deps} -[env:Heltec_Vision_Master_E213_room_server] -extends = Heltec_Vision_Master_E213_base +[env:Heltec_E213_room_server] +extends = Heltec_E213_base build_flags = - ${Heltec_Vision_Master_E213_base.build_flags} + ${Heltec_E213_base.build_flags} -D DISPLAY_CLASS=E213Display -D ADVERT_NAME='"Heltec E213 Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D ROOM_PASSWORD='"hello"' -build_src_filter = ${Heltec_Vision_Master_E213_base.build_src_filter} +build_src_filter = ${Heltec_E213_base.build_src_filter} + +<../examples/simple_room_server> lib_deps = - ${Heltec_Vision_Master_E213_base.lib_deps} + ${Heltec_E213_base.lib_deps} ${esp32_ota.lib_deps} diff --git a/variants/heltec_vision_master_e213/target.cpp b/variants/heltec_e213/target.cpp similarity index 100% rename from variants/heltec_vision_master_e213/target.cpp rename to variants/heltec_e213/target.cpp diff --git a/variants/heltec_vision_master_e213/target.h b/variants/heltec_e213/target.h similarity index 100% rename from variants/heltec_vision_master_e213/target.h rename to variants/heltec_e213/target.h diff --git a/variants/heltec_vision_master_e290/HeltecE290Board.cpp b/variants/heltec_e290/HeltecE290Board.cpp similarity index 94% rename from variants/heltec_vision_master_e290/HeltecE290Board.cpp rename to variants/heltec_e290/HeltecE290Board.cpp index 7d8c654d..3994a206 100644 --- a/variants/heltec_vision_master_e290/HeltecE290Board.cpp +++ b/variants/heltec_e290/HeltecE290Board.cpp @@ -23,7 +23,7 @@ void HeltecE290Board::begin() { void HeltecE290Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); - // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep + // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); @@ -44,8 +44,7 @@ void HeltecE290Board::begin() { } void HeltecE290Board::powerOff() { - // TODO: re-enable this when there is a definite wake-up source pin: - // enterDeepSleep(0); + enterDeepSleep(0); } uint16_t HeltecE290Board::getBattMilliVolts() { @@ -66,4 +65,3 @@ void HeltecE290Board::begin() { const char* HeltecE290Board::getManufacturerName() const { return "Heltec E290"; } - diff --git a/variants/heltec_vision_master_e290/HeltecE290Board.h b/variants/heltec_e290/HeltecE290Board.h similarity index 66% rename from variants/heltec_vision_master_e290/HeltecE290Board.h rename to variants/heltec_e290/HeltecE290Board.h index 95f8c03e..ff16e273 100644 --- a/variants/heltec_vision_master_e290/HeltecE290Board.h +++ b/variants/heltec_e290/HeltecE290Board.h @@ -5,15 +5,6 @@ #include #include -// LoRa radio module pins for heltec_vision_master_e290 -#define P_LORA_DIO_1 14 -#define P_LORA_NSS 8 -#define P_LORA_RESET 12 -#define P_LORA_BUSY 13 -#define P_LORA_SCLK 9 -#define P_LORA_MISO 11 -#define P_LORA_MOSI 10 - class HeltecE290Board : public ESP32Board { public: diff --git a/variants/heltec_vision_master_e290/pins_arduino.h b/variants/heltec_e290/pins_arduino.h similarity index 100% rename from variants/heltec_vision_master_e290/pins_arduino.h rename to variants/heltec_e290/pins_arduino.h diff --git a/variants/heltec_vision_master_e290/platformio.ini b/variants/heltec_e290/platformio.ini similarity index 53% rename from variants/heltec_vision_master_e290/platformio.ini rename to variants/heltec_e290/platformio.ini index 4150adc8..377162f4 100644 --- a/variants/heltec_vision_master_e290/platformio.ini +++ b/variants/heltec_e290/platformio.ini @@ -1,13 +1,21 @@ -[Heltec_Vision_Master_E290_base] +[Heltec_E290_base] extends = esp32_base -board = heltec_vision_master_e290 +board = heltec_e290 build_flags = ${esp32_base.build_flags} - -I variants/heltec_vision_master_e290 - -D HELTEC_VISION_MASTER_E290 + -I variants/heltec_e290 + -D Vision_Master_E290 + -D ARDUINO_USB_CDC_ON_BOOT=1 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 + -D P_LORA_DIO_1=14 + -D P_LORA_NSS=8 + -D P_LORA_RESET=12 + -D P_LORA_BUSY=13 + -D P_LORA_SCLK=9 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 -D P_LORA_TX_LED=45 -D PIN_USER_BTN=0 -D PIN_VEXT_EN=18 @@ -20,17 +28,16 @@ build_flags = -D SX126X_RX_BOOSTED_GAIN=1 -D PIN_BOARD_SDA=39 -D PIN_BOARD_SCL=38 - -D Vision_Master_E290 build_src_filter = ${esp32_base.build_src_filter} - +<../variants/heltec_vision_master_e290> + +<../variants/heltec_e290> lib_deps = ${esp32_base.lib_deps} https://github.com/Quency-D/heltec-eink-modules/archive/563dd41fd850a1bc3039b8723da4f3a20fe1c800.zip -[env:Heltec_Vision_Master_E290_radio_ble] -extends = Heltec_Vision_Master_E290_base +[env:Heltec_E290_companion_radio_ble] +extends = Heltec_E290_base build_flags = - ${Heltec_Vision_Master_E290_base.build_flags} + ${Heltec_E290_base.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 @@ -38,43 +45,63 @@ build_flags = -D BLE_PIN_CODE=123456 ; dynamic, random PIN -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 -build_src_filter = ${Heltec_Vision_Master_E290_base.build_src_filter} +build_src_filter = ${Heltec_E290_base.build_src_filter} + + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${Heltec_Vision_Master_E290_base.lib_deps} + ${Heltec_E290_base.lib_deps} densaugeo/base64 @ ~1.4.0 -[env:Heltec_Vision_Master_E290_repeater] -extends = Heltec_Vision_Master_E290_base +[env:Heltec_E290_companion_radio_usb] +extends = Heltec_E290_base build_flags = - ${Heltec_Vision_Master_E290_base.build_flags} + ${Heltec_E290_base.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=300 + -D MAX_GROUP_CHANNELS=8 + -D DISPLAY_CLASS=E290Display + -D BLE_PIN_CODE=123456 ; dynamic, random PIN + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${Heltec_E290_base.build_src_filter} + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Heltec_E290_base.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:Heltec_E290_repeater] +extends = Heltec_E290_base +build_flags = + ${Heltec_E290_base.build_flags} -D DISPLAY_CLASS=E290Display -D ADVERT_NAME='"Heltec E290 Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -build_src_filter = ${Heltec_Vision_Master_E290_base.build_src_filter} +build_src_filter = ${Heltec_E290_base.build_src_filter} + +<../examples/simple_repeater> lib_deps = - ${Heltec_Vision_Master_E290_base.lib_deps} + ${Heltec_E290_base.lib_deps} ${esp32_ota.lib_deps} -[env:Heltec_Vision_Master_E290_room_server] -extends = Heltec_Vision_Master_E290_base +[env:Heltec_E290_room_server] +extends = Heltec_E290_base build_flags = - ${Heltec_Vision_Master_E290_base.build_flags} + ${Heltec_E290_base.build_flags} -D DISPLAY_CLASS=E290Display -D ADVERT_NAME='"Heltec E290 Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D ROOM_PASSWORD='"hello"' -build_src_filter = ${Heltec_Vision_Master_E290_base.build_src_filter} +build_src_filter = ${Heltec_E290_base.build_src_filter} + +<../examples/simple_room_server> lib_deps = - ${Heltec_Vision_Master_E290_base.lib_deps} + ${Heltec_E290_base.lib_deps} ${esp32_ota.lib_deps} diff --git a/variants/heltec_vision_master_e290/target.cpp b/variants/heltec_e290/target.cpp similarity index 100% rename from variants/heltec_vision_master_e290/target.cpp rename to variants/heltec_e290/target.cpp diff --git a/variants/heltec_vision_master_e290/target.h b/variants/heltec_e290/target.h similarity index 100% rename from variants/heltec_vision_master_e290/target.h rename to variants/heltec_e290/target.h diff --git a/variants/heltec_vision_master_t190/HeltecT190Board.cpp b/variants/heltec_t190/HeltecT190Board.cpp similarity index 94% rename from variants/heltec_vision_master_t190/HeltecT190Board.cpp rename to variants/heltec_t190/HeltecT190Board.cpp index c5b03bc8..4f35be40 100644 --- a/variants/heltec_vision_master_t190/HeltecT190Board.cpp +++ b/variants/heltec_t190/HeltecT190Board.cpp @@ -23,7 +23,7 @@ void HeltecT190Board::begin() { void HeltecT190Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); - // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep + // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); @@ -44,8 +44,7 @@ void HeltecT190Board::begin() { } void HeltecT190Board::powerOff() { - // TODO: re-enable this when there is a definite wake-up source pin: - // enterDeepSleep(0); + enterDeepSleep(0); } uint16_t HeltecT190Board::getBattMilliVolts() { @@ -66,4 +65,3 @@ void HeltecT190Board::begin() { const char* HeltecT190Board::getManufacturerName() const { return "Heltec T190"; } - diff --git a/variants/heltec_vision_master_t190/HeltecT190Board.h b/variants/heltec_t190/HeltecT190Board.h similarity index 67% rename from variants/heltec_vision_master_t190/HeltecT190Board.h rename to variants/heltec_t190/HeltecT190Board.h index 96c09c1c..bc38c1e0 100644 --- a/variants/heltec_vision_master_t190/HeltecT190Board.h +++ b/variants/heltec_t190/HeltecT190Board.h @@ -5,15 +5,6 @@ #include #include -// LoRa radio module pins for heltec_vision_master_e290 -#define P_LORA_DIO_1 14 -#define P_LORA_NSS 8 -#define P_LORA_RESET 12 -#define P_LORA_BUSY 13 -#define P_LORA_SCLK 9 -#define P_LORA_MISO 11 -#define P_LORA_MOSI 10 - class HeltecT190Board : public ESP32Board { public: diff --git a/variants/heltec_vision_master_t190/pins_arduino.h b/variants/heltec_t190/pins_arduino.h similarity index 100% rename from variants/heltec_vision_master_t190/pins_arduino.h rename to variants/heltec_t190/pins_arduino.h diff --git a/variants/heltec_vision_master_t190/platformio.ini b/variants/heltec_t190/platformio.ini similarity index 57% rename from variants/heltec_vision_master_t190/platformio.ini rename to variants/heltec_t190/platformio.ini index e8492335..7debe178 100644 --- a/variants/heltec_vision_master_t190/platformio.ini +++ b/variants/heltec_t190/platformio.ini @@ -1,13 +1,20 @@ -[Heltec_Vision_Master_T190_base] +[Heltec_T190_base] extends = esp32_base -board = heltec_vision_master_t190 +board = heltec_t190 build_flags = ${esp32_base.build_flags} - -I variants/heltec_vision_master_t190 + -I variants/heltec_t190 -I src/helpers/ui -D HELTEC_VISION_MASTER_T190 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper + -D P_LORA_DIO_1=14 + -D P_LORA_NSS=8 + -D P_LORA_RESET=12 + -D P_LORA_BUSY=13 + -D P_LORA_SCLK=9 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 -D LORA_TX_POWER=22 -D PIN_USER_BTN=0 -D PIN_VEXT_EN=5 @@ -31,7 +38,7 @@ build_flags = -D ST7789 -D DISPLAY_CLASS=ST7789Display build_src_filter = ${esp32_base.build_src_filter} - +<../variants/heltec_vision_master_t190> + +<../variants/heltec_t190> + + + @@ -40,48 +47,64 @@ lib_deps = ${esp32_base.lib_deps} adafruit/Adafruit GFX Library @ ^1.12.1 -[env:Heltec_Vision_Master_T190_radio_ble] -extends = Heltec_Vision_Master_T190_base +[env:Heltec_T190_companion_radio_ble] +extends = Heltec_T190_base build_flags = - ${Heltec_Vision_Master_T190_base.build_flags} + ${Heltec_T190_base.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 ; dynamic, random PIN -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 -build_src_filter = ${Heltec_Vision_Master_T190_base.build_src_filter} +build_src_filter = ${Heltec_T190_base.build_src_filter} + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${Heltec_Vision_Master_T190_base.lib_deps} + ${Heltec_T190_base.lib_deps} densaugeo/base64 @ ~1.4.0 -[env:Heltec_Vision_Master_T190_repeater] -extends = Heltec_Vision_Master_T190_base +[env:Heltec_T190_companion_radio_usb] +extends = Heltec_T190_base build_flags = - ${Heltec_Vision_Master_T190_base.build_flags} + ${Heltec_T190_base.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=300 + -D MAX_GROUP_CHANNELS=8 + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${Heltec_T190_base.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Heltec_T190_base.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:Heltec_T190_repeater] +extends = Heltec_T190_base +build_flags = + ${Heltec_T190_base.build_flags} -D ADVERT_NAME='"Heltec T190 Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -build_src_filter = ${Heltec_Vision_Master_T190_base.build_src_filter} +build_src_filter = ${Heltec_T190_base.build_src_filter} +<../examples/simple_repeater> lib_deps = - ${Heltec_Vision_Master_T190_base.lib_deps} + ${Heltec_T190_base.lib_deps} ${esp32_ota.lib_deps} -[env:Heltec_Vision_Master_T190_room_server] -extends = Heltec_Vision_Master_T190_base +[env:Heltec_T190_room_server] +extends = Heltec_T190_base build_flags = - ${Heltec_Vision_Master_T190_base.build_flags} + ${Heltec_T190_base.build_flags} -D ADVERT_NAME='"Heltec T190 Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' -D ROOM_PASSWORD='"hello"' -build_src_filter = ${Heltec_Vision_Master_T190_base.build_src_filter} +build_src_filter = ${Heltec_T190_base.build_src_filter} +<../examples/simple_room_server> lib_deps = - ${Heltec_Vision_Master_T190_base.lib_deps} + ${Heltec_T190_base.lib_deps} ${esp32_ota.lib_deps} diff --git a/variants/heltec_vision_master_t190/target.cpp b/variants/heltec_t190/target.cpp similarity index 100% rename from variants/heltec_vision_master_t190/target.cpp rename to variants/heltec_t190/target.cpp diff --git a/variants/heltec_vision_master_t190/target.h b/variants/heltec_t190/target.h similarity index 100% rename from variants/heltec_vision_master_t190/target.h rename to variants/heltec_t190/target.h From ce31fd7c572d025ca96fab9e2a87fa705fba570c Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 08:25:59 +1000 Subject: [PATCH 17/48] multi click support including buzzer toggle --- examples/companion_radio/ui-new/UITask.cpp | 46 +++++++++++++++++++--- examples/companion_radio/ui-new/UITask.h | 6 +++ src/helpers/ui/MomentaryButton.cpp | 38 +++++++++++++++++- src/helpers/ui/MomentaryButton.h | 6 +++ 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index c751eaf5..d3fc5bad 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -495,6 +495,10 @@ void UITask::loop() { c = checkDisplayOn(KEY_SELECT); } else if (ev == BUTTON_EVENT_LONG_PRESS) { c = handleLongPress(KEY_ENTER); + } else if (ev == BUTTON_EVENT_DOUBLE_CLICK) { + c = handleDoubleClick(KEY_ENTER); + } else if (ev == BUTTON_EVENT_TRIPLE_CLICK) { + c = handleTripleClick(KEY_ENTER); } #endif #if defined(WIO_TRACKER_L1) @@ -604,10 +608,43 @@ char UITask::handleLongPress(char c) { return c; } -/* -void UITask::handleButtonTriplePress() { - MESH_DEBUG_PRINTLN("UITask: triple press triggered"); - // Toggle buzzer quiet mode +char UITask::handleDoubleClick(char c) { + MESH_DEBUG_PRINTLN("UITask: double click triggered"); + c = 0; + return c; +} + +char UITask::handleTripleClick(char c) { + MESH_DEBUG_PRINTLN("UITask: triple click triggered"); + toggleBuzzer(); + c = 0; + return c; +} + +void UITask::toggleGPS() { + if (_sensors != NULL) { + // toggle GPS on/off + int num = _sensors->getNumSettings(); + for (int i = 0; i < num; i++) { + if (strcmp(_sensors->getSettingName(i), "gps") == 0) { + if (strcmp(_sensors->getSettingValue(i), "1") == 0) { + _sensors->setSettingValue("gps", "0"); + soundBuzzer(UIEventType::ack); + showAlert("GPS: Disabled", 600); + } else { + _sensors->setSettingValue("gps", "1"); + soundBuzzer(UIEventType::ack); + showAlert("GPS: Enabled", 600); + } + _next_refresh = 0; + break; + } + } + } +} + +void UITask::toggleBuzzer() { + // Toggle buzzer quiet mode #ifdef PIN_BUZZER if (buzzer.isQuiet()) { buzzer.quiet(false); @@ -620,4 +657,3 @@ void UITask::handleButtonTriplePress() { _next_refresh = 0; // trigger refresh #endif } -*/ diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index f9e01550..a96abf89 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -37,6 +37,8 @@ class UITask : public AbstractUITask { // Button action handlers char checkDisplayOn(char c); char handleLongPress(char c); + char handleDoubleClick(char c); + char handleTripleClick(char c); void setCurrScreen(UIScreen* c); @@ -55,6 +57,10 @@ public: bool hasDisplay() const { return _display != NULL; } bool isButtonPressed() const; + void toggleBuzzer(); + void toggleGPS(); + + // from AbstractUITask void msgRead(int msgcount) override; void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override; diff --git a/src/helpers/ui/MomentaryButton.cpp b/src/helpers/ui/MomentaryButton.cpp index 36309600..4b87705a 100644 --- a/src/helpers/ui/MomentaryButton.cpp +++ b/src/helpers/ui/MomentaryButton.cpp @@ -9,6 +9,10 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse cancel = 0; _long_millis = long_press_millis; _threshold = 0; + _click_count = 0; + _last_click_time = 0; + _multi_click_window = 500; + _pending_click = false; } MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, int analog_threshold) { @@ -20,6 +24,10 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, int analog_t cancel = 0; _long_millis = long_press_millis; _threshold = analog_threshold; + _click_count = 0; + _last_click_time = 0; + _multi_click_window = 500; + _pending_click = false; } void MomentaryButton::begin() { @@ -35,6 +43,8 @@ bool MomentaryButton::isPressed() const { void MomentaryButton::cancelClick() { cancel = 1; + _click_count = 0; + _pending_click = false; } bool MomentaryButton::isPressed(int level) const { @@ -60,10 +70,14 @@ int MomentaryButton::check(bool repeat_click) { // button UP if (_long_millis > 0) { if (down_at > 0 && (unsigned long)(millis() - down_at) < _long_millis) { // only a CLICK if still within the long_press millis - event = BUTTON_EVENT_CLICK; + _click_count++; + _last_click_time = millis(); + _pending_click = true; } } else { - event = BUTTON_EVENT_CLICK; // any UP results in CLICK event when NOT using long_press feature + _click_count++; + _last_click_time = millis(); + _pending_click = true; } if (event == BUTTON_EVENT_CLICK && cancel) { event = BUTTON_EVENT_NONE; @@ -87,5 +101,25 @@ int MomentaryButton::check(bool repeat_click) { } } + if (_pending_click && (millis() - _last_click_time) >= _multi_click_window) { + switch (_click_count) { + case 1: + event = BUTTON_EVENT_CLICK; + break; + case 2: + event = BUTTON_EVENT_DOUBLE_CLICK; + break; + case 3: + event = BUTTON_EVENT_TRIPLE_CLICK; + break; + default: + // For 4+ clicks, treat as triple click? + event = BUTTON_EVENT_TRIPLE_CLICK; + break; + } + _click_count = 0; + _pending_click = false; + } + return event; } \ No newline at end of file diff --git a/src/helpers/ui/MomentaryButton.h b/src/helpers/ui/MomentaryButton.h index d002f652..1122e56a 100644 --- a/src/helpers/ui/MomentaryButton.h +++ b/src/helpers/ui/MomentaryButton.h @@ -5,6 +5,8 @@ #define BUTTON_EVENT_NONE 0 #define BUTTON_EVENT_CLICK 1 #define BUTTON_EVENT_LONG_PRESS 2 +#define BUTTON_EVENT_DOUBLE_CLICK 3 +#define BUTTON_EVENT_TRIPLE_CLICK 4 class MomentaryButton { int8_t _pin; @@ -13,6 +15,10 @@ class MomentaryButton { int _long_millis; int _threshold; // analog mode unsigned long down_at; + uint8_t _click_count; + unsigned long _last_click_time; + int _multi_click_window; + bool _pending_click; bool isPressed(int level) const; From 43c3105bf1d0fc8c0682960352bf0f3aedb64af1 Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 08:31:38 +1000 Subject: [PATCH 18/48] wake screen on double and triple clicks --- examples/companion_radio/ui-new/UITask.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index d3fc5bad..1c565a8a 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -610,12 +610,14 @@ char UITask::handleLongPress(char c) { char UITask::handleDoubleClick(char c) { MESH_DEBUG_PRINTLN("UITask: double click triggered"); + checkDisplayOn(c); c = 0; return c; } char UITask::handleTripleClick(char c) { MESH_DEBUG_PRINTLN("UITask: triple click triggered"); + checkDisplayOn(c); toggleBuzzer(); c = 0; return c; From 5de0dc1fd6152a7f3bb5a34f0f8e0679138093c8 Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 12:03:31 +1000 Subject: [PATCH 19/48] sliding multiclick window --- src/helpers/ui/MomentaryButton.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/helpers/ui/MomentaryButton.cpp b/src/helpers/ui/MomentaryButton.cpp index 4b87705a..0446c639 100644 --- a/src/helpers/ui/MomentaryButton.cpp +++ b/src/helpers/ui/MomentaryButton.cpp @@ -11,7 +11,7 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse _threshold = 0; _click_count = 0; _last_click_time = 0; - _multi_click_window = 500; + _multi_click_window = 260; _pending_click = false; } @@ -26,7 +26,7 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, int analog_t _threshold = analog_threshold; _click_count = 0; _last_click_time = 0; - _multi_click_window = 500; + _multi_click_window = 260; _pending_click = false; } @@ -81,6 +81,9 @@ int MomentaryButton::check(bool repeat_click) { } if (event == BUTTON_EVENT_CLICK && cancel) { event = BUTTON_EVENT_NONE; + _click_count = 0; + _last_click_time = 0; + _pending_click = false; } down_at = 0; } @@ -93,6 +96,9 @@ int MomentaryButton::check(bool repeat_click) { if (_long_millis > 0 && down_at > 0 && (unsigned long)(millis() - down_at) >= _long_millis) { event = BUTTON_EVENT_LONG_PRESS; down_at = 0; + _click_count = 0; + _last_click_time = 0; + _pending_click = false; } if (down_at > 0 && repeat_click) { unsigned long diff = (unsigned long)(millis() - down_at); @@ -118,6 +124,7 @@ int MomentaryButton::check(bool repeat_click) { break; } _click_count = 0; + _last_click_time = 0; _pending_click = false; } From 9f185303b4448df72c2fa38d844a6d6b8ecdae72 Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 12:29:20 +1000 Subject: [PATCH 20/48] long press cancels multi click --- src/helpers/ui/MomentaryButton.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/helpers/ui/MomentaryButton.cpp b/src/helpers/ui/MomentaryButton.cpp index 0446c639..0ea4b027 100644 --- a/src/helpers/ui/MomentaryButton.cpp +++ b/src/helpers/ui/MomentaryButton.cpp @@ -1,5 +1,7 @@ #include "MomentaryButton.h" +#define MULTI_CLICK_WINDOW_MS 280 + MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse, bool pulldownup) { _pin = pin; _reverse = reverse; @@ -11,7 +13,7 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse _threshold = 0; _click_count = 0; _last_click_time = 0; - _multi_click_window = 260; + _multi_click_window = MULTI_CLICK_WINDOW_MS; _pending_click = false; } @@ -26,7 +28,7 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, int analog_t _threshold = analog_threshold; _click_count = 0; _last_click_time = 0; - _multi_click_window = 260; + _multi_click_window = MULTI_CLICK_WINDOW_MS; _pending_click = false; } @@ -43,7 +45,9 @@ bool MomentaryButton::isPressed() const { void MomentaryButton::cancelClick() { cancel = 1; + down_at = 0; _click_count = 0; + _last_click_time = 0; _pending_click = false; } @@ -94,11 +98,16 @@ int MomentaryButton::check(bool repeat_click) { } if (_long_millis > 0 && down_at > 0 && (unsigned long)(millis() - down_at) >= _long_millis) { - event = BUTTON_EVENT_LONG_PRESS; - down_at = 0; - _click_count = 0; - _last_click_time = 0; - _pending_click = false; + if (_pending_click) { + // long press during multi-click detection - cancel pending clicks + cancelClick(); + } else { + event = BUTTON_EVENT_LONG_PRESS; + down_at = 0; + _click_count = 0; + _last_click_time = 0; + _pending_click = false; + } } if (down_at > 0 && repeat_click) { unsigned long diff = (unsigned long)(millis() - down_at); @@ -108,6 +117,10 @@ int MomentaryButton::check(bool repeat_click) { } if (_pending_click && (millis() - _last_click_time) >= _multi_click_window) { + if (down_at > 0) { + // still pressed - wait for button release before processing clicks + return event; + } switch (_click_count) { case 1: event = BUTTON_EVENT_CLICK; From a9ab1f072a78e0eea51e7f469af00be9536b16f4 Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 14:02:35 +1000 Subject: [PATCH 21/48] increase gps/buzzer alert times 600 is a bit short for eink --- examples/companion_radio/ui-new/UITask.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 1c565a8a..39eb26b3 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -632,11 +632,11 @@ void UITask::toggleGPS() { if (strcmp(_sensors->getSettingValue(i), "1") == 0) { _sensors->setSettingValue("gps", "0"); soundBuzzer(UIEventType::ack); - showAlert("GPS: Disabled", 600); + showAlert("GPS: Disabled", 800); } else { _sensors->setSettingValue("gps", "1"); soundBuzzer(UIEventType::ack); - showAlert("GPS: Enabled", 600); + showAlert("GPS: Enabled", 800); } _next_refresh = 0; break; @@ -651,10 +651,10 @@ void UITask::toggleBuzzer() { if (buzzer.isQuiet()) { buzzer.quiet(false); soundBuzzer(UIEventType::ack); - showAlert("Buzzer: ON", 600); + showAlert("Buzzer: ON", 800); } else { buzzer.quiet(true); - showAlert("Buzzer: OFF", 600); + showAlert("Buzzer: OFF", 800); } _next_refresh = 0; // trigger refresh #endif From afbfc6c6edd223a9f7bfd4eae0305394afa026b6 Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 15:48:50 +1000 Subject: [PATCH 22/48] add new keycodes --- src/helpers/ui/UIScreen.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/helpers/ui/UIScreen.h b/src/helpers/ui/UIScreen.h index 6faa591a..6aa1d69c 100644 --- a/src/helpers/ui/UIScreen.h +++ b/src/helpers/ui/UIScreen.h @@ -2,13 +2,17 @@ #include "DisplayDriver.h" -#define KEY_LEFT 0xB4 -#define KEY_UP 0xB5 -#define KEY_DOWN 0xB6 -#define KEY_RIGHT 0xB7 -#define KEY_SELECT 10 -#define KEY_ENTER 13 -#define KEY_BACK 27 // Esc +#define KEY_LEFT 0xB4 +#define KEY_UP 0xB5 +#define KEY_DOWN 0xB6 +#define KEY_RIGHT 0xB7 +#define KEY_SELECT 10 +#define KEY_ENTER 13 +#define KEY_CANCEL 27 // Esc +#define KEY_HOME 0xF0 +#define KEY_NEXT 0xF1 +#define KEY_PREV 0xF2 +#define KEY_CONTEXT_MENU 0xF3 class UIScreen { protected: From 96a71bb21b6f93fd8f7c22496ff4999ec406249a Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 3 Sep 2025 16:28:58 +1000 Subject: [PATCH 23/48] alter keycode keycode handling --- examples/companion_radio/ui-new/UITask.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 39eb26b3..dfc545d0 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -223,11 +223,11 @@ public: } bool handleInput(char c) override { - if (c == KEY_LEFT) { + if (c == KEY_LEFT || c == KEY_PREV) { _page = (_page + HomePage::Count - 1) % HomePage::Count; return true; } - if (c == KEY_RIGHT || c == KEY_SELECT) { + if (c == KEY_NEXT || c == KEY_RIGHT) { _page = (_page + 1) % HomePage::Count; if (_page == HomePage::RECENT) { _task->showAlert("Recent adverts", 800); @@ -325,7 +325,7 @@ public: } bool handleInput(char c) override { - if (c == KEY_SELECT || c == KEY_RIGHT) { + if (c == KEY_NEXT || c == KEY_RIGHT) { num_unread--; if (num_unread == 0) { _task->gotoHomeScreen(); @@ -492,13 +492,13 @@ void UITask::loop() { #if defined(PIN_USER_BTN) int ev = user_btn.check(); if (ev == BUTTON_EVENT_CLICK) { - c = checkDisplayOn(KEY_SELECT); + c = checkDisplayOn(KEY_NEXT); } else if (ev == BUTTON_EVENT_LONG_PRESS) { c = handleLongPress(KEY_ENTER); } else if (ev == BUTTON_EVENT_DOUBLE_CLICK) { - c = handleDoubleClick(KEY_ENTER); + c = handleDoubleClick(KEY_PREV); } else if (ev == BUTTON_EVENT_TRIPLE_CLICK) { - c = handleTripleClick(KEY_ENTER); + c = handleTripleClick(KEY_SELECT); } #endif #if defined(WIO_TRACKER_L1) @@ -518,9 +518,13 @@ void UITask::loop() { #if defined(PIN_USER_BTN_ANA) ev = analog_btn.check(); if (ev == BUTTON_EVENT_CLICK) { - c = checkDisplayOn(KEY_SELECT); + c = checkDisplayOn(KEY_NEXT); } else if (ev == BUTTON_EVENT_LONG_PRESS) { c = handleLongPress(KEY_ENTER); + } else if (ev == BUTTON_EVENT_DOUBLE_CLICK) { + c = handleDoubleClick(KEY_PREV); + } else if (ev == BUTTON_EVENT_TRIPLE_CLICK) { + c = handleTripleClick(KEY_SELECT); } #endif @@ -611,7 +615,6 @@ char UITask::handleLongPress(char c) { char UITask::handleDoubleClick(char c) { MESH_DEBUG_PRINTLN("UITask: double click triggered"); checkDisplayOn(c); - c = 0; return c; } From cb3049e706201e300681981590feceeb5af02a91 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 3 Sep 2025 17:22:11 +0200 Subject: [PATCH 24/48] cleanups (remove statics and typos) --- examples/companion_radio/ui-new/UITask.cpp | 33 +++++++++------------- examples/companion_radio/ui-new/UITask.h | 6 ++++ src/helpers/ui/GxEPDDisplay.cpp | 2 +- variants/techo/platformio.ini | 1 + 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index f0f9ed1d..a02b0288 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -419,38 +419,34 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i if (_display != NULL) { if (!_display->isOn()) _display->turnOn(); _auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer - _next_refresh = 0; // trigger refresh + _next_refresh = 100; // trigger refresh } } void UITask::userLedHandler() { #ifdef PIN_STATUS_LED - static int state = 0; - static int next_change = 0; - static int last_increment = 0; - int cur_time = millis(); - if (cur_time > next_change) { - if (state == 0) { - state = 1; + if (cur_time > next_led_change) { + if (led_state == 0) { + led_state = 1; if (_msgcount > 0) { - last_increment = LED_ON_MSG_MILLIS; + last_led_increment = LED_ON_MSG_MILLIS; } else { - last_increment = LED_ON_MILLIS; + last_led_increment = LED_ON_MILLIS; } - next_change = cur_time + last_increment; + next_led_change = cur_time + last_led_increment; } else { - state = 0; - next_change = cur_time + LED_CYCLE_MILLIS - last_increment; + led_state = 0; + next_led_change = cur_time + LED_CYCLE_MILLIS - last_led_increment; } - digitalWrite(PIN_STATUS_LED, state); + digitalWrite(PIN_STATUS_LED, led_state); } #endif } void UITask::setCurrScreen(UIScreen* c) { curr = c; - _next_refresh = 0; + _next_refresh = 100; } /* @@ -520,18 +516,17 @@ void UITask::loop() { } #endif #if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN) - static int next_btn_check = 0; - if (millis() > next_btn_check) { + if (millis() > next_backlight_btn_check) { bool touch_state = digitalRead(PIN_BUTTON2); digitalWrite(DISP_BACKLIGHT, !touch_state); - next_btn_check = millis() + 300; + next_backlight_btn_check = millis() + 300; } #endif if (c != 0 && curr) { curr->handleInput(c); _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer - _next_refresh = 0; // trigger refresh + _next_refresh = 100; // trigger refresh } userLedHandler(); diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index f9e01550..3a27e55f 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -26,6 +26,12 @@ class UITask : public AbstractUITask { unsigned long _alert_expiry; int _msgcount; unsigned long ui_started_at, next_batt_chck; + int next_backlight_btn_check = 0; +#ifdef PIN_STATUS_LED + int led_state = 0; + int next_led_change = 0; + int last_led_increment = 0; +#endif UIScreen* splash; UIScreen* home; diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index 9ba7d074..49022d74 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -28,7 +28,7 @@ bool GxEPDDisplay::begin() { void GxEPDDisplay::turnOn() { if (!_init) begin(); -#if defined(DISP_BACKLIGHT) && !defined(BACLIGHT_BTN) +#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN) digitalWrite(DISP_BACKLIGHT, HIGH); #endif _isOn = true; diff --git a/variants/techo/platformio.ini b/variants/techo/platformio.ini index 260be35f..f748fdfe 100644 --- a/variants/techo/platformio.ini +++ b/variants/techo/platformio.ini @@ -92,3 +92,4 @@ lib_deps = ${LilyGo_Techo.lib_deps} densaugeo/base64 @ ~1.4.0 zinggjm/GxEPD2 @ 1.6.2 + bakercp/CRC32 @ ^2.0.0 From 9f97edcb21f01fb126bd94f55a1215d965c41999 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 3 Sep 2025 18:17:37 +0200 Subject: [PATCH 25/48] gxepd: use a crc to track damage ! --- examples/companion_radio/ui-new/UITask.cpp | 10 ++++++++- src/helpers/ui/GxEPDDisplay.cpp | 26 +++++++++++++++++++++- src/helpers/ui/GxEPDDisplay.h | 3 +++ variants/techo/platformio.ini | 3 ++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index a02b0288..8ca5c950 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -3,7 +3,9 @@ #include "../MyMesh.h" #include "target.h" -#define AUTO_OFF_MILLIS 15000 // 15 seconds +#ifndef AUTO_OFF_MILLIS + #define AUTO_OFF_MILLIS 15000 // 15 seconds +#endif #define BOOT_SCREEN_MILLIS 3000 // 3 seconds #ifdef PIN_STATUS_LED @@ -321,7 +323,11 @@ public: display.setColor(DisplayDriver::LIGHT); display.printWordWrap(p->msg, display.width()); +#if AUTO_OFF_MILLIS==0 // probably e-ink + return 10000; // 10 s +#else return 1000; // next render after 1000 ms +#endif } bool handleInput(char c) override { @@ -556,9 +562,11 @@ void UITask::loop() { } _display->endFrame(); } +#if AUTO_OFF_MILLIS > 0 if (millis() > _auto_off) { _display->turnOff(); } +#endif } #ifdef AUTO_SHUTDOWN_MILLIVOLTS diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index 49022d74..98b34eaa 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -44,14 +44,17 @@ void GxEPDDisplay::turnOff() { void GxEPDDisplay::clear() { display.fillScreen(GxEPD_WHITE); display.setTextColor(GxEPD_BLACK); + display_crc.reset(); } void GxEPDDisplay::startFrame(Color bkg) { display.fillScreen(GxEPD_WHITE); display.setTextColor(_curr_color = GxEPD_BLACK); + display_crc.reset(); } void GxEPDDisplay::setTextSize(int sz) { + display_crc.update(sz); switch(sz) { case 1: // Small display.setFont(&FreeSans9pt7b); @@ -69,6 +72,7 @@ void GxEPDDisplay::setTextSize(int sz) { } void GxEPDDisplay::setColor(Color c) { + display_crc.update (c); // colours need to be inverted for epaper displays if (c == DARK) { display.setTextColor(_curr_color = GxEPD_WHITE); @@ -78,22 +82,38 @@ void GxEPDDisplay::setColor(Color c) { } void GxEPDDisplay::setCursor(int x, int y) { + display_crc.update(x); + display_crc.update(y); display.setCursor(x*SCALE_X, (y+10)*SCALE_Y); } void GxEPDDisplay::print(const char* str) { + display_crc.update(str, strlen(str)); display.print(str); } void GxEPDDisplay::fillRect(int x, int y, int w, int h) { + display_crc.update(x); + display_crc.update(y); + display_crc.update(w); + display_crc.update(h); display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color); } void GxEPDDisplay::drawRect(int x, int y, int w, int h) { + display_crc.update(x); + display_crc.update(y); + display_crc.update(w); + display_crc.update(h); display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color); } void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { + display_crc.update(x); + display_crc.update(y); + display_crc.update(w); + display_crc.update(h); + display_crc.update(bits, w * h / 8); // Calculate the base position in display coordinates uint16_t startX = x * SCALE_X; uint16_t startY = y * SCALE_Y; @@ -137,5 +157,9 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) { } void GxEPDDisplay::endFrame() { - display.display(true); + uint32_t crc = display_crc.finalize(); + if (crc != last_display_crc_value) { + display.display(true); + last_display_crc_value = crc; + } } diff --git a/src/helpers/ui/GxEPDDisplay.h b/src/helpers/ui/GxEPDDisplay.h index 49746dee..9acf3ac2 100644 --- a/src/helpers/ui/GxEPDDisplay.h +++ b/src/helpers/ui/GxEPDDisplay.h @@ -17,6 +17,7 @@ #define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1 #include // 1.54" b/w +#include #include "DisplayDriver.h" @@ -29,6 +30,8 @@ class GxEPDDisplay : public DisplayDriver { bool _init = false; bool _isOn = false; uint16_t _curr_color; + CRC32 display_crc; + int last_display_crc_value = 0; public: // there is a margin in y... diff --git a/variants/techo/platformio.ini b/variants/techo/platformio.ini index f748fdfe..812baa78 100644 --- a/variants/techo/platformio.ini +++ b/variants/techo/platformio.ini @@ -74,11 +74,12 @@ build_flags = -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 - -D BLE_DEBUG_LOGGING=1 +; -D BLE_DEBUG_LOGGING=1 -D DISPLAY_CLASS=GxEPDDisplay -D OFFLINE_QUEUE_SIZE=256 -D UI_RECENT_LIST_SIZE=9 -D BACKLIGHT_BTN=PIN_BUTTON2 + -D AUTO_OFF_MILLIS=0 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${LilyGo_Techo.build_src_filter} From 1c91298b3a5c1622d6ff1555553eab1d4617d92f Mon Sep 17 00:00:00 2001 From: recrof Date: Wed, 3 Sep 2025 19:38:38 +0200 Subject: [PATCH 26/48] tidy up heltec_t114 variant --- .../heltec_t114}/T114Board.cpp | 16 ++++---- .../heltec_t114}/T114Board.h | 13 ------- variants/{t114 => heltec_t114}/platformio.ini | 38 +++++++++---------- variants/{t114 => heltec_t114}/target.cpp | 0 variants/{t114 => heltec_t114}/target.h | 2 +- variants/{t114 => heltec_t114}/variant.cpp | 0 variants/{t114 => heltec_t114}/variant.h | 0 7 files changed, 27 insertions(+), 42 deletions(-) rename {src/helpers/nrf52 => variants/heltec_t114}/T114Board.cpp (93%) rename {src/helpers/nrf52 => variants/heltec_t114}/T114Board.h (79%) rename variants/{t114 => heltec_t114}/platformio.ini (86%) rename variants/{t114 => heltec_t114}/target.cpp (100%) rename variants/{t114 => heltec_t114}/target.h (97%) rename variants/{t114 => heltec_t114}/variant.cpp (100%) rename variants/{t114 => heltec_t114}/variant.h (100%) diff --git a/src/helpers/nrf52/T114Board.cpp b/variants/heltec_t114/T114Board.cpp similarity index 93% rename from src/helpers/nrf52/T114Board.cpp rename to variants/heltec_t114/T114Board.cpp index 78c21b33..3b40e7cf 100644 --- a/src/helpers/nrf52/T114Board.cpp +++ b/variants/heltec_t114/T114Board.cpp @@ -1,19 +1,17 @@ -#include #include "T114Board.h" -#include +#include #include +#include static BLEDfu bledfu; -static void connect_callback(uint16_t conn_handle) -{ +static void connect_callback(uint16_t conn_handle) { (void)conn_handle; MESH_DEBUG_PRINTLN("BLE client connected"); } -static void disconnect_callback(uint16_t conn_handle, uint8_t reason) -{ +static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { (void)conn_handle; (void)reason; @@ -60,7 +58,7 @@ void T114Board::begin() { // Disable unused analog peripherals // SAADC channels - only keep what's needed for battery monitoring - NRF_SAADC->ENABLE = 0; // Re-enable only when needed for measurements + NRF_SAADC->ENABLE = 0; // Re-enable only when needed for measurements // COMP - Comparator not used NRF_COMP->ENABLE = 0; @@ -78,10 +76,10 @@ void T114Board::begin() { pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); - delay(10); // give sx1262 some time to power up + delay(10); // give sx1262 some time to power up } -bool T114Board::startOTAUpdate(const char* id, char reply[]) { +bool T114Board::startOTAUpdate(const char *id, char reply[]) { // Config the peripheral connection with maximum bandwidth // more SRAM required by SoftDevice // Note: All config***() function must be called before begin() diff --git a/src/helpers/nrf52/T114Board.h b/variants/heltec_t114/T114Board.h similarity index 79% rename from src/helpers/nrf52/T114Board.h rename to variants/heltec_t114/T114Board.h index cf345937..7a7a654b 100644 --- a/src/helpers/nrf52/T114Board.h +++ b/variants/heltec_t114/T114Board.h @@ -3,19 +3,6 @@ #include #include -// LoRa radio module pins for Heltec T114 -#define P_LORA_DIO_1 20 -#define P_LORA_NSS 24 -#define P_LORA_RESET 25 -#define P_LORA_BUSY 17 -#define P_LORA_SCLK 19 -#define P_LORA_MISO 23 -#define P_LORA_MOSI 22 -#define SX126X_POWER_EN 37 - -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 - // built-ins #define PIN_VBAT_READ 4 #define PIN_BAT_CTL 6 diff --git a/variants/t114/platformio.ini b/variants/heltec_t114/platformio.ini similarity index 86% rename from variants/t114/platformio.ini rename to variants/heltec_t114/platformio.ini index e48ee121..2cac2eae 100644 --- a/variants/t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -1,40 +1,40 @@ -[nrf52840_t114] -extends = nrf52_base -platform_packages = framework-arduinoadafruitnrf52 -build_flags = ${nrf52_base.build_flags} - -I src/helpers/nrf52 - -I lib/nrf52/s140_nrf52_6.1.1_API/include - -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 -lib_deps = - ${nrf52_base.lib_deps} - rweather/Crypto @ ^0.4.0 - [Heltec_t114] -extends = nrf52840_t114 +extends = nrf52_base board = heltec_t114 board_build.ldscript = boards/nrf52840_s140_v6.ld -build_flags = ${nrf52840_t114.build_flags} - -I variants/t114 +build_flags = ${nrf52_base.build_flags} + -I lib/nrf52/s140_nrf52_6.1.1_API/include + -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 + -I variants/heltec_t114 -I src/helpers/ui - -DHELTEC_T114 + -D HELTEC_T114 + -D P_LORA_DIO_1=20 + -D P_LORA_NSS=24 + -D P_LORA_RESET=25 + -D P_LORA_BUSY=17 + -D P_LORA_SCLK=19 + -D P_LORA_MISO=23 + -D P_LORA_MOSI=22 -D P_LORA_TX_LED=35 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 + -D SX126X_POWER_EN=37 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 -D ST7789 -D DISPLAY_CLASS=ST7789Display -build_src_filter = ${nrf52840_t114.build_src_filter} +build_src_filter = ${nrf52_base.build_src_filter} + - + - +<../variants/t114> + +<../variants/heltec_t114> + + + + lib_deps = - ${nrf52840_t114.lib_deps} + ${nrf52_base.lib_deps} stevemarple/MicroNMEA @ ^2.0.6 adafruit/Adafruit GFX Library @ ^1.12.1 debug_tool = jlink diff --git a/variants/t114/target.cpp b/variants/heltec_t114/target.cpp similarity index 100% rename from variants/t114/target.cpp rename to variants/heltec_t114/target.cpp diff --git a/variants/t114/target.h b/variants/heltec_t114/target.h similarity index 97% rename from variants/t114/target.h rename to variants/heltec_t114/target.h index 35e86f60..053a7c44 100644 --- a/variants/t114/target.h +++ b/variants/heltec_t114/target.h @@ -3,7 +3,7 @@ #define RADIOLIB_STATIC_ONLY 1 #include #include -#include +#include #include #include #include diff --git a/variants/t114/variant.cpp b/variants/heltec_t114/variant.cpp similarity index 100% rename from variants/t114/variant.cpp rename to variants/heltec_t114/variant.cpp diff --git a/variants/t114/variant.h b/variants/heltec_t114/variant.h similarity index 100% rename from variants/t114/variant.h rename to variants/heltec_t114/variant.h From d610b7be8606039dc1366f15376dea6565c6f2d5 Mon Sep 17 00:00:00 2001 From: recrof Date: Wed, 3 Sep 2025 20:17:55 +0200 Subject: [PATCH 27/48] thinknode m1 refactor --- .../thinknode_m1}/ThinkNodeM1Board.cpp | 16 ++++----- .../thinknode_m1}/ThinkNodeM1Board.h | 13 ------- variants/thinknode_m1/platformio.ini | 35 ++++++++++--------- variants/thinknode_m1/target.h | 2 +- 4 files changed, 27 insertions(+), 39 deletions(-) rename {src/helpers/nrf52 => variants/thinknode_m1}/ThinkNodeM1Board.cpp (92%) rename {src/helpers/nrf52 => variants/thinknode_m1}/ThinkNodeM1Board.h (78%) diff --git a/src/helpers/nrf52/ThinkNodeM1Board.cpp b/variants/thinknode_m1/ThinkNodeM1Board.cpp similarity index 92% rename from src/helpers/nrf52/ThinkNodeM1Board.cpp rename to variants/thinknode_m1/ThinkNodeM1Board.cpp index 63768eea..12dd7362 100644 --- a/src/helpers/nrf52/ThinkNodeM1Board.cpp +++ b/variants/thinknode_m1/ThinkNodeM1Board.cpp @@ -1,10 +1,10 @@ -#include #include "ThinkNodeM1Board.h" +#include #ifdef THINKNODE_M1 -#include #include +#include static BLEDfu bledfu; @@ -26,14 +26,14 @@ void ThinkNodeM1Board::begin() { Wire.begin(); - #ifdef P_LORA_TX_LED - pinMode(P_LORA_TX_LED, OUTPUT); - digitalWrite(P_LORA_TX_LED, LOW); - #endif +#ifdef P_LORA_TX_LED + pinMode(P_LORA_TX_LED, OUTPUT); + digitalWrite(P_LORA_TX_LED, LOW); +#endif pinMode(SX126X_POWER_EN, OUTPUT); digitalWrite(SX126X_POWER_EN, HIGH); - delay(10); // give sx1262 some time to power up + delay(10); // give sx1262 some time to power up } uint16_t ThinkNodeM1Board::getBattMilliVolts() { @@ -50,7 +50,7 @@ uint16_t ThinkNodeM1Board::getBattMilliVolts() { return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB); } -bool ThinkNodeM1Board::startOTAUpdate(const char* id, char reply[]) { +bool ThinkNodeM1Board::startOTAUpdate(const char *id, char reply[]) { // Config the peripheral connection with maximum bandwidth // more SRAM required by SoftDevice // Note: All config***() function must be called before begin() diff --git a/src/helpers/nrf52/ThinkNodeM1Board.h b/variants/thinknode_m1/ThinkNodeM1Board.h similarity index 78% rename from src/helpers/nrf52/ThinkNodeM1Board.h rename to variants/thinknode_m1/ThinkNodeM1Board.h index fc752223..cffa0aaa 100644 --- a/src/helpers/nrf52/ThinkNodeM1Board.h +++ b/variants/thinknode_m1/ThinkNodeM1Board.h @@ -3,19 +3,6 @@ #include #include -// LoRa radio module pins for Elecrow ThinkNode M1 -#define P_LORA_DIO_1 20 -#define P_LORA_NSS 24 -#define P_LORA_RESET 25 -#define P_LORA_BUSY 17 -#define P_LORA_SCLK 19 -#define P_LORA_MISO 23 -#define P_LORA_MOSI 22 -#define SX126X_POWER_EN 37 - -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 - // built-ins #define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 diff --git a/variants/thinknode_m1/platformio.ini b/variants/thinknode_m1/platformio.ini index 590f2100..f987ac83 100644 --- a/variants/thinknode_m1/platformio.ini +++ b/variants/thinknode_m1/platformio.ini @@ -1,33 +1,35 @@ -[nrf52840_thinknode_m1] +[ThinkNode_M1] extends = nrf52_base -platform_packages = framework-arduinoadafruitnrf52 +board = thinknode_m1 +board_build.ldscript = boards/nrf52840_s140_v6.ld build_flags = ${nrf52_base.build_flags} -I src/helpers/nrf52 -I lib/nrf52/s140_nrf52_6.1.1_API/include -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 -lib_deps = - ${nrf52_base.lib_deps} - rweather/Crypto @ ^0.4.0 - -[ThinkNode_M1] -extends = nrf52840_thinknode_m1 -board = thinknode_m1 -board_build.ldscript = boards/nrf52840_s140_v6.ld -build_flags = ${nrf52840_thinknode_m1.build_flags} -I variants/thinknode_m1 -D THINKNODE_M1=1 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper - -D LORA_TX_POWER=22 - -D P_LORA_TX_LED=13 + -D P_LORA_DIO_1=20 + -D P_LORA_NSS=24 + -D P_LORA_RESET=25 + -D P_LORA_BUSY=17 + -D P_LORA_SCLK=19 + -D P_LORA_MISO=23 + -D P_LORA_MOSI=22 + -D SX126X_POWER_EN=37 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 -build_src_filter = ${nrf52840_thinknode_m1.build_src_filter} + -D LORA_TX_POWER=22 + -D P_LORA_TX_LED=13 +build_src_filter = ${nrf52_base.build_src_filter} + - + + + +<../variants/thinknode_m1> lib_deps = - ${nrf52840_thinknode_m1.lib_deps} + ${nrf52_base.lib_deps} stevemarple/MicroNMEA @ ^2.0.6 debug_tool = jlink upload_protocol = nrfutil @@ -81,7 +83,6 @@ build_flags = ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${ThinkNode_M1.build_src_filter} - + + + + diff --git a/variants/thinknode_m1/target.h b/variants/thinknode_m1/target.h index eac221c3..1e4e1381 100644 --- a/variants/thinknode_m1/target.h +++ b/variants/thinknode_m1/target.h @@ -3,7 +3,7 @@ #define RADIOLIB_STATIC_ONLY 1 #include #include -#include +#include #include #include #include From cbf3a03d2e34db67b77e2bd3830d5af81d7a313f Mon Sep 17 00:00:00 2001 From: recrof Date: Wed, 3 Sep 2025 20:52:58 +0200 Subject: [PATCH 28/48] rpi picow cleanup --- .../rpi_picow}/PicoWBoard.cpp | 0 .../rpi_picow}/PicoWBoard.h | 13 ---- variants/{picow => rpi_picow}/platformio.ini | 65 +++++++++++-------- variants/{picow => rpi_picow}/target.cpp | 0 variants/{picow => rpi_picow}/target.h | 2 +- 5 files changed, 38 insertions(+), 42 deletions(-) rename {src/helpers/rp2040 => variants/rpi_picow}/PicoWBoard.cpp (100%) rename {src/helpers/rp2040 => variants/rpi_picow}/PicoWBoard.h (75%) rename variants/{picow => rpi_picow}/platformio.ini (64%) rename variants/{picow => rpi_picow}/target.cpp (100%) rename variants/{picow => rpi_picow}/target.h (93%) diff --git a/src/helpers/rp2040/PicoWBoard.cpp b/variants/rpi_picow/PicoWBoard.cpp similarity index 100% rename from src/helpers/rp2040/PicoWBoard.cpp rename to variants/rpi_picow/PicoWBoard.cpp diff --git a/src/helpers/rp2040/PicoWBoard.h b/variants/rpi_picow/PicoWBoard.h similarity index 75% rename from src/helpers/rp2040/PicoWBoard.h rename to variants/rpi_picow/PicoWBoard.h index cdc9c9f7..708e9655 100644 --- a/src/helpers/rp2040/PicoWBoard.h +++ b/variants/rpi_picow/PicoWBoard.h @@ -3,19 +3,6 @@ #include #include -// LoRa radio module pins for PicoW -#define P_LORA_DIO_1 20 -#define P_LORA_NSS 3 -#define P_LORA_RESET 15 -#define P_LORA_BUSY 2 -#define P_LORA_SCLK 10 -#define P_LORA_MISO 12 -#define P_LORA_MOSI 11 -//#define SX126X_POWER_EN ??? // Not Sure - -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 - // built-ins #define PIN_VBAT_READ 26 #define ADC_MULTIPLIER (3.1 * 3.3 * 1000) // MT Uses 3.1 diff --git a/variants/picow/platformio.ini b/variants/rpi_picow/platformio.ini similarity index 64% rename from variants/picow/platformio.ini rename to variants/rpi_picow/platformio.ini index 7b75c224..adec5d77 100644 --- a/variants/picow/platformio.ini +++ b/variants/rpi_picow/platformio.ini @@ -1,26 +1,35 @@ -[picow] +[rpi_picow] extends = rp2040_base platform = https://github.com/maxgerhardt/platform-raspberrypi.git board = rpipicow board_build.core = earlephilhower board_build.filesystem_size = 0.5m build_flags = ${rp2040_base.build_flags} - -I variants/picow + -I variants/rpi_picow ; -D PICOW ; -D HW_SPI1_DEVICE + -D P_LORA_DIO_1=20 + -D P_LORA_NSS=3 + -D P_LORA_RESET=15 + -D P_LORA_BUSY=2 + -D P_LORA_SCLK=10 + -D P_LORA_MISO=12 + -D P_LORA_MOSI=11 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=130 + -D SX126X_RX_BOOSTED_GAIN=1 + -D LORA_TX_POWER=22 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper - -D LORA_TX_POWER=22 - -D SX126X_RX_BOOSTED_GAIN=1 build_src_filter = ${rp2040_base.build_src_filter} - + - +<../variants/picow> + + + +<../variants/rpi_picow> lib_deps = ${rp2040_base.lib_deps} [env:PicoW_Repeater] -extends = picow -build_flags = ${picow.build_flags} +extends = rpi_picow +build_flags = ${rpi_picow.build_flags} -D ADVERT_NAME='"PicoW Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -28,12 +37,12 @@ build_flags = ${picow.build_flags} -D MAX_NEIGHBOURS=8 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${picow.build_src_filter} +build_src_filter = ${rpi_picow.build_src_filter} +<../examples/simple_repeater> [env:PicoW_room_server] -extends = picow -build_flags = ${picow.build_flags} +extends = rpi_picow +build_flags = ${rpi_picow.build_flags} -D ADVERT_NAME='"Test Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -41,38 +50,38 @@ build_flags = ${picow.build_flags} -D ROOM_PASSWORD='"hello"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${picow.build_src_filter} +build_src_filter = ${rpi_picow.build_src_filter} +<../examples/simple_room_server> [env:PicoW_companion_radio_usb] -extends = picow -build_flags = ${picow.build_flags} +extends = rpi_picow +build_flags = ${rpi_picow.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 -build_src_filter = ${picow.build_src_filter} +build_src_filter = ${rpi_picow.build_src_filter} +<../examples/companion_radio/*.cpp> -lib_deps = ${picow.lib_deps} +lib_deps = ${rpi_picow.lib_deps} densaugeo/base64 @ ~1.4.0 ; [env:PicoW_companion_radio_ble] -; extends = picow -; build_flags = ${picow.build_flags} +; extends = rpi_picow +; build_flags = ${rpi_picow.build_flags} ; -D MAX_CONTACTS=100 ; -D MAX_GROUP_CHANNELS=8 ; -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 ; ; -D MESH_PACKET_LOGGING=1 ; ; -D MESH_DEBUG=1 -; build_src_filter = ${picow.build_src_filter} +; build_src_filter = ${rpi_picow.build_src_filter} ; +<../examples/companion_radio/*.cpp> -; lib_deps = ${picow.lib_deps} +; lib_deps = ${rpi_picow.lib_deps} ; densaugeo/base64 @ ~1.4.0 ; [env:PicoW_companion_radio_wifi] -; extends = picow -; build_flags = ${picow.build_flags} +; extends = rpi_picow +; build_flags = ${rpi_picow.build_flags} ; -D MAX_CONTACTS=100 ; -D MAX_GROUP_CHANNELS=8 ; -D WIFI_DEBUG_LOGGING=1 @@ -80,19 +89,19 @@ lib_deps = ${picow.lib_deps} ; -D WIFI_PWD='"mypwd"' ; ; -D MESH_PACKET_LOGGING=1 ; ; -D MESH_DEBUG=1 -; build_src_filter = ${picow.build_src_filter} +; build_src_filter = ${rpi_picow.build_src_filter} ; +<../examples/companion_radio/*.cpp> -; lib_deps = ${picow.lib_deps} +; lib_deps = ${rpi_picow.lib_deps} ; densaugeo/base64 @ ~1.4.0 [env:PicoW_terminal_chat] -extends = picow -build_flags = ${picow.build_flags} +extends = rpi_picow +build_flags = ${rpi_picow.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${picow.build_src_filter} +build_src_filter = ${rpi_picow.build_src_filter} +<../examples/simple_secure_chat/main.cpp> -lib_deps = ${picow.lib_deps} +lib_deps = ${rpi_picow.lib_deps} densaugeo/base64 @ ~1.4.0 diff --git a/variants/picow/target.cpp b/variants/rpi_picow/target.cpp similarity index 100% rename from variants/picow/target.cpp rename to variants/rpi_picow/target.cpp diff --git a/variants/picow/target.h b/variants/rpi_picow/target.h similarity index 93% rename from variants/picow/target.h rename to variants/rpi_picow/target.h index 7b1e7437..17dbb35f 100644 --- a/variants/picow/target.h +++ b/variants/rpi_picow/target.h @@ -3,7 +3,7 @@ #define RADIOLIB_STATIC_ONLY 1 #include #include -#include +#include #include #include #include From 72b267092f3bdad3dc4d8818f4496b5241689e09 Mon Sep 17 00:00:00 2001 From: recrof Date: Wed, 3 Sep 2025 21:28:46 +0200 Subject: [PATCH 29/48] xiao rp2040 cleanup --- .../xiao_rp2040}/XiaoRP2040Board.cpp | 0 .../xiao_rp2040}/XiaoRP2040Board.h | 15 --------------- variants/xiao_rp2040/platformio.ini | 17 +++++++++++------ variants/xiao_rp2040/target.h | 2 +- 4 files changed, 12 insertions(+), 22 deletions(-) rename {src/helpers/rp2040 => variants/xiao_rp2040}/XiaoRP2040Board.cpp (100%) rename {src/helpers/rp2040 => variants/xiao_rp2040}/XiaoRP2040Board.h (79%) diff --git a/src/helpers/rp2040/XiaoRP2040Board.cpp b/variants/xiao_rp2040/XiaoRP2040Board.cpp similarity index 100% rename from src/helpers/rp2040/XiaoRP2040Board.cpp rename to variants/xiao_rp2040/XiaoRP2040Board.cpp diff --git a/src/helpers/rp2040/XiaoRP2040Board.h b/variants/xiao_rp2040/XiaoRP2040Board.h similarity index 79% rename from src/helpers/rp2040/XiaoRP2040Board.h rename to variants/xiao_rp2040/XiaoRP2040Board.h index c9353906..d2951c75 100644 --- a/src/helpers/rp2040/XiaoRP2040Board.h +++ b/variants/xiao_rp2040/XiaoRP2040Board.h @@ -3,21 +3,6 @@ #include #include -// LoRa radio module pins for the Xiao RP2040 -// https://wiki.seeedstudio.com/XIAO-RP2040/ - -#define P_LORA_DIO_1 27 // D1 -#define P_LORA_NSS 6 // D4 -#define P_LORA_RESET 28 // D2 -#define P_LORA_BUSY 29 // D3 -#define P_LORA_TX_LED 17 - -#define SX126X_RXEN 7 // D5 -#define SX126X_TXEN -1 - -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 - /* * This board has no built-in way to read battery voltage. * Nevertheless it's very easy to make it work, you only require two 1% resistors. diff --git a/variants/xiao_rp2040/platformio.ini b/variants/xiao_rp2040/platformio.ini index 619350ec..48ae3c26 100644 --- a/variants/xiao_rp2040/platformio.ini +++ b/variants/xiao_rp2040/platformio.ini @@ -1,27 +1,32 @@ [Xiao_rp2040] extends = rp2040_base - board = seeed_xiao_rp2040 board_build.filesystem_size = 0.5m - build_flags = ${rp2040_base.build_flags} -I variants/xiao_rp2040 -D SX126X_CURRENT_LIMIT=140 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper - -D LORA_TX_POWER=22 + -D P_LORA_DIO_1=27 ; D1 + -D P_LORA_NSS=6 ; D4 + -D P_LORA_RESET=28 ; D2 + -D P_LORA_BUSY=29 ; D3 + -D P_LORA_TX_LED=17 + -D SX126X_RXEN=7 ; D5 + -D SX126X_TXEN=1 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_RX_BOOSTED_GAIN=1 + -D LORA_TX_POWER=22 ; Debug options ; -D DEBUG_RP2040_WIRE=1 ; -D DEBUG_RP2040_SPI=1 ; -D DEBUG_RP2040_CORE=1 ; -D RADIOLIB_DEBUG_SPI=1 ; -D DEBUG_RP2040_PORT=Serial - build_src_filter = ${rp2040_base.build_src_filter} - + + + +<../variants/xiao_rp2040> - lib_deps = ${rp2040_base.lib_deps} [env:Xiao_rp2040_Repeater] diff --git a/variants/xiao_rp2040/target.h b/variants/xiao_rp2040/target.h index 34861db3..33b3766c 100644 --- a/variants/xiao_rp2040/target.h +++ b/variants/xiao_rp2040/target.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include extern XiaoRP2040Board board; extern WRAPPER_CLASS radio_driver; From c2fc70047a0944b30df0a98304f486b2701c348d Mon Sep 17 00:00:00 2001 From: recrof Date: Wed, 3 Sep 2025 21:37:07 +0200 Subject: [PATCH 30/48] waveshare rp2040 lora cleanup --- .../waveshare_rp2040_lora}/WaveshareBoard.cpp | 0 .../waveshare_rp2040_lora}/WaveshareBoard.h | 12 ------------ variants/waveshare_rp2040_lora/platformio.ini | 18 ++++++++++++------ variants/waveshare_rp2040_lora/target.h | 2 +- 4 files changed, 13 insertions(+), 19 deletions(-) rename {src/helpers/rp2040 => variants/waveshare_rp2040_lora}/WaveshareBoard.cpp (100%) rename {src/helpers/rp2040 => variants/waveshare_rp2040_lora}/WaveshareBoard.h (81%) diff --git a/src/helpers/rp2040/WaveshareBoard.cpp b/variants/waveshare_rp2040_lora/WaveshareBoard.cpp similarity index 100% rename from src/helpers/rp2040/WaveshareBoard.cpp rename to variants/waveshare_rp2040_lora/WaveshareBoard.cpp diff --git a/src/helpers/rp2040/WaveshareBoard.h b/variants/waveshare_rp2040_lora/WaveshareBoard.h similarity index 81% rename from src/helpers/rp2040/WaveshareBoard.h rename to variants/waveshare_rp2040_lora/WaveshareBoard.h index c2b5aff5..694b8bd1 100644 --- a/src/helpers/rp2040/WaveshareBoard.h +++ b/variants/waveshare_rp2040_lora/WaveshareBoard.h @@ -6,18 +6,6 @@ // LoRa radio module pins for Waveshare RP2040-LoRa-HF/LF // https://files.waveshare.com/wiki/RP2040-LoRa/Rp2040-lora-sch.pdf -#define P_LORA_DIO_1 16 -#define P_LORA_NSS 13 // CS -#define P_LORA_RESET 23 -#define P_LORA_BUSY 18 -#define P_LORA_SCLK 14 -#define P_LORA_MISO 24 -#define P_LORA_MOSI 15 -#define P_LORA_TX_LED 25 - -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 0 - /* * This board has no built-in way to read battery voltage. * Nevertheless it's very easy to make it work, you only require two 1% resistors. diff --git a/variants/waveshare_rp2040_lora/platformio.ini b/variants/waveshare_rp2040_lora/platformio.ini index 933c7661..e3c812b6 100644 --- a/variants/waveshare_rp2040_lora/platformio.ini +++ b/variants/waveshare_rp2040_lora/platformio.ini @@ -3,28 +3,34 @@ [waveshare_rp2040_lora] extends = rp2040_base - board = pico board_build.filesystem_size = 0.5m - build_flags = ${rp2040_base.build_flags} -I variants/waveshare_rp2040_lora -D SX126X_CURRENT_LIMIT=140 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper - -D LORA_TX_POWER=22 + -D P_LORA_DIO_1=16 + -D P_LORA_NSS=13 ; CS + -D P_LORA_RESET=23 + -D P_LORA_BUSY=18 + -D P_LORA_SCLK=14 + -D P_LORA_MISO=24 + -D P_LORA_MOSI=15 + -D P_LORA_TX_LED=25 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=0 -D SX126X_RX_BOOSTED_GAIN=1 + -D LORA_TX_POWER=22 ; Debug options ; -D DEBUG_RP2040_WIRE=1 ; -D DEBUG_RP2040_SPI=1 ; -D DEBUG_RP2040_CORE=1 ; -D RADIOLIB_DEBUG_SPI=1 ; -D DEBUG_RP2040_PORT=Serial - build_src_filter = ${rp2040_base.build_src_filter} - + + + +<../variants/waveshare_rp2040_lora> - lib_deps = ${rp2040_base.lib_deps} [env:waveshare_rp2040_lora_Repeater] diff --git a/variants/waveshare_rp2040_lora/target.h b/variants/waveshare_rp2040_lora/target.h index 149b9469..aed55893 100644 --- a/variants/waveshare_rp2040_lora/target.h +++ b/variants/waveshare_rp2040_lora/target.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include extern WaveshareBoard board; extern WRAPPER_CLASS radio_driver; From f4df94a20e412b75596aac6ff7a935c5a4851caf Mon Sep 17 00:00:00 2001 From: Quency-D Date: Thu, 4 Sep 2025 14:04:00 +0800 Subject: [PATCH 31/48] Delete the sensor part and adapt to the latest crc display. --- src/helpers/ui/GxEPDDisplay.cpp | 4 ++-- variants/mesh_pocket/platformio.ini | 3 +++ variants/mesh_pocket/target.cpp | 30 +---------------------------- variants/mesh_pocket/target.h | 14 +------------- 4 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/helpers/ui/GxEPDDisplay.cpp b/src/helpers/ui/GxEPDDisplay.cpp index 874705ae..34e31e30 100644 --- a/src/helpers/ui/GxEPDDisplay.cpp +++ b/src/helpers/ui/GxEPDDisplay.cpp @@ -94,7 +94,7 @@ void GxEPDDisplay::fillRect(int x, int y, int w, int h) { display_crc.update(y); display_crc.update(w); display_crc.update(h); - display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color); + display.fillRect(x*scale_x, y*scale_y, w*scale_x, h*scale_y, _curr_color); } void GxEPDDisplay::drawRect(int x, int y, int w, int h) { @@ -102,7 +102,7 @@ void GxEPDDisplay::drawRect(int x, int y, int w, int h) { display_crc.update(y); display_crc.update(w); display_crc.update(h); - display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color); + display.drawRect(x*scale_x, y*scale_y, w*scale_x, h*scale_y, _curr_color); } void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { diff --git a/variants/mesh_pocket/platformio.ini b/variants/mesh_pocket/platformio.ini index e492d515..c9510ae3 100644 --- a/variants/mesh_pocket/platformio.ini +++ b/variants/mesh_pocket/platformio.ini @@ -30,6 +30,7 @@ lib_deps = rweather/Crypto @ ^0.4.0 stevemarple/MicroNMEA @ ^2.0.6 zinggjm/GxEPD2 @ 1.6.2 + bakercp/CRC32 @ ^2.0.0 debug_tool = jlink upload_protocol = nrfutil @@ -72,6 +73,7 @@ build_flags = -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 + -D AUTO_OFF_MILLIS=0 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -91,6 +93,7 @@ build_flags = -I examples/companion_radio/ui-new -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 + -D AUTO_OFF_MILLIS=0 ; -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 diff --git a/variants/mesh_pocket/target.cpp b/variants/mesh_pocket/target.cpp index 0821e0e8..a7f6c7fb 100644 --- a/variants/mesh_pocket/target.cpp +++ b/variants/mesh_pocket/target.cpp @@ -9,7 +9,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU WRAPPER_CLASS radio_driver(radio, board); -MeshPocketSensorManager sensors = MeshPocketSensorManager(); +SensorManager sensors = SensorManager(); VolatileRTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); @@ -42,31 +42,3 @@ mesh::LocalIdentity radio_new_identity() { RadioNoiseListener rng(radio); return mesh::LocalIdentity(&rng); // create new random identity } - -bool MeshPocketSensorManager::begin() { - return true; -} - -void MeshPocketSensorManager::loop() { - -} - -bool MeshPocketSensorManager::querySensors(uint8_t requester_permission, CayenneLPP& telemetry) { - return true; -} - -int MeshPocketSensorManager::getNumSettings() const { - return 0; -} - -const char* MeshPocketSensorManager::getSettingName(int i) const { - return NULL; -} - -const char* MeshPocketSensorManager::getSettingValue(int i) const { - return NULL; -} - -bool MeshPocketSensorManager::setSettingValue(const char* name, const char* value) { - return false; -} \ No newline at end of file diff --git a/variants/mesh_pocket/target.h b/variants/mesh_pocket/target.h index a44c8c52..2aa95669 100644 --- a/variants/mesh_pocket/target.h +++ b/variants/mesh_pocket/target.h @@ -29,17 +29,5 @@ void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); void radio_set_tx_power(uint8_t dbm); mesh::LocalIdentity radio_new_identity(); -class MeshPocketSensorManager : public SensorManager { -public: - MeshPocketSensorManager() {}; - bool begin() override; - bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry); - void loop(); - int getNumSettings() const override; - const char* getSettingName(int i) const override; - const char* getSettingValue(int i) const override; - bool setSettingValue(const char* name, const char* value) override; -}; - -extern MeshPocketSensorManager sensors; +extern SensorManager sensors; From 8fa31e00aa0412339adac35f47977a5d40594ea6 Mon Sep 17 00:00:00 2001 From: Quency-D Date: Thu, 4 Sep 2025 15:39:08 +0800 Subject: [PATCH 32/48] -D DISABLE_DIAGNOSTIC_OUTPUT this one will make GxEPD less verbose ;) --- variants/mesh_pocket/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/mesh_pocket/platformio.ini b/variants/mesh_pocket/platformio.ini index c9510ae3..3fa4c7b8 100644 --- a/variants/mesh_pocket/platformio.ini +++ b/variants/mesh_pocket/platformio.ini @@ -20,6 +20,7 @@ build_flags = ${nrf52_base.build_flags} -D EINK_X_OFFSET=0 -D EINK_Y_OFFSET=10 -D DISPLAY_CLASS=GxEPDDisplay + -D DISABLE_DIAGNOSTIC_OUTPUT build_src_filter = ${nrf52_base.build_src_filter} + +<../variants/mesh_pocket> From d56b725256c0bb4d4093f77e90f37783907bd385 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Thu, 4 Sep 2025 20:07:37 +1200 Subject: [PATCH 33/48] add missing crc32 libdep after gxepd display driver changes --- variants/thinknode_m1/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/thinknode_m1/platformio.ini b/variants/thinknode_m1/platformio.ini index 590f2100..19bf653f 100644 --- a/variants/thinknode_m1/platformio.ini +++ b/variants/thinknode_m1/platformio.ini @@ -92,4 +92,5 @@ lib_deps = ${ThinkNode_M1.lib_deps} densaugeo/base64 @ ~1.4.0 zinggjm/GxEPD2 @ 1.6.2 + bakercp/CRC32 @ ^2.0.0 end2endzone/NonBlockingRTTTL@^1.3.0 From 1f20722f51e7ed7be7e39dd59b20e3d7a2a2365d Mon Sep 17 00:00:00 2001 From: taco Date: Thu, 4 Sep 2025 19:59:33 +1000 Subject: [PATCH 34/48] fix: wio tracker L1: tidy platformio.ini --- variants/wio-tracker-l1/platformio.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/variants/wio-tracker-l1/platformio.ini b/variants/wio-tracker-l1/platformio.ini index ddf7cf47..be0086c4 100644 --- a/variants/wio-tracker-l1/platformio.ini +++ b/variants/wio-tracker-l1/platformio.ini @@ -60,6 +60,8 @@ build_flags = ${WioTrackerL1.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D DISPLAY_CLASS=SH1106Display + -D OFFLINE_QUEUE_SIZE=256 + -D PIN_BUZZER=12 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 build_src_filter = ${WioTrackerL1.build_src_filter} @@ -83,9 +85,9 @@ build_flags = ${WioTrackerL1.build_flags} -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 -D DISPLAY_CLASS=SH1106Display -; -D MESH_PACKET_LOGGING=1 - -D MESH_DEBUG=1 -D PIN_BUZZER=12 + ; -D MESH_PACKET_LOGGING=1 + ; -D MESH_DEBUG=1 build_src_filter = ${WioTrackerL1.build_src_filter} + + From d8f80f259a962d4437f9bd69840955a02b0c064e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Thu, 4 Sep 2025 13:25:10 +0100 Subject: [PATCH 35/48] Refactor display driver inclusion for Heltec T114 to support configurations without a display --- variants/heltec_t114/NullDisplayDriver.h | 24 ++++++ variants/heltec_t114/platformio.ini | 105 +++++++++++++++++++++-- variants/heltec_t114/target.h | 9 +- 3 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 variants/heltec_t114/NullDisplayDriver.h diff --git a/variants/heltec_t114/NullDisplayDriver.h b/variants/heltec_t114/NullDisplayDriver.h new file mode 100644 index 00000000..2a9670bd --- /dev/null +++ b/variants/heltec_t114/NullDisplayDriver.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +class NullDisplayDriver : public DisplayDriver { +public: + NullDisplayDriver() : DisplayDriver(128, 64) { } + bool begin() { return false; } // not present + + bool isOn() override { return false; } + void turnOn() override { } + void turnOff() override { } + void clear() override { } + void startFrame(Color bkg = DARK) override { } + void setTextSize(int sz) override { } + void setColor(Color c) override { } + void setCursor(int x, int y) override { } + void print(const char* str) override { } + void fillRect(int x, int y, int w, int h) override { } + void drawRect(int x, int y, int w, int h) override { } + void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { } + uint16_t getTextWidth(const char* str) override { return 0; } + void endFrame() { } +}; diff --git a/variants/heltec_t114/platformio.ini b/variants/heltec_t114/platformio.ini index 2cac2eae..e17ac10c 100644 --- a/variants/heltec_t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -1,3 +1,6 @@ +; +; Heltec T114 without display +; [Heltec_t114] extends = nrf52_base board = heltec_t114 @@ -24,15 +27,11 @@ build_flags = ${nrf52_base.build_flags} -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 + -D DISPLAY_CLASS=NullDisplayDriver -D ST7789 - -D DISPLAY_CLASS=ST7789Display build_src_filter = ${nrf52_base.build_src_filter} + +<../variants/heltec_t114> - + - + - + - + lib_deps = ${nrf52_base.lib_deps} stevemarple/MicroNMEA @ ^2.0.6 @@ -40,7 +39,7 @@ lib_deps = debug_tool = jlink upload_protocol = nrfutil -[env:Heltec_t114_repeater] +[env:Heltec_t114_without_display_repeater] extends = Heltec_t114 build_src_filter = ${Heltec_t114.build_src_filter} +<../examples/simple_repeater> @@ -55,7 +54,7 @@ build_flags = ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -[env:Heltec_t114_room_server] +[env:Heltec_t114_without_display_room_server] extends = Heltec_t114 build_src_filter = ${Heltec_t114.build_src_filter} +<../examples/simple_room_server> @@ -69,7 +68,7 @@ build_flags = ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -[env:Heltec_t114_companion_radio_ble] +[env:Heltec_t114_without_display_companion_radio_ble] extends = Heltec_t114 build_flags = ${Heltec_t114.build_flags} @@ -89,7 +88,7 @@ lib_deps = ${Heltec_t114.lib_deps} densaugeo/base64 @ ~1.4.0 -[env:Heltec_t114_companion_radio_usb] +[env:Heltec_t114_without_display_companion_radio_usb] extends = Heltec_t114 build_flags = ${Heltec_t114.build_flags} @@ -106,4 +105,92 @@ build_src_filter = ${Heltec_t114.build_src_filter} +<../examples/companion_radio/ui-new/*.cpp> lib_deps = ${Heltec_t114.lib_deps} + densaugeo/base64 @ ~1.4.0 + +; +; Heltec T114 with ST7789 display +; +[Heltec_t114_with_display] +extends = Heltec_t114 +board = heltec_t114 +board_build.ldscript = boards/nrf52840_s140_v6.ld +build_flags = ${Heltec_t114.build_flags} + -D HELTEC_T114_WITH_DISPLAY + -D DISPLAY_CLASS=ST7789Display +build_src_filter = ${Heltec_t114.build_src_filter} + + + + + + + + +lib_deps = + ${Heltec_t114.lib_deps} +debug_tool = jlink +upload_protocol = nrfutil + +[env:Heltec_t114_repeater] +extends = Heltec_t114_with_display +build_src_filter = ${Heltec_t114_with_display.build_src_filter} + +<../examples/simple_repeater> + +build_flags = + ${Heltec_t114_with_display.build_flags} + -D ADVERT_NAME='"Heltec_T114 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=8 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 + +[env:Heltec_t114_room_server] +extends = Heltec_t114_with_display +build_src_filter = ${Heltec_t114_with_display.build_src_filter} + +<../examples/simple_room_server> +build_flags = + ${Heltec_t114_with_display.build_flags} + -D ADVERT_NAME='"Heltec_T114 Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 + +[env:Heltec_t114_companion_radio_ble] +extends = Heltec_t114_with_display +build_flags = + ${Heltec_t114_with_display.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 + -D BLE_PIN_CODE=123456 +; -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${Heltec_t114_with_display.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Heltec_t114_with_display.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:Heltec_t114_companion_radio_usb] +extends = Heltec_t114_with_display +build_flags = + ${Heltec_t114_with_display.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 +; -D BLE_PIN_CODE=123456 +; -D BLE_DEBUG_LOGGING=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${Heltec_t114_with_display.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${Heltec_t114_with_display.lib_deps} densaugeo/base64 @ ~1.4.0 \ No newline at end of file diff --git a/variants/heltec_t114/target.h b/variants/heltec_t114/target.h index 053a7c44..3283f009 100644 --- a/variants/heltec_t114/target.h +++ b/variants/heltec_t114/target.h @@ -8,9 +8,14 @@ #include #include #include + #ifdef DISPLAY_CLASS - #include - #include +#include +#ifdef HELTEC_T114_WITH_DISPLAY +#include +#else +#include "NullDisplayDriver.h" +#endif #endif class T114SensorManager : public SensorManager { From 5b2c1715f49891c125f15d82c143d65c03d52e21 Mon Sep 17 00:00:00 2001 From: recrof Date: Thu, 4 Sep 2025 21:45:42 +0200 Subject: [PATCH 36/48] lilygo t-echo cleanup, add AUTO_SHUTDOWN_MILLIVOLTS --- examples/companion_radio/ui-new/UITask.cpp | 10 +- .../lilygo_techo}/TechoBoard.cpp | 0 .../lilygo_techo}/TechoBoard.h | 13 --- .../{techo => lilygo_techo}/platformio.ini | 93 ++++++++++++------- variants/{techo => lilygo_techo}/target.cpp | 0 variants/{techo => lilygo_techo}/target.h | 2 +- variants/{techo => lilygo_techo}/variant.cpp | 0 variants/{techo => lilygo_techo}/variant.h | 0 8 files changed, 63 insertions(+), 55 deletions(-) rename {src/helpers/nrf52 => variants/lilygo_techo}/TechoBoard.cpp (100%) rename {src/helpers/nrf52 => variants/lilygo_techo}/TechoBoard.h (78%) rename variants/{techo => lilygo_techo}/platformio.ini (59%) rename variants/{techo => lilygo_techo}/target.cpp (100%) rename variants/{techo => lilygo_techo}/target.h (95%) rename variants/{techo => lilygo_techo}/variant.cpp (100%) rename variants/{techo => lilygo_techo}/variant.h (100%) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 34ba60e5..0f540878 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -202,8 +202,8 @@ public: display.print(tmp); } else if (_page == HomePage::BLUETOOTH) { display.setColor(DisplayDriver::GREEN); - display.drawXbm((display.width() - 32) / 2, 18, - _task->isSerialEnabled() ? bluetooth_on : bluetooth_off, + display.drawXbm((display.width() - 32) / 2, 18, + _task->isSerialEnabled() ? bluetooth_on : bluetooth_off, 32, 32); display.setTextSize(1); display.drawTextCentered(display.width() / 2, 64 - 11, "toggle: " PRESS_LABEL); @@ -455,8 +455,8 @@ void UITask::setCurrScreen(UIScreen* c) { _next_refresh = 100; } -/* - hardware-agnostic pre-shutdown activity should be done here +/* + hardware-agnostic pre-shutdown activity should be done here */ void UITask::shutdown(bool restart){ @@ -584,7 +584,7 @@ void UITask::loop() { // show low battery shutdown alert // we should only do this for eink displays, which will persist after power loss - #ifdef THINKNODE_M1 + #if defined(THINKNODE_M1) || defined(LILYGO_TECHO) if (_display != NULL) { _display->startFrame(); _display->setTextSize(2); diff --git a/src/helpers/nrf52/TechoBoard.cpp b/variants/lilygo_techo/TechoBoard.cpp similarity index 100% rename from src/helpers/nrf52/TechoBoard.cpp rename to variants/lilygo_techo/TechoBoard.cpp diff --git a/src/helpers/nrf52/TechoBoard.h b/variants/lilygo_techo/TechoBoard.h similarity index 78% rename from src/helpers/nrf52/TechoBoard.h rename to variants/lilygo_techo/TechoBoard.h index 2c05c4ed..4792153a 100644 --- a/src/helpers/nrf52/TechoBoard.h +++ b/variants/lilygo_techo/TechoBoard.h @@ -3,19 +3,6 @@ #include #include -// LoRa radio module pins for LilyGo T-Echo -#define P_LORA_DIO_1 20 -#define P_LORA_NSS 24 -#define P_LORA_RESET 25 -#define P_LORA_BUSY 17 -#define P_LORA_SCLK 19 -#define P_LORA_MISO 23 -#define P_LORA_MOSI 22 -#define SX126X_POWER_EN 37 - -#define SX126X_DIO2_AS_RF_SWITCH true -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 - // built-ins #define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 diff --git a/variants/techo/platformio.ini b/variants/lilygo_techo/platformio.ini similarity index 59% rename from variants/techo/platformio.ini rename to variants/lilygo_techo/platformio.ini index 812baa78..8a090a4d 100644 --- a/variants/techo/platformio.ini +++ b/variants/lilygo_techo/platformio.ini @@ -1,24 +1,26 @@ -[nrf52840_techo] +[LilyGo_T-Echo] extends = nrf52_base -platform_packages = framework-arduinoadafruitnrf52 +board = t-echo +board_build.ldscript = boards/nrf52840_s140_v6.ld build_flags = ${nrf52_base.build_flags} + -I variants/lilygo_techo -I src/helpers/nrf52 -I lib/nrf52/s140_nrf52_6.1.1_API/include -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 -lib_deps = - ${nrf52_base.lib_deps} - rweather/Crypto @ ^0.4.0 - -[LilyGo_Techo] -extends = nrf52840_techo -board = t-echo -board_build.ldscript = boards/nrf52840_s140_v6.ld -build_flags = ${nrf52840_techo.build_flags} - -I variants/techo - -DLILYGO_TECHO + -D LILYGO_TECHO -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22 + -D P_LORA_DIO_1=20 + -D P_LORA_NSS=24 + -D P_LORA_RESET=25 + -D P_LORA_BUSY=17 + -D P_LORA_SCLK=19 + -D P_LORA_MISO=23 + -D P_LORA_MOSI=22 + -D SX126X_POWER_EN=37 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 -D P_LORA_TX_LED=LED_GREEN @@ -28,23 +30,31 @@ build_flags = ${nrf52840_techo.build_flags} -D GPS_BAUD_RATE=9600 -D PIN_GPS_EN=GPS_EN -D TELEM_BME280_ADDRESS=0x77 -build_src_filter = ${nrf52840_techo.build_src_filter} + -D DISPLAY_CLASS=GxEPDDisplay + -D BACKLIGHT_BTN=PIN_BUTTON2 + -D AUTO_OFF_MILLIS=0 +build_src_filter = ${nrf52_base.build_src_filter} + - + + + + - +<../variants/techo> + + + + + +<../variants/lilygo_techo> lib_deps = - ${nrf52840_techo.lib_deps} + ${nrf52_base.lib_deps} stevemarple/MicroNMEA @ ^2.0.6 adafruit/Adafruit BME280 Library @ ^2.3.0 + zinggjm/GxEPD2 @ 1.6.2 + bakercp/CRC32 @ ^2.0.0 debug_tool = jlink upload_protocol = nrfutil [env:LilyGo_T-Echo_repeater] -extends = LilyGo_Techo -build_src_filter = ${LilyGo_Techo.build_src_filter} +<../examples/simple_repeater/main.cpp> +extends = LilyGo_T-Echo +build_src_filter = ${LilyGo_T-Echo.build_src_filter} + +<../examples/simple_repeater> build_flags = - ${LilyGo_Techo.build_flags} + ${LilyGo_T-Echo.build_flags} -D ADVERT_NAME='"T-Echo Repeater"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -54,10 +64,11 @@ build_flags = ; -D MESH_DEBUG=1 [env:LilyGo_T-Echo_room_server] -extends = LilyGo_Techo -build_src_filter = ${LilyGo_Techo.build_src_filter} +<../examples/simple_room_server/main.cpp> +extends = LilyGo_T-Echo +build_src_filter = ${LilyGo_T-Echo.build_src_filter} + +<../examples/simple_room_server> build_flags = - ${LilyGo_Techo.build_flags} + ${LilyGo_T-Echo.build_flags} -D ADVERT_NAME='"T-Echo Room"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -66,31 +77,41 @@ build_flags = ; -D MESH_DEBUG=1 [env:LilyGo_T-Echo_companion_radio_ble] -extends = LilyGo_Techo +extends = LilyGo_T-Echo build_flags = - ${LilyGo_Techo.build_flags} + ${LilyGo_T-Echo.build_flags} -I src/helpers/ui -I examples/companion_radio/ui-new -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 - -D DISPLAY_CLASS=GxEPDDisplay -D OFFLINE_QUEUE_SIZE=256 - -D UI_RECENT_LIST_SIZE=9 - -D BACKLIGHT_BTN=PIN_BUTTON2 - -D AUTO_OFF_MILLIS=0 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -build_src_filter = ${LilyGo_Techo.build_src_filter} - + + -D AUTO_SHUTDOWN_MILLIVOLTS=3300 +build_src_filter = ${LilyGo_T-Echo.build_src_filter} + - + - + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> lib_deps = - ${LilyGo_Techo.lib_deps} + ${LilyGo_T-Echo.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:LilyGo_T-Echo_companion_radio_usb] +extends = LilyGo_T-Echo +build_flags = + ${LilyGo_T-Echo.build_flags} + -I src/helpers/ui + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 + -D OFFLINE_QUEUE_SIZE=256 + -D UI_RECENT_LIST_SIZE=9 + -D AUTO_SHUTDOWN_MILLIVOLTS=3300 +build_src_filter = ${LilyGo_T-Echo.build_src_filter} + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${LilyGo_T-Echo.lib_deps} densaugeo/base64 @ ~1.4.0 - zinggjm/GxEPD2 @ 1.6.2 - bakercp/CRC32 @ ^2.0.0 diff --git a/variants/techo/target.cpp b/variants/lilygo_techo/target.cpp similarity index 100% rename from variants/techo/target.cpp rename to variants/lilygo_techo/target.cpp diff --git a/variants/techo/target.h b/variants/lilygo_techo/target.h similarity index 95% rename from variants/techo/target.h rename to variants/lilygo_techo/target.h index 134f13b5..2b6ed45f 100644 --- a/variants/techo/target.h +++ b/variants/lilygo_techo/target.h @@ -3,7 +3,7 @@ #define RADIOLIB_STATIC_ONLY 1 #include #include -#include +#include #include #include #include diff --git a/variants/techo/variant.cpp b/variants/lilygo_techo/variant.cpp similarity index 100% rename from variants/techo/variant.cpp rename to variants/lilygo_techo/variant.cpp diff --git a/variants/techo/variant.h b/variants/lilygo_techo/variant.h similarity index 100% rename from variants/techo/variant.h rename to variants/lilygo_techo/variant.h From 816bbf925f1742f701f89bf271df340447e853f8 Mon Sep 17 00:00:00 2001 From: recrof Date: Thu, 4 Sep 2025 23:12:57 +0200 Subject: [PATCH 37/48] t1000 cleanup + move NullDisplayDriver.h to helpers/ui for other variants to use --- .../helpers/ui}/NullDisplayDriver.h | 0 variants/t1000-e/platformio.ini | 22 +- variants/t1000-e/t1000e_sensors.cpp | 194 ++++++++---------- variants/t1000-e/t1000e_sensors.h | 3 +- 4 files changed, 94 insertions(+), 125 deletions(-) rename {variants/t1000-e => src/helpers/ui}/NullDisplayDriver.h (100%) diff --git a/variants/t1000-e/NullDisplayDriver.h b/src/helpers/ui/NullDisplayDriver.h similarity index 100% rename from variants/t1000-e/NullDisplayDriver.h rename to src/helpers/ui/NullDisplayDriver.h diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index b1826139..d43d5bf6 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -1,25 +1,13 @@ -; ----------------- NRF52 T1000e--------------------- -[nrf52840_t1000e] +[t1000-e] extends = nrf52_base -platform_packages = framework-arduinoadafruitnrf52 +board = tracker-t1000-e +board_build.ldscript = boards/nrf52840_s140_v7.ld build_flags = ${nrf52_base.build_flags} -I src/helpers/nrf52 -I lib/nrf52/s140_nrf52_7.3.0_API/include -I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52 -lib_ignore = - BluetoothOTA - lvgl - lib5b4 -lib_deps = - ${nrf52_base.lib_deps} - rweather/Crypto @ ^0.4.0 - -[t1000-e] -extends = nrf52840_t1000e -board = tracker-t1000-e -board_build.ldscript = boards/nrf52840_s140_v7.ld -build_flags = ${nrf52840_t1000e.build_flags} -I variants/t1000-e + -I src/helpers/ui -D T1000_E -D PIN_USER_BTN=6 -D USER_BTN_PRESSED=HIGH @@ -27,7 +15,7 @@ build_flags = ${nrf52840_t1000e.build_flags} -D RADIO_CLASS=CustomLR1110 -D WRAPPER_CLASS=CustomLR1110Wrapper -D LORA_TX_POWER=22 -build_src_filter = ${nrf52840_t1000e.build_src_filter} +build_src_filter = ${nrf52_base.build_src_filter} + + +<../variants/t1000-e> diff --git a/variants/t1000-e/t1000e_sensors.cpp b/variants/t1000-e/t1000e_sensors.cpp index 17693022..a5b443cf 100644 --- a/variants/t1000-e/t1000e_sensors.cpp +++ b/variants/t1000-e/t1000e_sensors.cpp @@ -1,119 +1,99 @@ -#include #include "t1000e_sensors.h" -#define HEATER_NTC_BX 4250 // thermistor coefficient B -#define HEATER_NTC_RP 8250 // ohm, series resistance to thermistor -#define HEATER_NTC_KA 273.15 // 25 Celsius at Kelvin -#define NTC_REF_VCC 3000 // mV, output voltage of LDO -#define LIGHT_REF_VCC 2400 // - -static unsigned int ntc_res2[136]={ - 113347,107565,102116,96978,92132,87559,83242,79166,75316,71677, - 68237,64991,61919,59011,56258,53650,51178,48835,46613,44506, - 42506,40600,38791,37073,35442,33892,32420,31020,29689,28423, - 27219,26076,24988,23951,22963,22021,21123,20267,19450,18670, - 17926,17214,16534,15886,15266,14674,14108,13566,13049,12554, - 12081,11628,11195,10780,10382,10000,9634,9284,8947,8624, - 8315,8018,7734,7461,7199,6948,6707,6475,6253,6039, - 5834,5636,5445,5262,5086,4917,4754,4597,4446,4301, - 4161,4026,3896,3771,3651,3535,3423,3315,3211,3111, - 3014,2922,2834,2748,2666,2586,2509,2435,2364,2294, - 2228,2163,2100,2040,1981,1925,1870,1817,1766,1716, - 1669,1622,1578,1535,1493,1452,1413,1375,1338,1303, - 1268,1234,1202,1170,1139,1110,1081,1053,1026,999, - 974,949,925,902,880,858, -}; - -static char ntc_temp2[136]= -{ - -30,-29,-28,-27,-26,-25,-24,-23,-22,-21, - -20,-19,-18,-17,-16,-15,-14,-13,-12,-11, - -10,-9,-8,-7,-6,-5,-4,-3,-2,-1, - 0,1,2,3,4,5,6,7,8,9, - 10,11,12,13,14,15,16,17,18,19, - 20,21,22,23,24,25,26,27,28,29, - 30,31,32,33,34,35,36,37,38,39, - 40,41,42,43,44,45,46,47,48,49, - 50,51,52,53,54,55,56,57,58,59, - 60,61,62,63,64,65,66,67,68,69, - 70,71,72,73,74,75,76,77,78,79, - 80,81,82,83,84,85,86,87,88,89, - 90,91,92,93,94,95,96,97,98,99, - 100,101,102,103,104,105, +#include + +#define HEATER_NTC_BX 4250 // thermistor coefficient B +#define HEATER_NTC_RP 8250 // ohm, series resistance to thermistor +#define HEATER_NTC_KA 273.15 // 25 Celsius at Kelvin +#define NTC_REF_VCC 3000 // mV, output voltage of LDO +#define LIGHT_REF_VCC 2400 // + +static unsigned int ntc_res2[136] = { + 113347, 107565, 102116, 96978, 92132, 87559, 83242, 79166, 75316, 71677, 68237, 64991, 61919, 59011, + 56258, 53650, 51178, 48835, 46613, 44506, 42506, 40600, 38791, 37073, 35442, 33892, 32420, 31020, + 29689, 28423, 27219, 26076, 24988, 23951, 22963, 22021, 21123, 20267, 19450, 18670, 17926, 17214, + 16534, 15886, 15266, 14674, 14108, 13566, 13049, 12554, 12081, 11628, 11195, 10780, 10382, 10000, + 9634, 9284, 8947, 8624, 8315, 8018, 7734, 7461, 7199, 6948, 6707, 6475, 6253, 6039, + 5834, 5636, 5445, 5262, 5086, 4917, 4754, 4597, 4446, 4301, 4161, 4026, 3896, 3771, + 3651, 3535, 3423, 3315, 3211, 3111, 3014, 2922, 2834, 2748, 2666, 2586, 2509, 2435, + 2364, 2294, 2228, 2163, 2100, 2040, 1981, 1925, 1870, 1817, 1766, 1716, 1669, 1622, + 1578, 1535, 1493, 1452, 1413, 1375, 1338, 1303, 1268, 1234, 1202, 1170, 1139, 1110, + 1081, 1053, 1026, 999, 974, 949, 925, 902, 880, 858, }; -static float get_heater_temperature( unsigned int vcc_volt, unsigned int ntc_volt ) -{ - int i = 0; - float Vout = 0, Rt = 0, temp = 0; - Vout = ntc_volt; - - Rt = ( HEATER_NTC_RP * vcc_volt ) / Vout - HEATER_NTC_RP; - - for( i = 0; i < 136; i++ ) - { - if( Rt >= ntc_res2[i] ) - { - break; - } +static char ntc_temp2[136] = { + -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, +}; + +static float get_heater_temperature(unsigned int vcc_volt, unsigned int ntc_volt) { + int i = 0; + float Vout = 0, Rt = 0, temp = 0; + Vout = ntc_volt; + + Rt = (HEATER_NTC_RP * vcc_volt) / Vout - HEATER_NTC_RP; + + for (i = 0; i < 136; i++) { + if (Rt >= ntc_res2[i]) { + break; } - - temp = ntc_temp2[i - 1] + 1 * ( ntc_res2[i - 1] - Rt ) / ( float )( ntc_res2[i - 1] - ntc_res2[i] ); - - temp = ( temp * 100 + 5 ) / 100; - return temp; + } + + temp = ntc_temp2[i - 1] + 1 * (ntc_res2[i - 1] - Rt) / (float)(ntc_res2[i - 1] - ntc_res2[i]); + + temp = (temp * 100 + 5) / 100; + return temp; } -static int get_light_lv( unsigned int light_volt ) -{ - float Vout = 0, Vin = 0, Rt = 0, temp = 0; - unsigned int light_level = 0; - - if( light_volt <= 80 ) - { - light_level = 0; - return light_level; - } - else if( light_volt >= 2480 ) - { - light_level = 100; - return light_level; - } - Vout = light_volt; - light_level = 100 * ( Vout - 80 ) / LIGHT_REF_VCC; - +static int get_light_lv(unsigned int light_volt) { + float Vout = 0, Vin = 0, Rt = 0, temp = 0; + unsigned int light_level = 0; + + if (light_volt <= 80) { + light_level = 0; return light_level; -} + } else if (light_volt >= 2480) { + light_level = 100; + return light_level; + } + Vout = light_volt; + light_level = 100 * (Vout - 80) / LIGHT_REF_VCC; -float t1000e_get_temperature( void ) -{ - unsigned int ntc_v, vcc_v; - - digitalWrite(PIN_3V3_EN, HIGH); - digitalWrite(SENSOR_EN, HIGH); - analogReference(AR_INTERNAL_3_0); - analogReadResolution(12); - delay(10); - vcc_v = (1000.0*(analogRead(BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE)) / 4096; - ntc_v = (1000.0 * AREF_VOLTAGE * analogRead(TEMP_SENSOR)) / 4096; - digitalWrite(PIN_3V3_EN, LOW); - digitalWrite(SENSOR_EN, LOW); - - return get_heater_temperature (vcc_v, ntc_v); + return light_level; } -uint32_t t1000e_get_light( void ) -{ - int lux = 0; - unsigned int lux_v = 0; - - digitalWrite(SENSOR_EN, HIGH); - analogReference(AR_INTERNAL_3_0); - analogReadResolution(12); - delay(10); - lux_v = 1000 * analogRead(LUX_SENSOR) * AREF_VOLTAGE / 4096; - lux = get_light_lv( lux_v ); - digitalWrite(SENSOR_EN, LOW); - - return lux; +float t1000e_get_temperature(void) { + unsigned int ntc_v, vcc_v; + + digitalWrite(PIN_3V3_EN, HIGH); + digitalWrite(SENSOR_EN, HIGH); + analogReference(AR_INTERNAL_3_0); + analogReadResolution(12); + delay(10); + vcc_v = (1000.0 * (analogRead(BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE)) / 4096; + ntc_v = (1000.0 * AREF_VOLTAGE * analogRead(TEMP_SENSOR)) / 4096; + digitalWrite(PIN_3V3_EN, LOW); + digitalWrite(SENSOR_EN, LOW); + + return get_heater_temperature(vcc_v, ntc_v); +} + +uint32_t t1000e_get_light(void) { + int lux = 0; + unsigned int lux_v = 0; + + digitalWrite(SENSOR_EN, HIGH); + analogReference(AR_INTERNAL_3_0); + analogReadResolution(12); + delay(10); + lux_v = 1000 * analogRead(LUX_SENSOR) * AREF_VOLTAGE / 4096; + lux = get_light_lv(lux_v); + digitalWrite(SENSOR_EN, LOW); + + return lux; } \ No newline at end of file diff --git a/variants/t1000-e/t1000e_sensors.h b/variants/t1000-e/t1000e_sensors.h index 8f3967ca..e8f790b6 100644 --- a/variants/t1000-e/t1000e_sensors.h +++ b/variants/t1000-e/t1000e_sensors.h @@ -1,7 +1,8 @@ #pragma once +#include // Light and temperature sensors are on ADC ports -// functions adapted from Seeed examples to get values +// functions adapted from Seeed examples to get values // see : https://github.com/Seeed-Studio/Seeed-Tracker-T1000-E-for-LoRaWAN-dev-board extern uint32_t t1000e_get_light(); From 9b9c7289e67abb75670cb688f2e70f03691e9b91 Mon Sep 17 00:00:00 2001 From: recrof Date: Thu, 4 Sep 2025 23:31:05 +0200 Subject: [PATCH 38/48] moved pindefs from board to platformio.ini --- variants/t1000-e/T1000eBoard.h | 20 ++------------------ variants/t1000-e/platformio.ini | 18 +++++++++++------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/variants/t1000-e/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h index f87d71e0..090c1b90 100644 --- a/variants/t1000-e/T1000eBoard.h +++ b/variants/t1000-e/T1000eBoard.h @@ -3,22 +3,6 @@ #include #include -// LoRa and SPI pins -#define P_LORA_DIO_1 (32 + 1) // P1.1 -#define P_LORA_NSS (0 + 12) // P0.12 -#define P_LORA_RESET (32 + 10) // P1.10 -#define P_LORA_BUSY (0 + 7) // P0.7 -#define P_LORA_SCLK (0 + 11) // P0.11 -#define P_LORA_MISO (32 + 8) // P1.8 -#define P_LORA_MOSI (32 + 9) // P0.9 - -#define LR11X0_DIO_AS_RF_SWITCH true -#define LR11X0_DIO3_TCXO_VOLTAGE 1.6 - -// built-ins -//#define PIN_VBAT_READ 5 -//#define ADC_MULTIPLIER (3 * 1.73 * 1000) - class T1000eBoard : public mesh::MainBoard { protected: uint8_t startup_reason; @@ -75,11 +59,11 @@ public: pinMode(GPS_RESETB, OUTPUT); digitalWrite(GPS_RESETB, LOW); #endif - + #ifdef BUZZER_EN digitalWrite(BUZZER_EN, LOW); #endif - + #ifdef PIN_3V3_EN digitalWrite(PIN_3V3_EN, LOW); #endif diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index d43d5bf6..044fffd8 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -15,6 +15,17 @@ build_flags = ${nrf52_base.build_flags} -D RADIO_CLASS=CustomLR1110 -D WRAPPER_CLASS=CustomLR1110Wrapper -D LORA_TX_POWER=22 + -D RF_SWITCH_TABLE + -D RX_BOOSTED_GAIN=true + -D P_LORA_BUSY=7 ; P0.7 + -D P_LORA_SCLK=11 ; P0.11 + -D P_LORA_NSS=12 ; P0.12 + -D P_LORA_DIO_1=33 ; P1.1 + -D P_LORA_MISO=40 ; P1.8 + -D P_LORA_MOSI=41 ; P0.9 + -D P_LORA_RESET=42 ; P1.10 + -D LR11X0_DIO_AS_RF_SWITCH=true + -D LR11X0_DIO3_TCXO_VOLTAGE=1.6 build_src_filter = ${nrf52_base.build_src_filter} + + @@ -33,8 +44,6 @@ build_flags = ${t1000-e.build_flags} -D MAX_NEIGHBOURS=8 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 - -D RX_BOOSTED_GAIN=true - -D RF_SWITCH_TABLE build_src_filter = ${t1000-e.build_src_filter} +<../examples/simple_repeater> lib_deps = ${t1000-e.lib_deps} @@ -51,7 +60,6 @@ build_flags = ${t1000-e.build_flags} -D ROOM_PASSWORD='"hello"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 - -D RX_BOOSTED_GAIN=true -D RF_SWITCH_TABLE build_src_filter = ${t1000-e.build_src_filter} +<../examples/simple_room_server> @@ -67,8 +75,6 @@ build_flags = ${t1000-e.build_flags} ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -D OFFLINE_QUEUE_SIZE=256 - -D RX_BOOSTED_GAIN=true - -D RF_SWITCH_TABLE -D DISPLAY_CLASS=NullDisplayDriver -D PIN_BUZZER=25 -D PIN_BUZZER_EN=37 ; P1/5 - required for T1000-E @@ -92,8 +98,6 @@ build_flags = ${t1000-e.build_flags} ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -D OFFLINE_QUEUE_SIZE=256 - -D RX_BOOSTED_GAIN=true - -D RF_SWITCH_TABLE -D DISPLAY_CLASS=NullDisplayDriver -D PIN_BUZZER=25 -D PIN_BUZZER_EN=37 ; P1/5 - required for T1000-E From c9e6ae9e6c907a4fcf0bf1917ede33754b508c51 Mon Sep 17 00:00:00 2001 From: recrof Date: Fri, 5 Sep 2025 11:12:17 +0200 Subject: [PATCH 39/48] fix typo in pin configuration --- variants/xiao_rp2040/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/xiao_rp2040/platformio.ini b/variants/xiao_rp2040/platformio.ini index 48ae3c26..6c9c70f6 100644 --- a/variants/xiao_rp2040/platformio.ini +++ b/variants/xiao_rp2040/platformio.ini @@ -13,7 +13,7 @@ build_flags = ${rp2040_base.build_flags} -D P_LORA_BUSY=29 ; D3 -D P_LORA_TX_LED=17 -D SX126X_RXEN=7 ; D5 - -D SX126X_TXEN=1 + -D SX126X_TXEN=RADIOLIB_NC -D SX126X_DIO2_AS_RF_SWITCH=true -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_RX_BOOSTED_GAIN=1 From 8549696e4d9273dfe99e2e95ab710ac759bdcdbd Mon Sep 17 00:00:00 2001 From: recrof Date: Fri, 5 Sep 2025 11:17:57 +0200 Subject: [PATCH 40/48] generic e22 uses new radio init --- variants/generic-e22/target.cpp | 42 ++++----------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/variants/generic-e22/target.cpp b/variants/generic-e22/target.cpp index d9b70c3a..e0253779 100644 --- a/variants/generic-e22/target.cpp +++ b/variants/generic-e22/target.cpp @@ -16,47 +16,15 @@ ESP32RTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); SensorManager sensors; -#ifndef LORA_CR - #define LORA_CR 5 -#endif - bool radio_init() { fallback_clock.begin(); rtc_clock.begin(Wire); - -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif -#if defined(P_LORA_SCLK) - spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); -#endif - int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); - if (status != RADIOLIB_ERR_NONE) { - Serial.print("ERROR: radio init failed: "); - Serial.println(status); - return false; // fail - } - - radio.setCRC(1); - -#if defined(SX126X_RXEN) && defined(SX126X_TXEN) - radio.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); -#endif - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif - - return true; // success + #if defined(P_LORA_SCLK) + return radio.std_init(&spi); + #else + return radio.std_init(); + #endif } uint32_t radio_get_rng_seed() { From 24b29538617c6772311e0a0672c427ee56e13e04 Mon Sep 17 00:00:00 2001 From: recrof Date: Fri, 5 Sep 2025 11:33:48 +0200 Subject: [PATCH 41/48] tlora_c6 to use new radio init --- variants/lilygo_tlora_c6/target.cpp | 40 +++-------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/variants/lilygo_tlora_c6/target.cpp b/variants/lilygo_tlora_c6/target.cpp index 1e60dc32..e12c58b5 100644 --- a/variants/lilygo_tlora_c6/target.cpp +++ b/variants/lilygo_tlora_c6/target.cpp @@ -16,49 +16,15 @@ ESP32RTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); SensorManager sensors; -#ifndef LORA_CR - #define LORA_CR 5 -#endif - bool radio_init() { fallback_clock.begin(); rtc_clock.begin(Wire); -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif - #if defined(P_LORA_SCLK) - spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); + return radio.std_init(&spi); +#else + return radio.std_init(); #endif - int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); - if (status != RADIOLIB_ERR_NONE) { - Serial.print("ERROR: radio init failed: "); - Serial.println(status); - return false; // fail - } - - radio.setCRC(1); - -#if defined(SX126X_RXEN) && defined(SX126X_TXEN) - radio.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); -#endif - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif - -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif - -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif - - return true; // success } uint32_t radio_get_rng_seed() { From 2ef38422e9f3184b533fb52fb9767b918163b9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Fri, 5 Sep 2025 17:59:59 +0100 Subject: [PATCH 42/48] Delete the variant-specific NullDisplayDriver.h and update target.h to use the shared implementation from #735 --- variants/heltec_t114/NullDisplayDriver.h | 24 ------------------------ variants/heltec_t114/target.h | 2 +- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 variants/heltec_t114/NullDisplayDriver.h diff --git a/variants/heltec_t114/NullDisplayDriver.h b/variants/heltec_t114/NullDisplayDriver.h deleted file mode 100644 index 2a9670bd..00000000 --- a/variants/heltec_t114/NullDisplayDriver.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -class NullDisplayDriver : public DisplayDriver { -public: - NullDisplayDriver() : DisplayDriver(128, 64) { } - bool begin() { return false; } // not present - - bool isOn() override { return false; } - void turnOn() override { } - void turnOff() override { } - void clear() override { } - void startFrame(Color bkg = DARK) override { } - void setTextSize(int sz) override { } - void setColor(Color c) override { } - void setCursor(int x, int y) override { } - void print(const char* str) override { } - void fillRect(int x, int y, int w, int h) override { } - void drawRect(int x, int y, int w, int h) override { } - void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { } - uint16_t getTextWidth(const char* str) override { return 0; } - void endFrame() { } -}; diff --git a/variants/heltec_t114/target.h b/variants/heltec_t114/target.h index 3283f009..1876aadc 100644 --- a/variants/heltec_t114/target.h +++ b/variants/heltec_t114/target.h @@ -14,7 +14,7 @@ #ifdef HELTEC_T114_WITH_DISPLAY #include #else -#include "NullDisplayDriver.h" +#include "helpers/ui/NullDisplayDriver.h" #endif #endif From c5180d4588b226f91933f6f2d31f312b610d6346 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 29 Jul 2025 20:06:35 +1000 Subject: [PATCH 43/48] initial commit: CustomLFS --- examples/companion_radio/DataStore.cpp | 23 ++++++++++++++------ examples/companion_radio/main.cpp | 30 ++++++++++++++++++++++++-- platformio.ini | 4 ++++ src/helpers/IdentityStore.h | 21 +++++++++++++----- variants/xiao_nrf52/platformio.ini | 3 ++- 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index b5d70edc..8e774d91 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -1,6 +1,12 @@ #include #include "DataStore.h" +#if defined(EXTRAFS) || defined(SPIFLASH) + #define MAX_BLOBRECS 100 +#else + #define MAX_BLOBRECS 20 +#endif + DataStore::DataStore(FILESYSTEM& fs, mesh::RTCClock& clock) : _fs(&fs), _clock(&clock), #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) identity_store(fs, "") @@ -41,7 +47,9 @@ void DataStore::begin() { #elif defined(RP2040_PLATFORM) #include #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - #include + // #include // disabled for now, leaving here for dual fs branch + #include + #include #endif #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) @@ -51,9 +59,9 @@ int _countLfsBlock(void *p, lfs_block_t block){ return 0; } -lfs_ssize_t _getLfsUsedBlockCount() { +lfs_ssize_t _getLfsUsedBlockCount(FILESYSTEM* fs) { lfs_size_t size = 0; - lfs_traverse(InternalFS._getFS(), _countLfsBlock, &size); + lfs_traverse(fs->_getFS(), _countLfsBlock, &size); return size; } #endif @@ -67,8 +75,8 @@ uint32_t DataStore::getStorageUsedKb() const { _fs->info(info); return info.usedBytes / 1024; #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - const lfs_config* config = InternalFS._getFS()->cfg; - int usedBlockCount = _getLfsUsedBlockCount(); + const lfs_config* config = _fs->_getFS()->cfg; + int usedBlockCount = _getLfsUsedBlockCount(_fs); int usedBytes = config->block_size * usedBlockCount; return usedBytes / 1024; #else @@ -85,7 +93,7 @@ uint32_t DataStore::getStorageTotalKb() const { _fs->info(info); return info.totalBytes / 1024; #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - const lfs_config* config = InternalFS._getFS()->cfg; + const lfs_config* config = _fs->_getFS()->cfg; int totalBytes = config->block_size * config->block_count; return totalBytes / 1024; #else @@ -109,6 +117,7 @@ bool DataStore::removeFile(const char* filename) { bool DataStore::formatFileSystem() { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + // InternalFS.format(); // leaving as placeholder to remind for dual fs branch return _fs->format(); #elif defined(RP2040_PLATFORM) return LittleFS.format(); @@ -336,7 +345,7 @@ void DataStore::checkAdvBlobFile() { if (file) { BlobRec zeroes; memset(&zeroes, 0, sizeof(zeroes)); - for (int i = 0; i < 20; i++) { // pre-allocate to fixed size + for (int i = 0; i < MAX_BLOBRECS; i++) { // pre-allocate to fixed size file.write((uint8_t *) &zeroes, sizeof(zeroes)); } file.close(); diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 1d5ec564..4900d3bc 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -14,7 +14,20 @@ static uint32_t _atoi(const char* sp) { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) #include - DataStore store(InternalFS, rtc_clock); + #if defined(SPIFLASH) + #include + const int chipSelect = PIN_QSPI_CS; + SPIClass SPI_2(NRF_SPIM2, PIN_QSPI_IO1, PIN_QSPI_SCK, PIN_QSPI_IO0); + DataStore store(FlashFS, rtc_clock); + #else + #if defined(EXTRAFS) + #include + CustomLFS ExtraFS(0xD4000, 0x19000, 128); + DataStore store(ExtraFS, rtc_clock); + #else + DataStore store(InternalFS, rtc_clock); + #endif + #endif #elif defined(RP2040_PLATFORM) #include DataStore store(LittleFS, rtc_clock); @@ -23,6 +36,7 @@ static uint32_t _atoi(const char* sp) { DataStore store(SPIFFS, rtc_clock); #endif + #ifdef ESP32 #ifdef WIFI_SSID #include @@ -117,7 +131,19 @@ void setup() { fast_rng.begin(radio_get_rng_seed()); #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - InternalFS.begin(); + #if defined(SPIFLASH) + if (!FlashFS.begin(chipSelect, SPI_2)) { + // debug output might not be available at this point, might be too early. maybe should fall back to InternalFS here? + MESH_DEBUG_PRINTLN("CustomLFS_SPIFlash: failed to initialize"); + } else { + MESH_DEBUG_PRINTLN("CustomLFS_SPIFlash: initialized successfully"); + } + #else + InternalFS.begin(); + #if defined(EXTRAFS) + ExtraFS.begin(); + #endif + #endif store.begin(); the_mesh.begin( #ifdef DISPLAY_CLASS diff --git a/platformio.ini b/platformio.ini index 1c89465f..5fe46986 100644 --- a/platformio.ini +++ b/platformio.ini @@ -78,6 +78,10 @@ platform = nordicnrf52 build_flags = ${arduino_base.build_flags} -D NRF52_PLATFORM -D LFS_NO_ASSERT=1 + -D EXTRAFS=1 +lib_deps = + ${arduino_base.lib_deps} + https://github.com/oltaco/CustomLFS ; ----------------- RP2040 --------------------- diff --git a/src/helpers/IdentityStore.h b/src/helpers/IdentityStore.h index e81290e7..15219a44 100644 --- a/src/helpers/IdentityStore.h +++ b/src/helpers/IdentityStore.h @@ -4,12 +4,19 @@ #include #define FILESYSTEM fs::FS #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - #include - #define FILESYSTEM Adafruit_LittleFS + #if defined(SPIFLASH) + #include + #define FILESYSTEM CustomLFS_SPIFlash + #elif defined(EXTRAFS) + #include + #define FILESYSTEM CustomLFS + #else + #include + #define FILESYSTEM Adafruit_LittleFS - using namespace Adafruit_LittleFS_Namespace; + using namespace Adafruit_LittleFS_Namespace; + #endif #endif - #include class IdentityStore { @@ -18,7 +25,11 @@ class IdentityStore { public: IdentityStore(FILESYSTEM& fs, const char* dir): _fs(&fs), _dir(dir) { } - void begin() { if (_dir && _dir[0] == '/') { _fs->mkdir(_dir); } } + void begin() { + if (_dir && _dir[0] == '/') { _fs->mkdir(_dir); } + + + } bool load(const char *name, mesh::LocalIdentity& id); bool load(const char *name, mesh::LocalIdentity& id, char display_name[], int max_name_sz); bool save(const char *name, const mesh::LocalIdentity& id); diff --git a/variants/xiao_nrf52/platformio.ini b/variants/xiao_nrf52/platformio.ini index fd4c362b..3717c26d 100644 --- a/variants/xiao_nrf52/platformio.ini +++ b/variants/xiao_nrf52/platformio.ini @@ -65,7 +65,8 @@ build_flags = -D OFFLINE_QUEUE_SIZE=256 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 -; -D MESH_DEBUG=1 + -D MESH_DEBUG=1 + -D SPIFLASH=1 build_src_filter = ${Xiao_nrf52.build_src_filter} + +<../examples/companion_radio/*.cpp> From bdfe9ad27bffcf4e9566c0e561048a38ebd3174e Mon Sep 17 00:00:00 2001 From: taco Date: Sat, 2 Aug 2025 08:31:23 +1000 Subject: [PATCH 44/48] switch to using QSPI bus for external flash --- examples/companion_radio/DataStore.cpp | 6 ++++-- examples/companion_radio/main.cpp | 16 +++++++--------- src/helpers/IdentityStore.h | 6 +++--- variants/nano_g2_ultra/platformio.ini | 1 + variants/thinknode_m1/platformio.ini | 1 + variants/thinknode_m1/variant.h | 9 +++++++++ variants/wio-tracker-l1/platformio.ini | 1 + variants/xiao_nrf52/platformio.ini | 2 +- 8 files changed, 27 insertions(+), 15 deletions(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 8e774d91..8c2962d3 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -1,7 +1,7 @@ #include #include "DataStore.h" -#if defined(EXTRAFS) || defined(SPIFLASH) +#if defined(EXTRAFS) || defined(QSPIFLASH) #define MAX_BLOBRECS 100 #else #define MAX_BLOBRECS 20 @@ -49,7 +49,9 @@ void DataStore::begin() { #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) // #include // disabled for now, leaving here for dual fs branch #include - #include + #if defined(QSPIFLASH) + #include + #endif #endif #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 4900d3bc..2dca708d 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -14,11 +14,9 @@ static uint32_t _atoi(const char* sp) { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) #include - #if defined(SPIFLASH) - #include - const int chipSelect = PIN_QSPI_CS; - SPIClass SPI_2(NRF_SPIM2, PIN_QSPI_IO1, PIN_QSPI_SCK, PIN_QSPI_IO0); - DataStore store(FlashFS, rtc_clock); + #if defined(QSPIFLASH) + #include + DataStore store(QSPIFlash, rtc_clock); #else #if defined(EXTRAFS) #include @@ -131,12 +129,12 @@ void setup() { fast_rng.begin(radio_get_rng_seed()); #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - #if defined(SPIFLASH) - if (!FlashFS.begin(chipSelect, SPI_2)) { + #if defined(QSPIFLASH) + if (!QSPIFlash.begin()) { // debug output might not be available at this point, might be too early. maybe should fall back to InternalFS here? - MESH_DEBUG_PRINTLN("CustomLFS_SPIFlash: failed to initialize"); + MESH_DEBUG_PRINTLN("CustomLFS_QSPIFlash: failed to initialize"); } else { - MESH_DEBUG_PRINTLN("CustomLFS_SPIFlash: initialized successfully"); + MESH_DEBUG_PRINTLN("CustomLFS_QSPIFlash: initialized successfully"); } #else InternalFS.begin(); diff --git a/src/helpers/IdentityStore.h b/src/helpers/IdentityStore.h index 15219a44..99c2bd77 100644 --- a/src/helpers/IdentityStore.h +++ b/src/helpers/IdentityStore.h @@ -4,9 +4,9 @@ #include #define FILESYSTEM fs::FS #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - #if defined(SPIFLASH) - #include - #define FILESYSTEM CustomLFS_SPIFlash + #if defined(QSPIFLASH) + #include + #define FILESYSTEM CustomLFS_QSPIFlash #elif defined(EXTRAFS) #include #define FILESYSTEM CustomLFS diff --git a/variants/nano_g2_ultra/platformio.ini b/variants/nano_g2_ultra/platformio.ini index 7fb2de28..e70c353b 100644 --- a/variants/nano_g2_ultra/platformio.ini +++ b/variants/nano_g2_ultra/platformio.ini @@ -42,6 +42,7 @@ build_flags = -D OFFLINE_QUEUE_SIZE=256 -D DISPLAY_CLASS=SH1106Display -D PIN_BUZZER=4 + -D QSPIFLASH=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Nano_G2_Ultra.build_src_filter} diff --git a/variants/thinknode_m1/platformio.ini b/variants/thinknode_m1/platformio.ini index e29e1471..eadc83ae 100644 --- a/variants/thinknode_m1/platformio.ini +++ b/variants/thinknode_m1/platformio.ini @@ -80,6 +80,7 @@ build_flags = -D OFFLINE_QUEUE_SIZE=256 -D PIN_BUZZER=6 -D AUTO_SHUTDOWN_MILLIVOLTS=3300 + -D QSPIFLASH=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${ThinkNode_M1.build_src_filter} diff --git a/variants/thinknode_m1/variant.h b/variants/thinknode_m1/variant.h index 2b58e341..f7f52a6a 100644 --- a/variants/thinknode_m1/variant.h +++ b/variants/thinknode_m1/variant.h @@ -110,6 +110,15 @@ extern const int MISO; extern const int MOSI; extern const int SCK; +//////////////////////////////////////////////////////////////////////////////// +// QSPI +#define PIN_QSPI_SCK (46) +#define PIN_QSPI_CS (47) +#define PIN_QSPI_IO0 (44) // MOSI if using two bit interface +#define PIN_QSPI_IO1 (45) // MISO if using two bit interface +#define PIN_QSPI_IO2 (7) // WP if using two bit interface (i.e. not used) +#define PIN_QSPI_IO3 (5) // HOLD if using two bit interface (i.e. not used) + //////////////////////////////////////////////////////////////////////////////// // Display diff --git a/variants/wio-tracker-l1/platformio.ini b/variants/wio-tracker-l1/platformio.ini index be0086c4..02f09e5c 100644 --- a/variants/wio-tracker-l1/platformio.ini +++ b/variants/wio-tracker-l1/platformio.ini @@ -86,6 +86,7 @@ build_flags = ${WioTrackerL1.build_flags} -D OFFLINE_QUEUE_SIZE=256 -D DISPLAY_CLASS=SH1106Display -D PIN_BUZZER=12 + -D QSPIFLASH=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${WioTrackerL1.build_src_filter} diff --git a/variants/xiao_nrf52/platformio.ini b/variants/xiao_nrf52/platformio.ini index 3717c26d..3e181672 100644 --- a/variants/xiao_nrf52/platformio.ini +++ b/variants/xiao_nrf52/platformio.ini @@ -66,7 +66,7 @@ build_flags = ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 -D MESH_DEBUG=1 - -D SPIFLASH=1 + -D QSPIFLASH=1 build_src_filter = ${Xiao_nrf52.build_src_filter} + +<../examples/companion_radio/*.cpp> From 2b24c575c7dbf77bc322d0155ef3493291780199 Mon Sep 17 00:00:00 2001 From: taco Date: Fri, 22 Aug 2025 13:09:54 +1000 Subject: [PATCH 45/48] support dual filsystems on nrf52 store identity and prefs in UserData and contacts, channels and adv_blobs in ExtraData --- examples/companion_radio/DataStore.cpp | 212 +++++++++++++++++++++++-- examples/companion_radio/DataStore.h | 7 + examples/companion_radio/MyMesh.cpp | 60 ++++++- examples/companion_radio/main.cpp | 10 +- src/helpers/IdentityStore.h | 8 - 5 files changed, 268 insertions(+), 29 deletions(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 8c2962d3..ca7337bd 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -18,14 +18,28 @@ DataStore::DataStore(FILESYSTEM& fs, mesh::RTCClock& clock) : _fs(&fs), _clock(& { } -static File openWrite(FILESYSTEM* _fs, const char* filename) { +#if defined(EXTRAFS) || defined(QSPIFLASH) + +DataStore::DataStore(FILESYSTEM& fs, FILESYSTEM& fsExtra, mesh::RTCClock& clock) : _fs(&fs), _fsExtra(&fsExtra), _clock(&clock), #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - _fs->remove(filename); - return _fs->open(filename, FILE_O_WRITE); + identity_store(fs, "") #elif defined(RP2040_PLATFORM) - return _fs->open(filename, "w"); + identity_store(fs, "/identity") #else - return _fs->open(filename, "w", true); + identity_store(fs, "/identity") +#endif +{ +} +#endif + +static File openWrite(FILESYSTEM* fs, const char* filename) { +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + fs->remove(filename); + return fs->open(filename, FILE_O_WRITE); +#elif defined(RP2040_PLATFORM) + return fs->open(filename, "w"); +#else + return fs->open(filename, "w", true); #endif } @@ -36,6 +50,9 @@ void DataStore::begin() { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) checkAdvBlobFile(); + #if defined(EXTRAFS) || defined(QSPIFLASH) + migrateToSecondaryFS(); + #endif #else // init 'blob store' support _fs->mkdir("/bl"); @@ -46,12 +63,13 @@ void DataStore::begin() { #include #elif defined(RP2040_PLATFORM) #include -#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - // #include // disabled for now, leaving here for dual fs branch +#elif defined(NRF52_PLATFORM) #include #if defined(QSPIFLASH) #include #endif +#elif defined(STM32_PLATFORM) + #include #endif #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) @@ -77,8 +95,13 @@ uint32_t DataStore::getStorageUsedKb() const { _fs->info(info); return info.usedBytes / 1024; #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) +#if defined(EXTRAFS) || defined(QSPIFLASH) + const lfs_config* config = _fsExtra->_getFS()->cfg; + int usedBlockCount = _getLfsUsedBlockCount(_fsExtra); +#else const lfs_config* config = _fs->_getFS()->cfg; int usedBlockCount = _getLfsUsedBlockCount(_fs); +#endif int usedBytes = config->block_size * usedBlockCount; return usedBytes / 1024; #else @@ -95,7 +118,11 @@ uint32_t DataStore::getStorageTotalKb() const { _fs->info(info); return info.totalBytes / 1024; #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) +#if defined(EXTRAFS) || defined(QSPIFLASH) + const lfs_config* config = _fsExtra->_getFS()->cfg; +#else const lfs_config* config = _fs->_getFS()->cfg; +#endif int totalBytes = config->block_size * config->block_count; return totalBytes / 1024; #else @@ -113,14 +140,31 @@ File DataStore::openRead(const char* filename) { #endif } +File DataStore::openRead(FILESYSTEM* fs, const char* filename) { +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + return fs->open(filename, FILE_O_READ); +#elif defined(RP2040_PLATFORM) + return fs->open(filename, "r"); +#else + return fs->open(filename, "r", false); +#endif +} + bool DataStore::removeFile(const char* filename) { return _fs->remove(filename); } +bool DataStore::removeFile(FILESYSTEM* fs, const char* filename) { + return fs->remove(filename); +} + bool DataStore::formatFileSystem() { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - // InternalFS.format(); // leaving as placeholder to remind for dual fs branch +#if defined(EXTRAFS) || defined(QSPIFLASH) + return _fs->format() && _fsExtra->format(); // in future maybe return an error code based on which format failed? +#else return _fs->format(); +#endif #elif defined(RP2040_PLATFORM) return LittleFS.format(); #elif defined(ESP32) @@ -214,11 +258,20 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_ } void DataStore::loadContacts(DataStoreHost* host) { +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) +#if defined(EXTRAFS) || defined(QSPIFLASH) + if (_fsExtra->exists("/contacts3")) { + File file = _fsExtra->open("/contacts3"); +#else if (_fs->exists("/contacts3")) { -#if defined(RP2040_PLATFORM) + File file = _fs->open("/contacts3"); +#endif +#elif defined(RP2040_PLATFORM) + if (_fs->exists("/contacts3")) { File file = _fs->open("/contacts3", "r"); #else - File file = _fs->open("/contacts3"); + if (_fs->exists("/contacts3")) { + File file = _fs->open("/contacts3", "r", false); #endif if (file) { bool full = false; @@ -251,7 +304,11 @@ void DataStore::loadContacts(DataStoreHost* host) { } void DataStore::saveContacts(DataStoreHost* host) { +#if defined(EXTRAFS) || defined(QSPIFLASH) + File file = openWrite(_fsExtra, "/contacts3"); +#else File file = openWrite(_fs, "/contacts3"); +#endif if (file) { uint32_t idx = 0; ContactInfo c; @@ -280,11 +337,20 @@ void DataStore::saveContacts(DataStoreHost* host) { } void DataStore::loadChannels(DataStoreHost* host) { +#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) +#if defined(EXTRAFS) || defined(QSPIFLASH) + if (_fsExtra->exists("/channels2")) { + File file = _fsExtra->open("/channels2"); +#else + if (_fs->exists("/channels2")) { + File file = _fs->open("/channels2"); +#endif +#elif defined(RP2040_PLATFORM) if (_fs->exists("/channels2")) { -#if defined(RP2040_PLATFORM) File file = _fs->open("/channels2", "r"); #else - File file = _fs->open("/channels2"); + if (_fs->exists("/channels2")) { + File file = _fs->open("/channels2", "r", false); #endif if (file) { bool full = false; @@ -311,7 +377,11 @@ void DataStore::loadChannels(DataStoreHost* host) { } void DataStore::saveChannels(DataStoreHost* host) { +#if defined(EXTRAFS) || defined(QSPIFLASH) + File file = openWrite(_fsExtra, "/channels2"); +#else File file = openWrite(_fs, "/channels2"); +#endif if (file) { uint8_t channel_idx = 0; ChannelDetails ch; @@ -342,8 +412,13 @@ struct BlobRec { }; void DataStore::checkAdvBlobFile() { +#if defined(EXTRAFS) || defined(QSPIFLASH) + if (!_fsExtra->exists("/adv_blobs")) { + File file = openWrite(_fsExtra, "/adv_blobs"); +#else if (!_fs->exists("/adv_blobs")) { File file = openWrite(_fs, "/adv_blobs"); +#endif if (file) { BlobRec zeroes; memset(&zeroes, 0, sizeof(zeroes)); @@ -355,8 +430,117 @@ void DataStore::checkAdvBlobFile() { } } +void DataStore::migrateToSecondaryFS() { + // migrate old adv_blobs, contacts3 and channels2 files to secondary FS if they don't already exist + if (!_fsExtra->exists("/adv_blobs")) { + if (_fs->exists("/adv_blobs")) { + File oldAdvBlobs = openRead(_fs, "/adv_blobs"); + File newAdvBlobs = openWrite(_fsExtra, "/adv_blobs"); + + if (oldAdvBlobs && newAdvBlobs) { + BlobRec rec; + size_t count = 0; + + // Copy 20 BlobRecs from old to new + while (count < 20 && oldAdvBlobs.read((uint8_t *)&rec, sizeof(rec)) == sizeof(rec)) { + newAdvBlobs.seek(count * sizeof(BlobRec)); + newAdvBlobs.write((uint8_t *)&rec, sizeof(rec)); + count++; + } + } + if (oldAdvBlobs) oldAdvBlobs.close(); + if (newAdvBlobs) newAdvBlobs.close(); + _fs->remove("/adv_blobs"); + } + } + if (!_fsExtra->exists("/contacts3")) { + if (_fs->exists("/contacts3")) { + File oldFile = openRead(_fs, "/contacts3"); + File newFile = openWrite(_fsExtra, "/contacts3"); + + if (oldFile && newFile) { + uint8_t buf[64]; + int n; + while ((n = oldFile.read(buf, sizeof(buf))) > 0) { + newFile.write(buf, n); + } + } + if (oldFile) oldFile.close(); + if (newFile) newFile.close(); + _fs->remove("/contacts3"); + } + } + if (!_fsExtra->exists("/channels2")) { + if (_fs->exists("/contacts2")) { + File oldFile = openRead(_fs, "/contacts2"); + File newFile = openWrite(_fsExtra, "/contacts2"); + + if (oldFile && newFile) { + uint8_t buf[64]; + int n; + while ((n = oldFile.read(buf, sizeof(buf))) > 0) { + newFile.write(buf, n); + } + } + if (oldFile) oldFile.close(); + if (newFile) newFile.close(); + _fs->remove("/contacts2"); + } + } + // cleanup nodes which have been testing the extra fs, copy _main.id and new_prefs back to primary + if (_fsExtra->exists("/_main.id")) { + if (_fs->exists("/_main.id")) {_fs->remove("/_main.id");} + File oldFile = openRead(_fsExtra, "/_main.id"); + File newFile = openWrite(_fs, "/_main.id"); + + if (oldFile && newFile) { + uint8_t buf[64]; + int n; + while ((n = oldFile.read(buf, sizeof(buf))) > 0) { + newFile.write(buf, n); + } + } + if (oldFile) oldFile.close(); + if (newFile) newFile.close(); + _fsExtra->remove("/_main.id"); + } + if (_fsExtra->exists("/new_prefs")) { + if (_fs->exists("/new_prefs")) {_fs->remove("/new_prefs");} + File oldFile = openRead(_fsExtra, "/new_prefs"); + File newFile = openWrite(_fs, "/new_prefs"); + + if (oldFile && newFile) { + uint8_t buf[64]; + int n; + while ((n = oldFile.read(buf, sizeof(buf))) > 0) { + newFile.write(buf, n); + } + } + if (oldFile) oldFile.close(); + if (newFile) newFile.close(); + _fsExtra->remove("/new_prefs"); + } + // remove files from where they should not be anymore + if (_fs->exists("/adv_blobs")) { + _fs->remove("/adv_blobs"); + } + if (_fs->exists("/contacts3")) { + _fs->remove("/contacts3"); + } + if (_fsExtra->exists("/_main.id")) { + _fsExtra->remove("/_main.id"); + } + if (_fsExtra->exists("/new_prefs")) { + _fsExtra->remove("/new_prefs"); + } +} + uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) { +#if defined(EXTRAFS) || defined(QSPIFLASH) + File file = _fsExtra->open("/adv_blobs"); +#else File file = _fs->open("/adv_blobs"); +#endif uint8_t len = 0; // 0 = not found if (file) { @@ -378,7 +562,11 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src checkAdvBlobFile(); +#if defined(EXTRAFS) || defined(QSPIFLASH) + File file = _fsExtra->open("/adv_blobs", FILE_O_WRITE); +#else File file = _fs->open("/adv_blobs", FILE_O_WRITE); +#endif if (file) { uint32_t pos = 0, found_pos = 0; uint32_t min_timestamp = 0xFFFFFFFF; diff --git a/examples/companion_radio/DataStore.h b/examples/companion_radio/DataStore.h index 7bd33301..04579bb3 100644 --- a/examples/companion_radio/DataStore.h +++ b/examples/companion_radio/DataStore.h @@ -15,6 +15,7 @@ public: class DataStore { FILESYSTEM* _fs; + FILESYSTEM* _fsExtra; mesh::RTCClock* _clock; IdentityStore identity_store; @@ -25,8 +26,11 @@ class DataStore { public: DataStore(FILESYSTEM& fs, mesh::RTCClock& clock); + DataStore(FILESYSTEM& fs, FILESYSTEM& fsExtra, mesh::RTCClock& clock); void begin(); bool formatFileSystem(); + FILESYSTEM* getPrimaryFS() const { return _fs; } + FILESYSTEM* getSecondaryFS() const { return _fsExtra; } bool loadMainIdentity(mesh::LocalIdentity &identity); bool saveMainIdentity(const mesh::LocalIdentity &identity); void loadPrefs(NodePrefs& prefs, double& node_lat, double& node_lon); @@ -35,10 +39,13 @@ public: void saveContacts(DataStoreHost* host); void loadChannels(DataStoreHost* host); void saveChannels(DataStoreHost* host); + void migrateToSecondaryFS(); uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]); bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len); File openRead(const char* filename); + File openRead(FILESYSTEM* fs, const char* filename); bool removeFile(const char* filename); + bool removeFile(FILESYSTEM* fs, const char* filename); uint32_t getStorageUsedKb() const; uint32_t getStorageTotalKb() const; }; diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 1fa5478b..6d4339b0 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1530,27 +1530,65 @@ void MyMesh::checkCLIRescueCmd() { if(root){ File file = root.openNextFile(); while (file) { - + + #if defined(EXTRAFS) || defined(QSPIFLASH) + if (file.isDirectory()) { + Serial.printf("[dir] /FS1/%s\n", file.name()); + } else { + Serial.printf("[file] /FS1/%s (%d bytes)\n", file.name(), file.size()); + } + #else if (file.isDirectory()) { Serial.printf("[dir] %s\n", file.name()); } else { Serial.printf("[file] %s (%d bytes)\n", file.name(), file.size()); } - + #endif // move to next file file = root.openNextFile(); } root.close(); } + #if defined(EXTRAFS) || defined(QSPIFLASH) + root = _store->openRead(_store->getSecondaryFS(), path); + if(root){ + File file = root.openNextFile(); + while (file) { + + if (file.isDirectory()) { + Serial.printf("[dir] /FS2/%s\n", file.name()); + } else { + Serial.printf("[file] /FS2/%s (%d bytes)\n", file.name(), file.size()); + } + + // move to next file + file = root.openNextFile(); + + } + root.close(); + } + #endif } else if (memcmp(cli_command, "cat", 3) == 0) { // get path from command e.g: "cat /contacts3" const char *path = &cli_command[4]; + // + bool is_fs2 = false; + if (memcmp(path, "FS1/", 4) == 0) { + path += 3; // skip "FS1" + } else if (memcmp(path, "FS2/", 4) == 0) { + path += 3; // skip "FS2" + is_fs2 = true; + } + // log file content as hex File file = _store->openRead(path); + if (is_fs2 == true) { + file = _store->openRead(_store->getSecondaryFS(), path); + } if(file){ // get file content @@ -1570,14 +1608,28 @@ void MyMesh::checkCLIRescueCmd() { // get path from command e.g: "rm /adv_blobs" const char *path = &cli_command[4]; - + MESH_DEBUG_PRINTLN("Removing file: %s", path); // ensure path is not empty, or root dir if(!path || strlen(path) == 0 || strcmp(path, "/") == 0){ Serial.println("Invalid path provided"); } else { + bool is_fs2 = false; + if (memcmp(path, "FS1/", 4) == 0) { + path += 3; // skip "FS1" + } else if (memcmp(path, "FS2/", 4) == 0) { + path += 3; // skip "FS2" + is_fs2 = true; + } // remove file - bool removed = _store->removeFile(path); + bool removed; + if (is_fs2) { + MESH_DEBUG_PRINTLN("Removing file from FS2: %s", path); + removed = _store->removeFile(_store->getSecondaryFS(), path); + } else { + MESH_DEBUG_PRINTLN("Removing file from FS1: %s", path); + removed = _store->removeFile(path); + } if(removed){ Serial.println("File removed"); } else { diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 2dca708d..9651c301 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -16,12 +16,12 @@ static uint32_t _atoi(const char* sp) { #include #if defined(QSPIFLASH) #include - DataStore store(QSPIFlash, rtc_clock); + DataStore store(InternalFS, QSPIFlash, rtc_clock); #else #if defined(EXTRAFS) #include CustomLFS ExtraFS(0xD4000, 0x19000, 128); - DataStore store(ExtraFS, rtc_clock); + DataStore store(InternalFS, ExtraFS, rtc_clock); #else DataStore store(InternalFS, rtc_clock); #endif @@ -129,6 +129,7 @@ void setup() { fast_rng.begin(radio_get_rng_seed()); #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) + InternalFS.begin(); #if defined(QSPIFLASH) if (!QSPIFlash.begin()) { // debug output might not be available at this point, might be too early. maybe should fall back to InternalFS here? @@ -137,10 +138,9 @@ void setup() { MESH_DEBUG_PRINTLN("CustomLFS_QSPIFlash: initialized successfully"); } #else - InternalFS.begin(); - #if defined(EXTRAFS) + #if defined(EXTRAFS) ExtraFS.begin(); - #endif + #endif #endif store.begin(); the_mesh.begin( diff --git a/src/helpers/IdentityStore.h b/src/helpers/IdentityStore.h index 99c2bd77..e022696a 100644 --- a/src/helpers/IdentityStore.h +++ b/src/helpers/IdentityStore.h @@ -4,18 +4,10 @@ #include #define FILESYSTEM fs::FS #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - #if defined(QSPIFLASH) - #include - #define FILESYSTEM CustomLFS_QSPIFlash - #elif defined(EXTRAFS) - #include - #define FILESYSTEM CustomLFS - #else #include #define FILESYSTEM Adafruit_LittleFS using namespace Adafruit_LittleFS_Namespace; - #endif #endif #include From accd1e0a97c5b6725b9d7653bfe084d42322a963 Mon Sep 17 00:00:00 2001 From: taco Date: Mon, 25 Aug 2025 12:41:59 +1000 Subject: [PATCH 46/48] nrf52 targets: increase limits for contacts and channels --- examples/companion_radio/DataStore.cpp | 22 ++++++++++++++-------- examples/companion_radio/main.cpp | 1 - platformio.ini | 2 +- src/helpers/IdentityStore.h | 11 ++++------- variants/heltec_mesh_solar/platformio.ini | 8 ++++---- variants/heltec_t114/platformio.ini | 8 ++++---- variants/ikoka_stick_nrf/platformio.ini | 8 ++++---- variants/lilygo_techo/platformio.ini | 5 +++-- variants/minewsemi_me25ls01/platformio.ini | 8 ++++---- variants/nano_g2_ultra/platformio.ini | 8 ++++---- variants/promicro/platformio.ini | 8 ++++---- variants/rak4631/platformio.ini | 8 ++++---- variants/sensecap_solar/platformio.ini | 8 ++++---- variants/t1000-e/platformio.ini | 4 ++-- variants/thinknode_m1/platformio.ini | 4 ++-- variants/wio-tracker-l1/platformio.ini | 4 ++-- variants/xiao_nrf52/platformio.ini | 8 ++++---- 17 files changed, 64 insertions(+), 61 deletions(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index ca7337bd..a27c4c86 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -63,13 +63,16 @@ void DataStore::begin() { #include #elif defined(RP2040_PLATFORM) #include -#elif defined(NRF52_PLATFORM) - #include +#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) #if defined(QSPIFLASH) #include + #else + #if defined(EXTRAFS) + #include + #else + #include #endif -#elif defined(STM32_PLATFORM) - #include +#endif #endif #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) @@ -471,9 +474,9 @@ void DataStore::migrateToSecondaryFS() { } } if (!_fsExtra->exists("/channels2")) { - if (_fs->exists("/contacts2")) { - File oldFile = openRead(_fs, "/contacts2"); - File newFile = openWrite(_fsExtra, "/contacts2"); + if (_fs->exists("/channels2")) { + File oldFile = openRead(_fs, "/channels2"); + File newFile = openWrite(_fsExtra, "/channels2"); if (oldFile && newFile) { uint8_t buf[64]; @@ -484,7 +487,7 @@ void DataStore::migrateToSecondaryFS() { } if (oldFile) oldFile.close(); if (newFile) newFile.close(); - _fs->remove("/contacts2"); + _fs->remove("/channels2"); } } // cleanup nodes which have been testing the extra fs, copy _main.id and new_prefs back to primary @@ -527,6 +530,9 @@ void DataStore::migrateToSecondaryFS() { if (_fs->exists("/contacts3")) { _fs->remove("/contacts3"); } + if (_fs->exists("/channels2")) { + _fs->remove("/channels2"); + } if (_fsExtra->exists("/_main.id")) { _fsExtra->remove("/_main.id"); } diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 9651c301..89adca59 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -34,7 +34,6 @@ static uint32_t _atoi(const char* sp) { DataStore store(SPIFFS, rtc_clock); #endif - #ifdef ESP32 #ifdef WIFI_SSID #include diff --git a/platformio.ini b/platformio.ini index 5fe46986..c08cd853 100644 --- a/platformio.ini +++ b/platformio.ini @@ -81,7 +81,7 @@ build_flags = ${arduino_base.build_flags} -D EXTRAFS=1 lib_deps = ${arduino_base.lib_deps} - https://github.com/oltaco/CustomLFS + https://github.com/oltaco/CustomLFS @ 0.2 ; ----------------- RP2040 --------------------- diff --git a/src/helpers/IdentityStore.h b/src/helpers/IdentityStore.h index e022696a..d0d7ee45 100644 --- a/src/helpers/IdentityStore.h +++ b/src/helpers/IdentityStore.h @@ -4,10 +4,10 @@ #include #define FILESYSTEM fs::FS #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - #include - #define FILESYSTEM Adafruit_LittleFS + #include + #define FILESYSTEM Adafruit_LittleFS - using namespace Adafruit_LittleFS_Namespace; + using namespace Adafruit_LittleFS_Namespace; #endif #include @@ -18,10 +18,7 @@ public: IdentityStore(FILESYSTEM& fs, const char* dir): _fs(&fs), _dir(dir) { } void begin() { - if (_dir && _dir[0] == '/') { _fs->mkdir(_dir); } - - - } + if (_dir && _dir[0] == '/') { _fs->mkdir(_dir); } } bool load(const char *name, mesh::LocalIdentity& id); bool load(const char *name, mesh::LocalIdentity& id, char display_name[], int max_name_sz); bool save(const char *name, const mesh::LocalIdentity& id); diff --git a/variants/heltec_mesh_solar/platformio.ini b/variants/heltec_mesh_solar/platformio.ini index 9fd3edd5..18c4ac73 100644 --- a/variants/heltec_mesh_solar/platformio.ini +++ b/variants/heltec_mesh_solar/platformio.ini @@ -59,8 +59,8 @@ build_flags = extends = Heltec_mesh_solar build_flags = ${Heltec_mesh_solar.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 @@ -77,8 +77,8 @@ lib_deps = extends = Heltec_mesh_solar build_flags = ${Heltec_mesh_solar.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 ; -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 diff --git a/variants/heltec_t114/platformio.ini b/variants/heltec_t114/platformio.ini index 2cac2eae..7222bb11 100644 --- a/variants/heltec_t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -74,8 +74,8 @@ extends = Heltec_t114 build_flags = ${Heltec_t114.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 @@ -94,8 +94,8 @@ extends = Heltec_t114 build_flags = ${Heltec_t114.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 ; -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 diff --git a/variants/ikoka_stick_nrf/platformio.ini b/variants/ikoka_stick_nrf/platformio.ini index 6e6ae101..1f2bbfe9 100644 --- a/variants/ikoka_stick_nrf/platformio.ini +++ b/variants/ikoka_stick_nrf/platformio.ini @@ -103,8 +103,8 @@ build_src_filter = ${nrf52840_xiao.build_src_filter} extends = ikoka_stick_nrf_baseboard build_flags = ${ikoka_stick_nrf_baseboard.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 -I examples/companion_radio/ui-new @@ -123,8 +123,8 @@ lib_deps = extends = ikoka_stick_nrf_baseboard build_flags = ${ikoka_stick_nrf_baseboard.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -I examples/companion_radio/ui-new ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 diff --git a/variants/lilygo_techo/platformio.ini b/variants/lilygo_techo/platformio.ini index 8a090a4d..91223205 100644 --- a/variants/lilygo_techo/platformio.ini +++ b/variants/lilygo_techo/platformio.ini @@ -82,8 +82,9 @@ build_flags = ${LilyGo_T-Echo.build_flags} -I src/helpers/ui -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D QSPIFLASH=1 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 diff --git a/variants/minewsemi_me25ls01/platformio.ini b/variants/minewsemi_me25ls01/platformio.ini index 3436062f..71887002 100644 --- a/variants/minewsemi_me25ls01/platformio.ini +++ b/variants/minewsemi_me25ls01/platformio.ini @@ -52,8 +52,8 @@ lib_deps = ${nrf52840_me25ls01.lib_deps} extends = me25ls01 build_flags = ${me25ls01.build_flags} -I examples/companion_radio/ui-orig - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 -D MESH_PACKET_LOGGING=1 @@ -149,8 +149,8 @@ lib_deps = ${me25ls01.lib_deps} extends = me25ls01 build_flags = ${me25ls01.build_flags} -I examples/companion_radio/ui-orig - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 ;-D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 -D MESH_PACKET_LOGGING=1 diff --git a/variants/nano_g2_ultra/platformio.ini b/variants/nano_g2_ultra/platformio.ini index e70c353b..163f4311 100644 --- a/variants/nano_g2_ultra/platformio.ini +++ b/variants/nano_g2_ultra/platformio.ini @@ -35,8 +35,8 @@ build_flags = ${Nano_G2_Ultra.build_flags} -I src/helpers/ui -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=0 -D OFFLINE_QUEUE_SIZE=256 @@ -66,8 +66,8 @@ build_flags = ${Nano_G2_Ultra.build_flags} -I src/helpers/ui -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D OFFLINE_QUEUE_SIZE=256 -D DISPLAY_CLASS=SH1106Display -D PIN_BUZZER=4 diff --git a/variants/promicro/platformio.ini b/variants/promicro/platformio.ini index 6b77bdcf..5a70f7ba 100644 --- a/variants/promicro/platformio.ini +++ b/variants/promicro/platformio.ini @@ -88,8 +88,8 @@ lib_deps = ${Faketec.lib_deps} extends = Faketec build_flags = ${Faketec.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=SSD1306Display ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 @@ -106,8 +106,8 @@ lib_deps = ${Faketec.lib_deps} extends = Faketec build_flags = ${Faketec.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index c9091878..7e7d2234 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -70,8 +70,8 @@ build_flags = -D PIN_USER_BTN=9 -D PIN_USER_BTN_ANA=31 -D DISPLAY_CLASS=SSD1306Display - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 ; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 build_src_filter = ${rak4631.build_src_filter} @@ -89,8 +89,8 @@ build_flags = -D PIN_USER_BTN=9 -D PIN_USER_BTN_ANA=31 -D DISPLAY_CLASS=SSD1306Display - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 diff --git a/variants/sensecap_solar/platformio.ini b/variants/sensecap_solar/platformio.ini index bbac5d99..649ace84 100644 --- a/variants/sensecap_solar/platformio.ini +++ b/variants/sensecap_solar/platformio.ini @@ -76,8 +76,8 @@ build_src_filter = ${SenseCap_Solar.build_src_filter} extends = SenseCap_Solar build_flags = ${SenseCap_Solar.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 ; -D BLE_DEBUG_LOGGING=1 @@ -94,8 +94,8 @@ lib_deps = extends = SenseCap_Solar build_flags = ${SenseCap_Solar.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${SenseCap_Solar.build_src_filter} diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index 044fffd8..d7b43cce 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -91,8 +91,8 @@ lib_deps = ${t1000-e.lib_deps} extends = t1000-e build_flags = ${t1000-e.build_flags} -I examples/companion_radio/ui-orig - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 diff --git a/variants/thinknode_m1/platformio.ini b/variants/thinknode_m1/platformio.ini index eadc83ae..a530d259 100644 --- a/variants/thinknode_m1/platformio.ini +++ b/variants/thinknode_m1/platformio.ini @@ -71,8 +71,8 @@ build_flags = ${ThinkNode_M1.build_flags} -I src/helpers/ui -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 -D DISPLAY_ROTATION=4 diff --git a/variants/wio-tracker-l1/platformio.ini b/variants/wio-tracker-l1/platformio.ini index 02f09e5c..87670bd0 100644 --- a/variants/wio-tracker-l1/platformio.ini +++ b/variants/wio-tracker-l1/platformio.ini @@ -79,8 +79,8 @@ lib_deps = ${WioTrackerL1.lib_deps} extends = WioTrackerL1 build_flags = ${WioTrackerL1.build_flags} -I examples/companion_radio/ui-new - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 diff --git a/variants/xiao_nrf52/platformio.ini b/variants/xiao_nrf52/platformio.ini index 3e181672..10807476 100644 --- a/variants/xiao_nrf52/platformio.ini +++ b/variants/xiao_nrf52/platformio.ini @@ -59,8 +59,8 @@ upload_protocol = nrfutil extends = Xiao_nrf52 build_flags = ${Xiao_nrf52.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 -D OFFLINE_QUEUE_SIZE=256 ; -D BLE_DEBUG_LOGGING=1 @@ -78,8 +78,8 @@ lib_deps = extends = Xiao_nrf52 build_flags = ${Xiao_nrf52.build_flags} - -D MAX_CONTACTS=100 - -D MAX_GROUP_CHANNELS=8 + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Xiao_nrf52.build_src_filter} From 3d8355682995ca56be9cd2d6fdc7986f85daf09b Mon Sep 17 00:00:00 2001 From: taco Date: Sat, 6 Sep 2025 14:07:18 +1000 Subject: [PATCH 47/48] refactor: use _getContactsChannelsFS() instead of ifdefs --- examples/companion_radio/DataStore.cpp | 86 ++++++-------------------- examples/companion_radio/DataStore.h | 3 + 2 files changed, 23 insertions(+), 66 deletions(-) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index a27c4c86..7631b905 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -7,7 +7,7 @@ #define MAX_BLOBRECS 20 #endif -DataStore::DataStore(FILESYSTEM& fs, mesh::RTCClock& clock) : _fs(&fs), _clock(&clock), +DataStore::DataStore(FILESYSTEM& fs, mesh::RTCClock& clock) : _fs(&fs), _fsExtra(nullptr), _clock(&clock), #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) identity_store(fs, "") #elif defined(RP2040_PLATFORM) @@ -19,7 +19,6 @@ DataStore::DataStore(FILESYSTEM& fs, mesh::RTCClock& clock) : _fs(&fs), _clock(& } #if defined(EXTRAFS) || defined(QSPIFLASH) - DataStore::DataStore(FILESYSTEM& fs, FILESYSTEM& fsExtra, mesh::RTCClock& clock) : _fs(&fs), _fsExtra(&fsExtra), _clock(&clock), #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) identity_store(fs, "") @@ -66,14 +65,12 @@ void DataStore::begin() { #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) #if defined(QSPIFLASH) #include - #else - #if defined(EXTRAFS) + #elif defined(EXTRAFS) #include #else #include #endif #endif -#endif #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) int _countLfsBlock(void *p, lfs_block_t block){ @@ -98,13 +95,8 @@ uint32_t DataStore::getStorageUsedKb() const { _fs->info(info); return info.usedBytes / 1024; #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) -#if defined(EXTRAFS) || defined(QSPIFLASH) - const lfs_config* config = _fsExtra->_getFS()->cfg; - int usedBlockCount = _getLfsUsedBlockCount(_fsExtra); -#else - const lfs_config* config = _fs->_getFS()->cfg; - int usedBlockCount = _getLfsUsedBlockCount(_fs); -#endif + const lfs_config* config = _getContactsChannelsFS()->_getFS()->cfg; + int usedBlockCount = _getLfsUsedBlockCount(_getContactsChannelsFS()); int usedBytes = config->block_size * usedBlockCount; return usedBytes / 1024; #else @@ -121,11 +113,7 @@ uint32_t DataStore::getStorageTotalKb() const { _fs->info(info); return info.totalBytes / 1024; #elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) -#if defined(EXTRAFS) || defined(QSPIFLASH) - const lfs_config* config = _fsExtra->_getFS()->cfg; -#else - const lfs_config* config = _fs->_getFS()->cfg; -#endif + const lfs_config* config = _getContactsChannelsFS()->_getFS()->cfg; int totalBytes = config->block_size * config->block_count; return totalBytes / 1024; #else @@ -163,11 +151,11 @@ bool DataStore::removeFile(FILESYSTEM* fs, const char* filename) { bool DataStore::formatFileSystem() { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) -#if defined(EXTRAFS) || defined(QSPIFLASH) - return _fs->format() && _fsExtra->format(); // in future maybe return an error code based on which format failed? -#else - return _fs->format(); -#endif + if (_fsExtra == nullptr) { + return _fs->format(); + } else { + return _fs->format() && _fsExtra->format(); + } #elif defined(RP2040_PLATFORM) return LittleFS.format(); #elif defined(ESP32) @@ -262,13 +250,8 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_ void DataStore::loadContacts(DataStoreHost* host) { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) -#if defined(EXTRAFS) || defined(QSPIFLASH) - if (_fsExtra->exists("/contacts3")) { - File file = _fsExtra->open("/contacts3"); -#else - if (_fs->exists("/contacts3")) { - File file = _fs->open("/contacts3"); -#endif + if (_getContactsChannelsFS()->exists("/contacts3")) { + File file = _getContactsChannelsFS()->open("/contacts3"); #elif defined(RP2040_PLATFORM) if (_fs->exists("/contacts3")) { File file = _fs->open("/contacts3", "r"); @@ -307,11 +290,7 @@ void DataStore::loadContacts(DataStoreHost* host) { } void DataStore::saveContacts(DataStoreHost* host) { -#if defined(EXTRAFS) || defined(QSPIFLASH) - File file = openWrite(_fsExtra, "/contacts3"); -#else - File file = openWrite(_fs, "/contacts3"); -#endif + File file = openWrite(_getContactsChannelsFS(), "/contacts3"); if (file) { uint32_t idx = 0; ContactInfo c; @@ -341,13 +320,8 @@ void DataStore::saveContacts(DataStoreHost* host) { void DataStore::loadChannels(DataStoreHost* host) { #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) -#if defined(EXTRAFS) || defined(QSPIFLASH) - if (_fsExtra->exists("/channels2")) { - File file = _fsExtra->open("/channels2"); -#else - if (_fs->exists("/channels2")) { - File file = _fs->open("/channels2"); -#endif + if (_getContactsChannelsFS()->exists("/channels2")) { + File file = _getContactsChannelsFS()->open("/channels2"); #elif defined(RP2040_PLATFORM) if (_fs->exists("/channels2")) { File file = _fs->open("/channels2", "r"); @@ -380,11 +354,7 @@ void DataStore::loadChannels(DataStoreHost* host) { } void DataStore::saveChannels(DataStoreHost* host) { -#if defined(EXTRAFS) || defined(QSPIFLASH) - File file = openWrite(_fsExtra, "/channels2"); -#else - File file = openWrite(_fs, "/channels2"); -#endif + File file = openWrite(_getContactsChannelsFS(), "/channels2"); if (file) { uint8_t channel_idx = 0; ChannelDetails ch; @@ -415,13 +385,8 @@ struct BlobRec { }; void DataStore::checkAdvBlobFile() { -#if defined(EXTRAFS) || defined(QSPIFLASH) - if (!_fsExtra->exists("/adv_blobs")) { - File file = openWrite(_fsExtra, "/adv_blobs"); -#else - if (!_fs->exists("/adv_blobs")) { - File file = openWrite(_fs, "/adv_blobs"); -#endif + if (!_getContactsChannelsFS()->exists("/adv_blobs")) { + File file = openWrite(_getContactsChannelsFS(), "/adv_blobs"); if (file) { BlobRec zeroes; memset(&zeroes, 0, sizeof(zeroes)); @@ -542,13 +507,8 @@ void DataStore::migrateToSecondaryFS() { } uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) { -#if defined(EXTRAFS) || defined(QSPIFLASH) - File file = _fsExtra->open("/adv_blobs"); -#else - File file = _fs->open("/adv_blobs"); -#endif + File file = _getContactsChannelsFS()->open("/adv_blobs"); uint8_t len = 0; // 0 = not found - if (file) { BlobRec tmp; while (file.read((uint8_t *) &tmp, sizeof(tmp)) == sizeof(tmp)) { @@ -565,14 +525,8 @@ uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_b bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len) { if (len < PUB_KEY_SIZE+4+SIGNATURE_SIZE || len > MAX_ADVERT_PKT_LEN) return false; - checkAdvBlobFile(); - -#if defined(EXTRAFS) || defined(QSPIFLASH) - File file = _fsExtra->open("/adv_blobs", FILE_O_WRITE); -#else - File file = _fs->open("/adv_blobs", FILE_O_WRITE); -#endif + File file = _getContactsChannelsFS()->open("/adv_blobs", FILE_O_WRITE); if (file) { uint32_t pos = 0, found_pos = 0; uint32_t min_timestamp = 0xFFFFFFFF; diff --git a/examples/companion_radio/DataStore.h b/examples/companion_radio/DataStore.h index 04579bb3..62580942 100644 --- a/examples/companion_radio/DataStore.h +++ b/examples/companion_radio/DataStore.h @@ -48,4 +48,7 @@ public: bool removeFile(FILESYSTEM* fs, const char* filename); uint32_t getStorageUsedKb() const; uint32_t getStorageTotalKb() const; + +private: + FILESYSTEM* _getContactsChannelsFS() const { if (_fsExtra) return _fsExtra; return _fs;}; }; From bcfc8d37711ec76e1e51a05a34b5026a69a48b2a Mon Sep 17 00:00:00 2001 From: taco Date: Sat, 6 Sep 2025 14:09:05 +1000 Subject: [PATCH 48/48] improved RescueCLI for dual FS --- examples/companion_radio/MyMesh.cpp | 100 ++++++++++++++-------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 6d4339b0..7847d652 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -1524,64 +1524,65 @@ void MyMesh::checkCLIRescueCmd() { // get path from command e.g: "ls /adafruit" const char *path = &cli_command[3]; - + + bool is_fs2 = false; + if (memcmp(path, "UserData/", 9) == 0) { + path += 8; // skip "UserData" + } else if (memcmp(path, "ExtraFS/", 8) == 0) { + path += 7; // skip "ExtraFS" + is_fs2 = true; + } + Serial.printf("Listing files in %s\n", path); + // log each file and directory File root = _store->openRead(path); - if(root){ - File file = root.openNextFile(); - while (file) { - - #if defined(EXTRAFS) || defined(QSPIFLASH) - if (file.isDirectory()) { - Serial.printf("[dir] /FS1/%s\n", file.name()); - } else { - Serial.printf("[file] /FS1/%s (%d bytes)\n", file.name(), file.size()); - } - #else - if (file.isDirectory()) { - Serial.printf("[dir] %s\n", file.name()); - } else { - Serial.printf("[file] %s (%d bytes)\n", file.name(), file.size()); - } - #endif - // move to next file - file = root.openNextFile(); - - } - root.close(); - } - #if defined(EXTRAFS) || defined(QSPIFLASH) - root = _store->openRead(_store->getSecondaryFS(), path); - if(root){ + if (is_fs2 == false) { + if (root) { File file = root.openNextFile(); while (file) { - if (file.isDirectory()) { - Serial.printf("[dir] /FS2/%s\n", file.name()); + Serial.printf("[dir] UserData%s/%s\n", path, file.name()); } else { - Serial.printf("[file] /FS2/%s (%d bytes)\n", file.name(), file.size()); + Serial.printf("[file] UserData%s/%s (%d bytes)\n", path, file.name(), file.size()); } - // move to next file file = root.openNextFile(); - } - root.close(); + root.close(); + } } - #endif + if (is_fs2 == true || strlen(path) == 0 || strcmp(path, "/") == 0) { + if (_store->getSecondaryFS() != nullptr) { + File root2 = _store->openRead(_store->getSecondaryFS(), path); + File file = root2.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.printf("[dir] ExtraFS%s/%s\n", path, file.name()); + } else { + Serial.printf("[file] ExtraFS%s/%s (%d bytes)\n", path, file.name(), file.size()); + } + // move to next file + file = root2.openNextFile(); + } + root2.close(); + } + } } else if (memcmp(cli_command, "cat", 3) == 0) { // get path from command e.g: "cat /contacts3" const char *path = &cli_command[4]; - // bool is_fs2 = false; - if (memcmp(path, "FS1/", 4) == 0) { - path += 3; // skip "FS1" - } else if (memcmp(path, "FS2/", 4) == 0) { - path += 3; // skip "FS2" + if (memcmp(path, "UserData/", 9) == 0) { + path += 8; // skip "UserData" + } else if (memcmp(path, "ExtraFS/", 8) == 0) { + path += 7; // skip "ExtraFS" is_fs2 = true; + } else { + Serial.println("Invalid path provided, must start with UserData/ or ExtraFS/"); + cli_command[0] = 0; + return; } // log file content as hex @@ -1605,29 +1606,28 @@ void MyMesh::checkCLIRescueCmd() { } } else if (memcmp(cli_command, "rm ", 3) == 0) { - // get path from command e.g: "rm /adv_blobs" - const char *path = &cli_command[4]; + const char *path = &cli_command[3]; MESH_DEBUG_PRINTLN("Removing file: %s", path); // ensure path is not empty, or root dir if(!path || strlen(path) == 0 || strcmp(path, "/") == 0){ Serial.println("Invalid path provided"); } else { - bool is_fs2 = false; - if (memcmp(path, "FS1/", 4) == 0) { - path += 3; // skip "FS1" - } else if (memcmp(path, "FS2/", 4) == 0) { - path += 3; // skip "FS2" - is_fs2 = true; - } + bool is_fs2 = false; + if (memcmp(path, "UserData/", 9) == 0) { + path += 8; // skip "UserData" + } else if (memcmp(path, "ExtraFS/", 8) == 0) { + path += 7; // skip "ExtraFS" + is_fs2 = true; + } // remove file bool removed; if (is_fs2) { - MESH_DEBUG_PRINTLN("Removing file from FS2: %s", path); + MESH_DEBUG_PRINTLN("Removing file from ExtraFS: %s", path); removed = _store->removeFile(_store->getSecondaryFS(), path); } else { - MESH_DEBUG_PRINTLN("Removing file from FS1: %s", path); + MESH_DEBUG_PRINTLN("Removing file from UserData: %s", path); removed = _store->removeFile(path); } if(removed){