Merge pull request #3202 from F4FPR/m6-power-observability

ThinkNode M6: expose external-power and charger state
This commit is contained in:
fdlamotte
2026-09-26 13:51:11 -04:00
committed by GitHub
5 changed files with 61 additions and 0 deletions
+10
View File
@@ -68,6 +68,16 @@ public:
// Power management interface (boards with power management override these)
virtual bool isPwrMgtInitialised() const { return false; }
virtual bool isExternalPowered() { return false; }
// True while a board can identify an active battery-charging source.
virtual bool isChargerActive() { return false; }
// Optional, source-specific power detection. Boards that can distinguish a USB
// supply from a solar charger override these; defaults keep every other board
// unaffected (the generic CLI prints "n/a" when a capability is absent).
virtual bool hasUsbPowerDetect() const { return false; }
virtual bool isUsbPowered() { return false; }
virtual bool hasSolarChargerDetect() const { return false; }
virtual bool isSolarChargerActive() { return false; }
virtual uint16_t getBootVoltage() { return 0; }
virtual bool getWakeLpcompSupported() const { return false; }
virtual uint32_t getResetReason() const { return 0; }
+13
View File
@@ -284,6 +284,19 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
sprintf(reply, "%s (Build: %s)", _callbacks->getFirmwareVer(), _callbacks->getBuildDate());
} else if (memcmp(command, "board", 5) == 0) {
sprintf(reply, "%s", _board->getManufacturerName());
} else if (strcmp(command, "power") == 0) {
const char* usb_state = _board->hasUsbPowerDetect()
? (_board->isUsbPowered() ? "yes" : "no")
: "n/a";
const char* solar_state = _board->hasSolarChargerDetect()
? (_board->isSolarChargerActive() ? "yes" : "no")
: "n/a";
snprintf(reply, 160, "batt:%u mV usb:%s solar_chg:%s ext:%s charger:%s",
(unsigned)_board->getBattMilliVolts(),
usb_state,
solar_state,
_board->isExternalPowered() ? "yes" : "no",
_board->isChargerActive() ? "yes" : "no");
} else if (memcmp(command, "sensor get ", 11) == 0) {
const char* key = command + 11;
const char* val = _sensors->getSettingByKey(key);
@@ -15,6 +15,9 @@ void ThinkNodeM6Board::begin() {
digitalWrite(P_LORA_TX_LED, LOW);
#endif
pinMode(EXT_PWR_DETECT, INPUT);
pinMode(EXT_CHRG_DETECT, INPUT);
delay(10); // give sx1262 some time to power up
}
+29
View File
@@ -36,6 +36,35 @@ public:
return "Elecrow ThinkNode M6";
}
bool hasUsbPowerDetect() const override { return true; }
bool isUsbPowered() override {
// P0.13 is the dedicated USB / external power-detect line on the M6 PCB
// (same pin the Meshtastic M6 variant uses for USB detection).
return digitalRead(EXT_PWR_DETECT) == EXT_PWR_DETECT_VALUE;
}
bool hasSolarChargerDetect() const override { return true; }
bool isSolarChargerActive() override {
// P0.15 is the active-low solar-charger status line. It reports the
// charger's state, not photovoltaic voltage or current.
return digitalRead(EXT_CHRG_DETECT) == EXT_CHRG_DETECT_VALUE;
}
bool isExternalPowered() override {
if (isUsbPowered() || isSolarChargerActive()) {
return true;
}
return NRF52Board::isExternalPowered();
}
bool isChargerActive() override {
// Preserve a generic charging indication while also exposing both
// source-specific states (USB / solar) separately through the CLI.
return isSolarChargerActive() || isUsbPowered();
}
void powerOff() override {
// turn off all leds, sd_power_system_off will not do this for us
+6
View File
@@ -29,6 +29,12 @@
#define AREF_VOLTAGE (3.0)
// External power and charger status lines.
#define EXT_PWR_DETECT (13)
#define EXT_PWR_DETECT_VALUE HIGH
#define EXT_CHRG_DETECT (15)
#define EXT_CHRG_DETECT_VALUE LOW
////////////////////////////////////////////////////////////////////////////////
// Number of pins