Skip to content
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

Screensaver to black out screen and save battery #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ platformio.ini
lib/readme.txt
.clang_complete
.gcc-flags.json
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
18 changes: 15 additions & 3 deletions src/outset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ void Outset::keypadEvent() {
switch (currentState) {
case TEXT_HISTORY_STATE: {
char key = keypad.getKey();
if (key && key == '{') {
switchToState(TEXT_MESSAGE_STATE, CONFIRM);
if (key) {
lastWakeupEventMills = millis();
digitalWrite(TFT_PWR_EN, LOW); // on
if (key == '{') {
switchToState(TEXT_MESSAGE_STATE, CONFIRM);
}
}
break;
}
Expand All @@ -170,6 +174,8 @@ void Outset::keypadEvent() {

// Scan for keys and draw them on the screen
if (keypad.getKeys()) {
lastWakeupEventMills = millis();
digitalWrite(TFT_PWR_EN, LOW); // on
for (uint8_t i = 0; i < LIST_MAX; i++) {
if (keypad.key[i].stateChanged) {
switch (keypad.key[i].kstate) {
Expand Down Expand Up @@ -407,6 +413,8 @@ void Outset::blinkTextCursor(uint8_t x, uint8_t y) {
}

void Outset::textHistoryState(uint8_t event) {
lastWakeupEventMills = millis();
digitalWrite(TFT_PWR_EN, LOW); // on
drawHeader(currentState);
if (textHistory[0].isEmpty()) {
tft.setCursor(24, 60);
Expand All @@ -415,11 +423,15 @@ void Outset::textHistoryState(uint8_t event) {
else {
drawTextHistory();
}

while (nextState == TEXT_HISTORY_STATE) {
if (millis() > (lastWakeupEventMills + SCREEN_SAVER_TIMEOUT)) {
digitalWrite(TFT_PWR_EN, HIGH); // off
}
keypadEvent();
listenForIncomingMessages();
if (textHistoryNeedsUpdate) {
lastWakeupEventMills = millis();
digitalWrite(TFT_PWR_EN, LOW); // on
drawTextHistory();
textHistoryNeedsUpdate = false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/outset.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Outset {
// The state of the sym key on the keypad. Returns true if pressed else false
bool symPressed;

// Last time a keypress or other event (i.e. new incoming data) happens in order to wake up screen
unsigned long lastWakeupEventMills;

// Used for keeping the debounce state of the trackpad
uint8_t trackpadState;
uint8_t lastTrackpadState;
Expand Down
2 changes: 2 additions & 0 deletions src/states.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
// #define DEVICE_ID ?
#define RF95_FREQ 915.0

#define SCREEN_SAVER_TIMEOUT 5000

#endif