Skip to content

Commit

Permalink
CO2 Gadget Beta v0.14.013 low-power
Browse files Browse the repository at this point in the history
Fix: Remove not needed I2C init
Fix: Not updating e-Ink (cyclesToRedrawDisplay for e-Ink)
Fix: Clean mess with cyclesLeftToRedrawDisplay and cyclesToRedrawDisplay
Fix: Clean mess with cyclesLeftToWiFiConnect and cyclesToWiFiConnect
Fix: Stop saving cyclesLeftToRedrawDisplay to preferences
Fix: Stop saving cyclesLeftToWiFiConnect to preferences
  • Loading branch information
melkati committed Jun 30, 2024
1 parent 068cee7 commit feaca42
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 55 deletions.
84 changes: 51 additions & 33 deletions CO2_Gadget_DeepSleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,43 +186,43 @@ void printResetReason() {

void printRTCMemoryEnter() {
#ifdef DEEP_SLEEP_DEBUG2
Serial.println("-->[DEEP][ENTER] lowPowerMode: " + String(deepSleepData.lowPowerMode));
Serial.println("-->[DEEP][ENTER] co2Sensor: " + String(deepSleepData.co2Sensor));
Serial.println("-->[DEEP][ENTER] waitToGoDeepSleepOn1stBoot: " + String(deepSleepData.waitToGoDeepSleepOn1stBoot));
Serial.println("-->[DEEP][ENTER] timeSleeping: " + String(deepSleepData.timeSleeping));
Serial.println("-->[DEEP][ENTER] gpioConfig: " + String(deepSleepData.gpioConfig));
Serial.println("-->[DEEP][ENTER] waitingForDataReady: " + String(deepSleepData.waitingForDataReady));
Serial.println("-->[DEEP][ENTER] cyclesToWiFiConnect: " + String(deepSleepData.cyclesLeftToWiFiConnect));
Serial.println("-->[DEEP][ENTER] redrawDisplayEveryCycles: " + String(deepSleepData.cyclesLeftToRedrawDisplay));
Serial.println("-->[DEEP][ENTER] lastCO2Value: " + String(deepSleepData.lastCO2Value));
Serial.println("-->[DEEP][ENTER] lastTemperatureValue: " + String(deepSleepData.lastTemperatureValue));
Serial.println("-->[DEEP][ENTER] lastHumidityValue: " + String(deepSleepData.lastHumidityValue));
Serial.println("-->[DEEP][ENTER] activeBLEOnWake: " + String(deepSleepData.activeBLEOnWake));
Serial.println("-->[DEEP][ENTER] activeWifiOnWake: " + String(deepSleepData.activeWifiOnWake));
Serial.println("-->[DEEP][ENTER] sendMQTTOnWake: " + String(deepSleepData.sendMQTTOnWake));
Serial.println("-->[DEEP][ENTER] sendESPNowOnWake: " + String(deepSleepData.sendESPNowOnWake));
Serial.println("-->[DEEP][ENTER] displayOnWake: " + String(deepSleepData.displayOnWake));
Serial.println("-->[DEEP][ENTER DeepSleep] lowPowerMode: " + String(deepSleepData.lowPowerMode));
Serial.println("-->[DEEP][ENTER DeepSleep] co2Sensor: " + String(deepSleepData.co2Sensor));
Serial.println("-->[DEEP][ENTER DeepSleep] waitToGoDeepSleepOn1stBoot: " + String(deepSleepData.waitToGoDeepSleepOn1stBoot));
Serial.println("-->[DEEP][ENTER DeepSleep] timeSleeping: " + String(deepSleepData.timeSleeping));
Serial.println("-->[DEEP][ENTER DeepSleep] gpioConfig: " + String(deepSleepData.gpioConfig));
Serial.println("-->[DEEP][ENTER DeepSleep] waitingForDataReady: " + String(deepSleepData.waitingForDataReady));
Serial.println("-->[DEEP][ENTER DeepSleep] cyclesLeftToWiFiConnect: " + String(deepSleepData.cyclesLeftToWiFiConnect));
Serial.println("-->[DEEP][ENTER DeepSleep] cyclesLeftToRedrawDisplay: " + String(deepSleepData.cyclesLeftToRedrawDisplay));
Serial.println("-->[DEEP][ENTER DeepSleep] lastCO2Value: " + String(deepSleepData.lastCO2Value));
Serial.println("-->[DEEP][ENTER DeepSleep] lastTemperatureValue: " + String(deepSleepData.lastTemperatureValue));
Serial.println("-->[DEEP][ENTER DeepSleep] lastHumidityValue: " + String(deepSleepData.lastHumidityValue));
Serial.println("-->[DEEP][ENTER DeepSleep] activeBLEOnWake: " + String(deepSleepData.activeBLEOnWake));
Serial.println("-->[DEEP][ENTER DeepSleep] activeWifiOnWake: " + String(deepSleepData.activeWifiOnWake));
Serial.println("-->[DEEP][ENTER DeepSleep] sendMQTTOnWake: " + String(deepSleepData.sendMQTTOnWake));
Serial.println("-->[DEEP][ENTER DeepSleep] sendESPNowOnWake: " + String(deepSleepData.sendESPNowOnWake));
Serial.println("-->[DEEP][ENTER DeepSleep] displayOnWake: " + String(deepSleepData.displayOnWake));
#endif
}

void printRTCMemoryExit() {
#ifdef DEEP_SLEEP_DEBUG2
Serial.println("-->[DEEP][EXIT] lowPowerMode: " + String(deepSleepData.lowPowerMode));
Serial.println("-->[DEEP][EXIT] co2Sensor: " + String(deepSleepData.co2Sensor));
Serial.println("-->[DEEP][EXIT] waitToGoDeepSleepOn1stBoot: " + String(deepSleepData.waitToGoDeepSleepOn1stBoot));
Serial.println("-->[DEEP][EXIT] timeSleeping: " + String(deepSleepData.timeSleeping));
Serial.println("-->[DEEP][EXIT] gpioConfig: " + String(deepSleepData.gpioConfig));
Serial.println("-->[DEEP][EXIT] waitingForDataReady: " + String(deepSleepData.waitingForDataReady));
Serial.println("-->[DEEP][EXIT] cyclesToWiFiConnect: " + String(deepSleepData.cyclesLeftToWiFiConnect));
Serial.println("-->[DEEP][EXIT] redrawDisplayEveryCycles: " + String(deepSleepData.cyclesLeftToRedrawDisplay));
Serial.println("-->[DEEP][EXIT] lastCO2Value: " + String(deepSleepData.lastCO2Value));
Serial.println("-->[DEEP][EXIT] lastTemperatureValue: " + String(deepSleepData.lastTemperatureValue));
Serial.println("-->[DEEP][EXIT] lastHumidityValue: " + String(deepSleepData.lastHumidityValue));
Serial.println("-->[DEEP][EXIT] activeBLEOnWake: " + String(deepSleepData.activeBLEOnWake));
Serial.println("-->[DEEP][EXIT] activeWifiOnWake: " + String(deepSleepData.activeWifiOnWake));
Serial.println("-->[DEEP][EXIT] sendMQTTOnWake: " + String(deepSleepData.sendMQTTOnWake));
Serial.println("-->[DEEP][EXIT] sendESPNowOnWake: " + String(deepSleepData.sendESPNowOnWake));
Serial.println("-->[DEEP][EXIT] displayOnWake: " + String(deepSleepData.displayOnWake));
Serial.println("-->[DEEP][EXIT DeepSleep] lowPowerMode: " + String(deepSleepData.lowPowerMode));
Serial.println("-->[DEEP][EXIT DeepSleep] co2Sensor: " + String(deepSleepData.co2Sensor));
Serial.println("-->[DEEP][EXIT DeepSleep] waitToGoDeepSleepOn1stBoot: " + String(deepSleepData.waitToGoDeepSleepOn1stBoot));
Serial.println("-->[DEEP][EXIT DeepSleep] timeSleeping: " + String(deepSleepData.timeSleeping));
Serial.println("-->[DEEP][EXIT DeepSleep] gpioConfig: " + String(deepSleepData.gpioConfig));
Serial.println("-->[DEEP][EXIT DeepSleep] waitingForDataReady: " + String(deepSleepData.waitingForDataReady));
Serial.println("-->[DEEP][EXIT DeepSleep] cyclesLeftToWiFiConnect: " + String(deepSleepData.cyclesLeftToWiFiConnect));
Serial.println("-->[DEEP][EXIT DeepSleep] cyclesLeftToRedrawDisplay: " + String(deepSleepData.cyclesLeftToRedrawDisplay));
Serial.println("-->[DEEP][EXIT DeepSleep] lastCO2Value: " + String(deepSleepData.lastCO2Value));
Serial.println("-->[DEEP][EXIT DeepSleep] lastTemperatureValue: " + String(deepSleepData.lastTemperatureValue));
Serial.println("-->[DEEP][EXIT DeepSleep] lastHumidityValue: " + String(deepSleepData.lastHumidityValue));
Serial.println("-->[DEEP][EXIT DeepSleep] activeBLEOnWake: " + String(deepSleepData.activeBLEOnWake));
Serial.println("-->[DEEP][EXIT DeepSleep] activeWifiOnWake: " + String(deepSleepData.activeWifiOnWake));
Serial.println("-->[DEEP][EXIT DeepSleep] sendMQTTOnWake: " + String(deepSleepData.sendMQTTOnWake));
Serial.println("-->[DEEP][EXIT DeepSleep] sendESPNowOnWake: " + String(deepSleepData.sendESPNowOnWake));
Serial.println("-->[DEEP][EXIT DeepSleep] displayOnWake: " + String(deepSleepData.displayOnWake));
#endif
}

Expand Down Expand Up @@ -623,13 +623,15 @@ bool handleLowPowerSensors() {
void fromDeepSleepTimer() {
--deepSleepData.cyclesLeftToWiFiConnect;
--deepSleepData.cyclesLeftToRedrawDisplay;
if (deepSleepData.cyclesLeftToWiFiConnect == 65535) deepSleepData.cyclesLeftToWiFiConnect = 0;
if (deepSleepData.cyclesLeftToRedrawDisplay == 65535) deepSleepData.cyclesLeftToRedrawDisplay = 0;

#if defined(DEEP_SLEEP_DEBUG)
Serial.println("-->[DEEP] Cycles left to connect to WiFi: " + String(deepSleepData.cyclesLeftToWiFiConnect));
#endif

#if defined(DEEP_SLEEP_DEBUG) && defined(SUPPORT_EINK)
Serial.println("-->[DEEP] Cycles left to redraw display: " + String(deepSleepData.cyclesLeftToRedrawDisplay));
Serial.println("-->[DEEP] Cycles left to redraw E-Ink display: " + String(deepSleepData.cyclesLeftToRedrawDisplay));
#endif

switch (deepSleepData.lowPowerMode) {
Expand Down Expand Up @@ -678,7 +680,23 @@ void fromDeepSleepTimer() {
timerLightSleep.pause();
#endif
}
#endif // defined(SUPPORT_TFT) || defined(SUPPORT_OLED)
#ifdef SUPPORT_EINK
if (deepSleepData.cyclesLeftToRedrawDisplay == 0) {
#ifdef DEEP_SLEEP_DEBUG
Serial.println("-->[DEEP] Updating e-ink display");
#endif
initPreferences();
initDisplay(true);
displayShowValues(true);
}
#ifdef TIMEDEBUG
timerLightSleep.resume();
#endif
#ifdef TIMEDEBUG
timerLightSleep.pause();
#endif
#endif // SUPPORT_EINK
if (deepSleepData.cyclesLeftToWiFiConnect == 0) {
doDeepSleepWiFiConnect();
}
Expand Down
11 changes: 4 additions & 7 deletions CO2_Gadget_EINK.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#define RESETDURATION 2 // Default reset duration in seconds for WaveShare displays with clever reset circuit
#endif

uint16_t redrawDisplayEveryCycles = 10; // Redraw display every X partial updates
uint16_t cyclesLeftToRedrawDisplay = 0; // Cycles left to redraw display

#if defined(EINKBOARDDEPG0213BN) || defined(EINKBOARDGDEM0213B74) || defined(EINKBOARDGDEW0213M21)

#include "bootlogo.h"
Expand Down Expand Up @@ -708,7 +705,7 @@ void displayShowValues(bool forceRedraw = false) {
Serial.println("-->[EINK] Cycles left to full refresh of display: " + String(cyclesLeftToRedrawDisplay));
#endif
} else {
cyclesLeftToRedrawDisplay = redrawDisplayEveryCycles;
deepSleepData.cyclesLeftToRedrawDisplay = deepSleepData.redrawDisplayEveryCycles;
forceRedraw = true;
#ifdef DEBUG_EINK
Serial.println("-->[EINK] Forcing full refresh of display");
Expand Down Expand Up @@ -771,13 +768,13 @@ void displayShowValues(bool forceRedraw = false) {
timer.start();
#endif

if (cyclesLeftToRedrawDisplay > 0) {
cyclesLeftToRedrawDisplay--;
if (deepSleepData.cyclesLeftToRedrawDisplay > 0) {
deepSleepData.cyclesLeftToRedrawDisplay--;
#ifdef DEBUG_EINK
Serial.println("-->[EINK] Cycles left to full refresh of display: " + String(cyclesLeftToRedrawDisplay));
#endif
} else {
cyclesLeftToRedrawDisplay = redrawDisplayEveryCycles;
deepSleepData.cyclesLeftToRedrawDisplay = deepSleepData.redrawDisplayEveryCycles;
forceRedraw = true;
#ifdef DEBUG_EINK
Serial.println("-->[EINK] Forcing full refresh of display");
Expand Down
26 changes: 12 additions & 14 deletions CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ void printActualSettings() {
Serial.printf("-->[PREF] lowPowerMode is:\t#%d#\n", deepSleepData.lowPowerMode);
Serial.printf("-->[PREF] waitToDeep is:\t#%d#\n", deepSleepData.waitToGoDeepSleepOn1stBoot);
Serial.printf("-->[PREF] timeSleeping is:\t#%d#\n", deepSleepData.timeSleeping);
Serial.printf("-->[PREF] cyclsWifiConn is:\t#%d#\n", deepSleepData.cyclesLeftToWiFiConnect);
Serial.printf("-->[PREF] cycRedrawDis is:\t#%d#\n", deepSleepData.cyclesLeftToRedrawDisplay);
Serial.printf("-->[PREF] cyclsWifiConn is:\t#%d#\n", deepSleepData.activateWiFiEvery);
Serial.printf("-->[PREF] cycRedrawDis is:\t#%d#\n", deepSleepData.redrawDisplayEveryCycles);
Serial.printf("-->[PREF] actBLEOnWake is:\t#%s#\n",
((deepSleepData.activeBLEOnWake) ? "Enabled" : "Disabled"));
Serial.printf("-->[PREF] actWifiOnWake is:\t#%s#\n",
Expand Down Expand Up @@ -371,10 +371,8 @@ void initPreferences() {
deepSleepData.lowPowerMode = preferences.getUInt("lowPowerMode", 0);
deepSleepData.waitToGoDeepSleepOn1stBoot = preferences.getUInt("waitToDeep", 60);
deepSleepData.timeSleeping = preferences.getUInt("timeSleeping", 60);
deepSleepData.cyclesLeftToWiFiConnect = preferences.getUInt("cyclsWifiConn", 5);
deepSleepData.activateWiFiEvery = deepSleepData.cyclesLeftToWiFiConnect;
// deepSleepData.cyclesLeftToRedrawDisplay = preferences.getUInt("cycRedrawDis", 5);
deepSleepData.redrawDisplayEveryCycles = deepSleepData.cyclesLeftToRedrawDisplay;
deepSleepData.activateWiFiEvery = preferences.getUInt("cyclsWifiConn", 5);
deepSleepData.redrawDisplayEveryCycles = preferences.getUInt("cycRedrawDis", 5);
deepSleepData.activeBLEOnWake = preferences.getBool("actBLEOnWake", true);
deepSleepData.activeWifiOnWake = preferences.getBool("actWifiOnWake", false);
deepSleepData.sendMQTTOnWake = preferences.getBool("actMQTTOnWake", false);
Expand Down Expand Up @@ -507,8 +505,8 @@ void putPreferences() {
preferences.putUInt("lowPowerMode", deepSleepData.lowPowerMode);
preferences.putUInt("waitToDeep", deepSleepData.waitToGoDeepSleepOn1stBoot);
preferences.putUInt("timeSleeping", deepSleepData.timeSleeping);
preferences.putUInt("cyclsWifiConn", deepSleepData.cyclesLeftToWiFiConnect);
preferences.putUInt("cycRedrawDis", deepSleepData.cyclesLeftToRedrawDisplay);
preferences.putUInt("cyclsWifiConn", deepSleepData.activateWiFiEvery);
preferences.putUInt("cycRedrawDis", deepSleepData.redrawDisplayEveryCycles);
preferences.putBool("actBLEOnWake", deepSleepData.activeBLEOnWake);
preferences.putBool("actWifiOnWake", deepSleepData.activeWifiOnWake);
preferences.putBool("actMQTTOnWake", deepSleepData.sendMQTTOnWake);
Expand Down Expand Up @@ -641,8 +639,8 @@ String getActualSettingsAsJson(bool includePasswords = false) {
doc["lowPowerMode"] = deepSleepData.lowPowerMode;
doc["waitToDeep"] = deepSleepData.waitToGoDeepSleepOn1stBoot;
doc["timeSleeping"] = deepSleepData.timeSleeping;
doc["cyclsWifiConn"] = deepSleepData.cyclesLeftToWiFiConnect;
doc["cycRedrawDis"] = deepSleepData.cyclesLeftToRedrawDisplay;
doc["cyclsWifiConn"] = deepSleepData.activateWiFiEvery;
doc["cycRedrawDis"] = deepSleepData.redrawDisplayEveryCycles;
doc["actBLEOnWake"] = deepSleepData.activeBLEOnWake;
doc["actWifiOnWake"] = deepSleepData.activeWifiOnWake;
doc["actMQTTOnWake"] = deepSleepData.sendMQTTOnWake;
Expand Down Expand Up @@ -942,11 +940,11 @@ bool handleSavePreferencesFromJSON(String jsonPreferences) {
deepSleepData.timeSleeping = JsonDocument["timeSleeping"];
}
if (JsonDocument.containsKey("cyclsWifiConn")) {
deepSleepData.cyclesLeftToWiFiConnect = JsonDocument["cyclsWifiConn"];
deepSleepData.activateWiFiEvery = JsonDocument["cyclsWifiConn"];
}
if (JsonDocument.containsKey("cycRedrawDis")) {
deepSleepData.redrawDisplayEveryCycles = JsonDocument["cycRedrawDis"];
}
// if (JsonDocument.containsKey("cycRedrawDis")) {
// deepSleepData.cyclesLeftToRedrawDisplay = JsonDocument["cycRedrawDis"];
// }
if (JsonDocument.containsKey("actBLEOnWake")) {
deepSleepData.activeBLEOnWake = JsonDocument["actBLEOnWake"];
}
Expand Down
1 change: 1 addition & 0 deletions CO2_Gadget_Sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void storeSensorSelectedInRTC() {
}

void initSCD30SensorLowPower() {
return;
#ifndef Wire1
if (!sensors.scd30.begin()) return;
#else
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extra_configs = platformio_extra_configs.ini
[version]
build_flags =
-D CO2_GADGET_VERSION="\"0.14."\"
-D CO2_GADGET_REV="\"012-development-low-power"\"
-D CO2_GADGET_REV="\"013-development-low-power"\"

;****************************************************************************************
;*** You can disable features by commenting the line with a semicolon at the beginning
Expand Down

0 comments on commit feaca42

Please sign in to comment.