Skip to content

Commit

Permalink
Screen off on idle (saves burn-in)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-Plastix committed Jan 20, 2022
1 parent 0f6a494 commit 2049c7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions main/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define REST_WAIT (30 * 60) // If we still haven't moved in this many seconds, start sending even slower
#define REST_TX_INTERVAL (10 * 60) // Slow resting ping frequency in seconds

#define SCREEN_IDLE_OFF_S (30) // If there are no Uplinks sent for this long, turn the screen off.

#define BATTERY_LOW_VOLTAGE 3.4 // Below this voltage, power off until USB power allows charging

#define LORAWAN_PORT 2 // FPort for Uplink messages -- must match Helium Console Decoder script!
Expand All @@ -48,8 +50,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Deadzone defines a circular area where no map packets will originate.
// Set Radius to zero to disable, or leave it enabled to select center position from menu.
// (Thanks to @Woutch for the name)
#ifndef DEADZONE_LAT
#define DEADZONE_LAT 34.5678
#endif
#ifndef DEADZONE_LON
#define DEADZONE_LON -123.4567
#endif
#define DEADZONE_RADIUS_M 500 // meters

// Uncomment to enable discarding network settings by long pressing second button
Expand Down
36 changes: 28 additions & 8 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ bool axp192_found = false;
bool packetQueued;
bool isJoined = false;

bool screen_stay_on = false;
bool is_screen_on = true;
int screen_idle_off_s = SCREEN_IDLE_OFF_S;
uint32_t screen_last_active_ms = 0;

// Buffer for Payload frame
static uint8_t txBuffer[11];

Expand Down Expand Up @@ -218,7 +223,6 @@ bool trySend() {
}

// send it!

packetQueued = true;
if (!ttn_send(txBuffer, sizeof(txBuffer), LORAWAN_PORT, confirmed)) {
Serial.println("Surprise send failure!");
Expand All @@ -229,6 +233,7 @@ bool trySend() {
last_send_lat = now_lat;
last_send_lon = now_long;

screen_last_active_ms = now;
return true; // We did it!
}

Expand Down Expand Up @@ -672,6 +677,7 @@ void clean_shutdown(void) {
}

void update_activity() {
uint32_t now = millis();
float bat_volts = axp.getBattVoltage() / 1000;
float charge_ma = axp.getBattChargeCurrent();
// float discharge_ma = axp.getBatChargeCurrent();
Expand All @@ -683,10 +689,22 @@ void update_activity() {
clean_shutdown();
}

if (millis() - last_moved_ms > rest_wait_s * 1000)
if (now - last_moved_ms > rest_wait_s * 1000)
tx_interval_s = rest_tx_interval_s;
else
tx_interval_s = stationary_tx_interval_s;

if (now - screen_last_active_ms > screen_idle_off_s * 1000) {
if (is_screen_on) {
is_screen_on = false;
screen_off();
}
} else {
if (!is_screen_on) {
is_screen_on = true;
screen_on();
}
}
}

/* I must know what that interrupt was for! */
Expand Down Expand Up @@ -826,6 +844,9 @@ void menu_deadzone_here(void) {
deadzone_lat = gps_latitude();
deadzone_lon = gps_longitude();
}
void menu_stay_on(void) {
screen_stay_on = !screen_stay_on;
}

dr_t sf_list[] = {DR_SF7, DR_SF8, DR_SF9, DR_SF10};
#define SF_ENTRIES (sizeof(sf_list) / sizeof(sf_list[0]))
Expand All @@ -846,7 +867,7 @@ struct menu_entry menu[] = {
{"Send Now", menu_send_now}, {"Power Off", menu_power_off}, {"Distance +", menu_distance_plus},
{"Distance -", menu_distance_minus}, {"Time +", menu_time_plus}, {"Time -", menu_time_minus},
{"Change SF", menu_change_sf}, {"Flush Prefs", menu_flush_prefs}, {"USB GPS", menu_gps_passthrough},
{"Deadzone Here", menu_deadzone_here}, {"Danger", menu_experiment}};
{"Deadzone Here", menu_deadzone_here}, {"Stay On", menu_stay_on}, {"Danger", menu_experiment}};
#define MENU_ENTRIES (sizeof(menu) / sizeof(menu[0]))

const char *menu_prev;
Expand Down Expand Up @@ -887,12 +908,8 @@ void loop() {

update_activity();

/*
if (packetSent) {
packetSent = false;
} */

// If any interrupts on PMIC, report the name
// PEK button handler
if (axp192_found && pmu_irq) {
const char *irq_name;
pmu_irq = false;
Expand All @@ -908,13 +925,16 @@ void loop() {
screen_print(buffer);
}
axp.clearIRQ();
screen_last_active_ms = millis();
}

// Middle Button handler
static uint32_t pressTime = 0;
if (!digitalRead(MIDDLE_BUTTON_PIN)) {
// Pressure is on
if (!pressTime) { // just started a new press
pressTime = millis();
screen_last_active_ms = pressTime;
is_highlighted = true;
}
} else if (pressTime) {
Expand Down
1 change: 0 additions & 1 deletion main/screen.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <Arduino.h>


void screen_print(const char *text);
void screen_print(const char *text, uint8_t x, uint8_t y);
void screen_print(const char *text, uint8_t x, uint8_t y, uint8_t alignment);
Expand Down

0 comments on commit 2049c7a

Please sign in to comment.