From 6a4b7463ef79058fe4e5248cfff39595b5ea5f6d Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 14 Mar 2025 19:08:41 +1100 Subject: [PATCH] * some fixes around the powerOff(). Tidy ups --- examples/companion_radio/UITask.cpp | 74 ++++++++++++++--------------- examples/companion_radio/UITask.h | 1 - src/MeshCore.h | 2 +- src/helpers/HeltecV3Board.h | 3 +- 4 files changed, 39 insertions(+), 41 deletions(-) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index df09e269..b454d939 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -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(); } } diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index fa645324..4cea0b8d 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -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; diff --git a/src/MeshCore.h b/src/MeshCore.h index 5f9956a3..9593877d 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -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 }; diff --git a/src/helpers/HeltecV3Board.h b/src/helpers/HeltecV3Board.h index c61189f2..88e49970 100644 --- a/src/helpers/HeltecV3Board.h +++ b/src/helpers/HeltecV3Board.h @@ -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 {