* some fixes around the powerOff(). Tidy ups

This commit is contained in:
Scott Powell
2025-03-14 19:08:41 +11:00
parent 99b376c512
commit 6a4b7463ef
4 changed files with 39 additions and 41 deletions

View File

@@ -26,7 +26,6 @@ static const uint8_t meshcore_logo [] PROGMEM = {
};
void UITask::begin(const char* node_name, const char* build_date, uint32_t pin_code) {
_prevBtnState = HIGH;
_auto_off = millis() + AUTO_OFF_MILLIS;
clearMsgPreview();
_node_name = node_name;
@@ -66,43 +65,43 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
}
void UITask::renderCurrScreen() {
if (_display != NULL) {
char tmp[80];
if (_origin[0] && _msg[0]) {
// render message preview
_display->setCursor(0, 0);
_display->setTextSize(1);
_display->print(_node_name);
if (_display == NULL) return; // assert() ??
_display->setCursor(0, 12);
_display->print(_origin);
_display->setCursor(0, 24);
_display->print(_msg);
char tmp[80];
if (_origin[0] && _msg[0]) {
// render message preview
_display->setCursor(0, 0);
_display->setTextSize(1);
_display->print(_node_name);
_display->setCursor(100, 9);
_display->setCursor(0, 12);
_display->print(_origin);
_display->setCursor(0, 24);
_display->print(_msg);
_display->setCursor(100, 9);
_display->setTextSize(2);
sprintf(tmp, "%d", _msgcount);
_display->print(tmp);
} else {
// render 'home' screen
_display->drawXbm(0, 0, meshcore_logo, 128, 13);
_display->setCursor(0, 20);
_display->setTextSize(1);
_display->print(_node_name);
sprintf(tmp, "Build: %s", _build_date);
_display->setCursor(0, 32);
_display->print(tmp);
if (_connected) {
//_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf);
//_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr);
} else if (_pin_code != 0) {
_display->setTextSize(2);
sprintf(tmp, "%d", _msgcount);
_display->setCursor(0, 43);
sprintf(tmp, "Pin:%d", _pin_code);
_display->print(tmp);
} else {
// render 'home' screen
_display->drawXbm(0, 0, meshcore_logo, 128, 13);
_display->setCursor(0, 20);
_display->setTextSize(1);
_display->print(_node_name);
sprintf(tmp, "Build: %s", _build_date);
_display->setCursor(0, 32);
_display->print(tmp);
if (_connected) {
//_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf);
//_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr);
} else if (_pin_code != 0) {
_display->setTextSize(2);
_display->setCursor(0, 43);
sprintf(tmp, "Pin:%d", _pin_code);
_display->print(tmp);
}
}
}
}
@@ -135,7 +134,7 @@ void UITask::userLedHandler() {
void UITask::buttonHandler() {
#ifdef PIN_USER_BTN
static int prev_btn_state = HIGH;
static int prev_btn_state = !USER_BTN_PRESSED;
static unsigned long btn_state_change_time = 0;
static unsigned long next_read = 0;
int cur_time = millis();
@@ -153,11 +152,10 @@ void UITask::buttonHandler() {
}
} else { // unpressed ? check pressed time ...
if ((cur_time - btn_state_change_time) > 5000) {
Serial.println("power off");
#ifdef PIN_STATUS_LED
#ifdef PIN_STATUS_LED
digitalWrite(PIN_STATUS_LED, LOW);
delay(10);
#endif
#endif
_board->powerOff();
}
}

View File

@@ -7,7 +7,6 @@ class UITask {
DisplayDriver* _display;
mesh::MainBoard* _board;
unsigned long _next_refresh, _auto_off;
int _prevBtnState;
bool _connected;
uint32_t _pin_code;
const char* _node_name;

View File

@@ -40,7 +40,7 @@ public:
virtual void onBeforeTransmit() { }
virtual void onAfterTransmit() { }
virtual void reboot() = 0;
virtual void powerOff() { while (1) { }}; // hope it's overriden or never called ;)
virtual void powerOff() { /* no op */ }
virtual uint8_t getStartupReason() const = 0;
virtual bool startOTAUpdate() { return false; } // not supported
};

View File

@@ -68,7 +68,8 @@ public:
}
void powerOff() override {
enterDeepSleep(0);
// TODO: re-enable this when there is a definite wake-up source pin:
// enterDeepSleep(0);
}
uint16_t getBattMilliVolts() override {