Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/MeshCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class MainBoard {

// Power management interface (boards with power management override these)
virtual bool isExternalPowered() { return false; }
// True while a board can identify an active battery-charging source.
virtual bool isChargerActive() { return false; }
virtual uint16_t getBootVoltage() { return 0; }
virtual uint32_t getResetReason() const { return 0; }
virtual const char* getResetReasonString(uint32_t reason) { return "Not available"; }
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/CommonCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ 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) {
snprintf(reply, 160, "batt:%u mV ext:%s charger:%s",
(unsigned)_board->getBattMilliVolts(),
_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);
Expand Down
3 changes: 3 additions & 0 deletions variants/thinknode_m6/ThinkNodeM6Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions variants/thinknode_m6/ThinkNodeM6Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ class ThinkNodeM6Board : public NRF52BoardDCDC {
return "Elecrow ThinkNode M6";
}

bool isExternalPowered() override {
if (digitalRead(EXT_PWR_DETECT) == EXT_PWR_DETECT_VALUE ||
digitalRead(EXT_CHRG_DETECT) == EXT_CHRG_DETECT_VALUE) {
return true;
}
return NRF52Board::isExternalPowered();
}

bool isChargerActive() override {
// The charge-status line covers solar input; external USB input is also a
// charging source, although the board cannot report charge completion.
return digitalRead(EXT_CHRG_DETECT) == EXT_CHRG_DETECT_VALUE ||
digitalRead(EXT_PWR_DETECT) == EXT_PWR_DETECT_VALUE;
}

void powerOff() override {

// turn off all leds, sd_power_system_off will not do this for us
Expand Down
6 changes: 6 additions & 0 deletions variants/thinknode_m6/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down