-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
WIP repeater: poweroff on long press #2883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fdlamotte
wants to merge
1
commit into
meshcore-dev:dev
Choose a base branch
from
fdlamotte:repeater_btn
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−19
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #include "UITask.h" | ||
| #include "target.h" | ||
| #include <Arduino.h> | ||
| #include <helpers/CommonCLI.h> | ||
|
|
||
|
|
@@ -9,6 +10,8 @@ | |
| #define AUTO_OFF_MILLIS 20000 // 20 seconds | ||
| #define BOOT_SCREEN_MILLIS 4000 // 4 seconds | ||
|
|
||
| #define POWEROFF_DELAY 3000 | ||
|
|
||
| // 'meshcore', 128x13px | ||
| static const uint8_t meshcore_logo [] PROGMEM = { | ||
| 0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, | ||
|
|
@@ -32,6 +35,10 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi | |
| _node_prefs = node_prefs; | ||
| _display->turnOn(); | ||
|
|
||
| #if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) | ||
| user_btn.begin(); | ||
| #endif | ||
|
|
||
| // strip off dash and commit hash by changing dash to null terminator | ||
| // e.g: v1.2.3-abcdef -> v1.2.3 | ||
| char *version = strdup(firmware_version); | ||
|
|
@@ -73,8 +80,26 @@ void UITask::renderCurrScreen() { | |
| uint16_t typeWidth = _display->getTextWidth(node_type); | ||
| _display->setCursor((_display->width() - typeWidth) / 2, 48); | ||
| _display->print(node_type); | ||
| } else { // home screen | ||
| // node name | ||
| } else if (_powering_off_at > 0) { | ||
| // meshcore logo | ||
| _display->setColor(DisplayDriver::BLUE); | ||
| int logoWidth = 128; | ||
| _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); | ||
|
|
||
| // meshcore website | ||
| const char* website = "https://meshcore.io"; | ||
| _display->setColor(DisplayDriver::LIGHT); | ||
| _display->setTextSize(1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have drawTextCentered() as shorthand for this |
||
| uint16_t websiteWidth = _display->getTextWidth(website); | ||
| _display->setCursor((_display->width() - websiteWidth) / 2, 22); | ||
| _display->print(website); | ||
|
|
||
| // Powering off | ||
| const char* poweroff_string = "Turning OFF"; | ||
| uint16_t poffWidth = _display->getTextWidth(poweroff_string); | ||
| _display->setCursor((_display->width() - poffWidth) / 2, 48); | ||
| _display->print(poweroff_string); | ||
| } else { | ||
| _display->setCursor(0, 0); | ||
| _display->setTextSize(1); | ||
| _display->setColor(DisplayDriver::GREEN); | ||
|
|
@@ -94,21 +119,19 @@ void UITask::renderCurrScreen() { | |
| } | ||
|
|
||
| void UITask::loop() { | ||
| #ifdef PIN_USER_BTN | ||
| if (millis() >= _next_read) { | ||
| int btnState = digitalRead(PIN_USER_BTN); | ||
| if (btnState != _prevBtnState) { | ||
| if (btnState == USER_BTN_PRESSED) { // pressed? | ||
| if (_display->isOn()) { | ||
| // TODO: any action ? | ||
| } else { | ||
| _display->turnOn(); | ||
| } | ||
| _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer | ||
| } | ||
| _prevBtnState = btnState; | ||
| #if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) | ||
| int ev = user_btn.check(); | ||
| if (ev == BUTTON_EVENT_CLICK) { | ||
| if (_display->isOn()) { | ||
| // TODO: any action ? | ||
| } else { | ||
| _display->turnOn(); | ||
| } | ||
| _next_read = millis() + 200; // 5 reads per second | ||
| _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer | ||
| } else if (ev == BUTTON_EVENT_LONG_PRESS) { | ||
| _display->turnOn(); | ||
| Serial.println("Powering Off"); | ||
| _powering_off_at = millis() + POWEROFF_DELAY; | ||
| } | ||
| #endif | ||
|
|
||
|
|
@@ -124,4 +147,15 @@ void UITask::loop() { | |
| _display->turnOff(); | ||
| } | ||
| } | ||
|
|
||
| if (_powering_off_at > 0) { // power off timer armed | ||
| #ifdef LED_PIN | ||
| digitalWrite(LED_PIN, LED_STATE_ON); // switch on the led until poweroff | ||
| #endif | ||
| if (millis() > _powering_off_at) { | ||
| _display->turnOff(); | ||
| radio_driver.powerOff(); | ||
| _board->powerOff(); // should not return | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to remove this ...
was added by pio ... should probably add this file to .gitignore ...