long term sleep with mostly blank screen

This commit is contained in:
Jelmer
2023-02-12 19:44:17 +01:00
parent f50b0bd4ff
commit feb3a7f9ba
8 changed files with 52 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -217,12 +217,16 @@ void mainProtocolLoop(void) {
voltageCheckCounter++;
// check if the battery level is below minimum, and force a redraw of the screen
if ((batteryVoltage < BATTERY_VOLTAGE_MINIMUM && !lowBatteryShown) || (noAPShown)) {
if ((lowBattery && !lowBatteryShown) || (noAPShown)) {
powerUp(INIT_EPD);
// Check if we were already displaying an image
if (curImgSlot != 0xFF) {
powerUp(INIT_EEPROM);
drawImageFromEeprom();
powerDown(INIT_EEPROM);
} else {
showAPFound();
powerDown(INIT_EPD);
}
}
@@ -280,18 +284,28 @@ void mainProtocolLoop(void) {
} else {
// not associated
powerUp(INIT_BASE | INIT_RADIO); // || INIT_GPIO | INIT_UART
if (((scanAttempts != 0) && (scanAttempts % VOLTAGEREADING_DURING_SCAN_INTERVAL == 0)) || (scanAttempts > (INTERVAL_1_ATTEMPTS + INTERVAL_2_ATTEMPTS))) {
powerUp(INIT_BASE | INIT_EPD_VOLTREADING | INIT_RADIO);
} else {
powerUp(INIT_BASE | INIT_RADIO); // || INIT_GPIO | INIT_UART
}
// try to find a working channel
powerUp(INIT_RADIO);
wdt30s();
currentChannel = channelSelect();
powerDown(INIT_RADIO);
if (!currentChannel && !noAPShown) {
if ((!currentChannel && !noAPShown) || (lowBattery && !lowBatteryShown) || (scanAttempts == (INTERVAL_1_ATTEMPTS + INTERVAL_2_ATTEMPTS-1))) {
powerUp(INIT_EPD);
if (curImgSlot != 0xFF) {
powerUp(INIT_EEPROM);
drawImageFromEeprom();
powerDown(INIT_EEPROM);
} else if ((scanAttempts >= (INTERVAL_1_ATTEMPTS + INTERVAL_2_ATTEMPTS-1))) {
showLongTermSleep();
powerDown(INIT_EPD);
} else {
showAPFound();
showNoAP();
powerDown(INIT_EPD);
}
}

View File

@@ -34,6 +34,7 @@ uint8_t __xdata scanAttempts = 0;
int8_t __xdata temperature = 0;
uint16_t __xdata batteryVoltage = 0;
bool __xdata lowBattery = false;
uint16_t __xdata longDataReqCounter = 0;
uint16_t __xdata voltageCheckCounter = 0;
@@ -70,6 +71,11 @@ void powerUp(uint8_t parts) {
if (!(parts & INIT_GPIO))
boardInit();
batteryVoltage = epdGetBattery();
if(batteryVoltage<BATTERY_VOLTAGE_MINIMUM){
lowBattery = true;
} else {
lowBattery = false;
}
}
if (parts & INIT_UART) {

View File

@@ -47,11 +47,12 @@
#define BATTERY_VOLTAGE_MINIMUM 2600 // 2600 or below is the best we can do on the EPD
// power saving when no AP's were found (scanning every X)
#define INTERVAL_1_TIME 3600UL // Try every hour
#define INTERVAL_1_ATTEMPTS 24 // for 24 attempts (an entire day)
#define INTERVAL_2_TIME 7200UL // Try every 2 hours
#define INTERVAL_2_ATTEMPTS 12 // for 12 attempts (an additional day)
#define INTERVAL_3_TIME 86400UL // Finally, try every day
#define VOLTAGEREADING_DURING_SCAN_INTERVAL 2 // how often we should read voltages; this is done every scan attempt in interval bracket 3
#define INTERVAL_1_TIME 3600UL // Try every hour
#define INTERVAL_1_ATTEMPTS 24 // for 24 attempts (an entire day)
#define INTERVAL_2_TIME 7200UL // Try every 2 hours
#define INTERVAL_2_ATTEMPTS 12 // for 12 attempts (an additional day)
#define INTERVAL_3_TIME 86400UL // Finally, try every day
extern void powerUp(uint8_t parts);
extern void powerDown(uint8_t parts);
@@ -71,6 +72,7 @@ extern uint16_t __xdata nextCheckInFromAP;
extern uint8_t __xdata dataReqLastAttempt;
extern int8_t __xdata temperature;
extern uint16_t __xdata batteryVoltage;
extern bool __xdata lowBattery;
extern uint8_t __xdata scanAttempts;
extern uint16_t __xdata longDataReqCounter;
extern uint16_t __xdata voltageCheckCounter;

View File

@@ -49,7 +49,7 @@ void addOverlay() {
if (batteryVoltage != 2600) {
#if (SCREEN_WIDTH != 128)
loadRawBitmap(battery, SCREEN_WIDTH - 16, SCREEN_HEIGHT - 8, EPD_COLOR_BLACK);
loadRawBitmap(battery, SCREEN_WIDTH - 16, SCREEN_HEIGHT - 10, EPD_COLOR_BLACK);
#else
loadRawBitmap(battery, 112, 0, EPD_COLOR_BLACK);
#endif
@@ -298,7 +298,7 @@ void showNoAP() {
selectLUT(EPD_LUT_NO_REPEATS);
setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT);
clearScreen();
#if (SCREEN_WIDTH == 128) // 1.54"
#if (SCREEN_WIDTH == 128) // 2,9"
epdPrintBegin(0, 285, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK);
epdpr("No AP found :(");
epdPrintEnd();
@@ -330,6 +330,23 @@ void showNoAP() {
drawWithSleep();
}
void showLongTermSleep() {
selectLUT(EPD_LUT_NO_REPEATS);
setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT);
clearScreen();
#if (SCREEN_WIDTH == 128) // 2.9"
epdPrintBegin(0, 295, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK);
epdpr("zZ");
epdPrintEnd();
#endif
#if (SCREEN_WIDTH == 152) // 1.54"
epdPrintBegin(1, 136, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK);
epdpr("zZ");
epdPrintEnd();
#endif
addOverlay();
drawWithSleep();
}
void showNoEEPROM() {
selectLUT(EPD_LUT_NO_REPEATS);
clearScreen();

View File

@@ -10,6 +10,7 @@ void showScanningWindow();
void addScanResult(uint8_t channel, uint8_t lqi);
void showAPFound();
void showNoAP();
void showLongTermSleep();
void showNoEEPROM();
void showNoMAC();