From a0cfea87a1739e220423ab5041af89c3554ef89d Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Thu, 11 Dec 2025 12:46:05 -0600 Subject: [PATCH] More blinkenlights work for Thinknode-m3 --- src/mesh/NodeDB.cpp | 4 +-- src/modules/StatusLEDModule.cpp | 25 +++++++++++++++++-- src/modules/StatusLEDModule.h | 4 ++- .../nrf52840/ELECROW-ThinkNode-M3/variant.h | 1 + 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 192f29553..1552c1ea6 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -805,11 +805,11 @@ void NodeDB::installDefaultModuleConfig() moduleConfig.external_notification.output_ms = 500; moduleConfig.external_notification.nag_timeout = 2; #endif -#if defined(RAK4630) || defined(RAK11310) || defined(RAK3312) || defined(MUZI_BASE) +#if defined(RAK4630) || defined(RAK11310) || defined(RAK3312) || defined(MUZI_BASE) || defined(ELECROW_ThinkNode_M3) // Default to RAK led pin 2 (blue) moduleConfig.external_notification.enabled = true; moduleConfig.external_notification.output = PIN_LED2; -#if defined(MUZI_BASE) +#if defined(MUZI_BASE) || defined(ELECROW_ThinkNode_M3) moduleConfig.external_notification.active = false; #else moduleConfig.external_notification.active = true; diff --git a/src/modules/StatusLEDModule.cpp b/src/modules/StatusLEDModule.cpp index fc9ed310e..04cd7326f 100644 --- a/src/modules/StatusLEDModule.cpp +++ b/src/modules/StatusLEDModule.cpp @@ -26,7 +26,11 @@ int StatusLEDModule::handleStatusUpdate(const meshtastic::Status *arg) power_state = charged; } } else { - power_state = discharging; + if (powerStatus->getBatteryChargePercent() > 5) { + power_state = discharging; + } else { + power_state = critical; + } } break; } @@ -58,16 +62,33 @@ int StatusLEDModule::handleStatusUpdate(const meshtastic::Status *arg) int32_t StatusLEDModule::runOnce() { + my_interval = 1000; if (power_state == charging) { CHARGE_LED_state = !CHARGE_LED_state; } else if (power_state == charged) { CHARGE_LED_state = LED_STATE_ON; + } else if (power_state == critical) { + if (POWER_LED_starttime + 30000 < millis() && !doing_fast_blink) { + doing_fast_blink = true; + POWER_LED_starttime = millis(); + } + if (doing_fast_blink) { + PAIRING_LED_state = LED_STATE_OFF; + CHARGE_LED_state = !CHARGE_LED_state; + my_interval = 250; + if (POWER_LED_starttime + 2000 < millis()) { + doing_fast_blink = false; + } + } else { + CHARGE_LED_state = LED_STATE_OFF; + } + } else { CHARGE_LED_state = LED_STATE_OFF; } - if (!config.bluetooth.enabled || PAIRING_LED_starttime + 30 * 1000 < millis()) { + if (!config.bluetooth.enabled || PAIRING_LED_starttime + 30 * 1000 < millis() || doing_fast_blink) { PAIRING_LED_state = LED_STATE_OFF; } else if (ble_state == unpaired) { if (slowTrack) { diff --git a/src/modules/StatusLEDModule.h b/src/modules/StatusLEDModule.h index d9e3a4f33..d90ff718c 100644 --- a/src/modules/StatusLEDModule.h +++ b/src/modules/StatusLEDModule.h @@ -31,8 +31,10 @@ class StatusLEDModule : private concurrency::OSThread bool PAIRING_LED_state = LED_STATE_OFF; uint32_t PAIRING_LED_starttime = 0; + uint32_t POWER_LED_starttime = 0; + bool doing_fast_blink = false; - enum PowerState { discharging, charging, charged }; + enum PowerState { discharging, charging, charged, critical }; PowerState power_state = discharging; diff --git a/variants/nrf52840/ELECROW-ThinkNode-M3/variant.h b/variants/nrf52840/ELECROW-ThinkNode-M3/variant.h index 2ad3efa27..a27a344d2 100644 --- a/variants/nrf52840/ELECROW-ThinkNode-M3/variant.h +++ b/variants/nrf52840/ELECROW-ThinkNode-M3/variant.h @@ -54,6 +54,7 @@ extern "C" { #define LED_POWER red_LED_PIN #define LED_CHARGE LED_POWER // Signals the Status LED Module to handle this LED #define green_LED_PIN 35 +#define PIN_LED2 green_LED_PIN #define LED_BLUE 37 #define LED_PAIRING LED_BLUE // Signals the Status LED Module to handle this LED