Skip to content

Commit

Permalink
Fixes to merge #228
Browse files Browse the repository at this point in the history
  • Loading branch information
melkati committed Jun 10, 2024
1 parent 538b16d commit 38e9ec8
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 88 deletions.
17 changes: 9 additions & 8 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ bool menuInitialized = false;
uint16_t DisplayBrightness = 100;
bool displayReverse = false;
bool showFahrenheit = false;
bool displayShowTemperature = true;
bool displayShowHumidity = true;
bool displayShowBattery = true;
bool displayShowBatteryVoltage = false;
bool displayShowCO2 = true;
bool displayShowPM25 = true;
volatile bool displayShowTemperature = true;
volatile bool displayShowHumidity = true;
volatile bool displayShowBattery = true;
volatile bool displayShowBatteryVoltage = false;
volatile bool displayShowCO2 = true;
volatile bool displayShowPM25 = true;
bool debugSensors = false;
bool inMenu = false;
bool shouldWakeUpDisplay = false;
bool shouldRedrawDisplay = false;
volatile bool shouldWakeUpDisplay = false;
volatile bool shouldRedrawDisplay = false;
volatile bool redrawDisplayOnNextLoop = false;
bool isMenuDirty = false; // To know if we need to redraw the menu
uint16_t measurementInterval = 10;
uint16_t sampleInterval = 60;
Expand Down
8 changes: 8 additions & 0 deletions CO2_Gadget_EINK.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@ void testRedrawValues(bool randomNumbers = false) {
void displayShowValues(bool forceRedraw = false) {
static uint32_t lastDisplayUpdate = 0;
if (isDownloadingBLE) return; // Do not update display while downloading BLE data to MyAmbiance
if (redrawDisplayOnNextLoop) {
shouldRedrawDisplay = true;
redrawDisplayOnNextLoop = false;
}
if (shouldRedrawDisplay) {
forceRedraw = true;
shouldRedrawDisplay = false;
Expand Down Expand Up @@ -743,6 +747,10 @@ void displayShowValues(bool forceRedraw = false) {
void displayShowValues(bool forceRedraw = false) {
static uint32_t lastDisplayUpdate = 0;
if (isDownloadingBLE) return; // Do not update display while downloading BLE data to MyAmbiance
if (redrawDisplayOnNextLoop) {
shouldRedrawDisplay = true;
redrawDisplayOnNextLoop = false;
}
if (shouldRedrawDisplay) {
forceRedraw = true;
shouldRedrawDisplay = false;
Expand Down
49 changes: 21 additions & 28 deletions CO2_Gadget_Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ MENU(temperatureConfigMenu, "Temp Config", doNothing, noEvent, wrapStyle
TOGGLE(displayOffOnExternalPower, activeDisplayOffMenuOnBattery, "Off on USB: ", doNothing,noEvent, wrapStyle
,VALUE("ON", true, doNothing, noEvent)
,VALUE("OFF", false, doNothing, noEvent));


result doDisplayReverse(eventMask e, navNode &nav, prompt &item) {
#ifdef DEBUG_ARDUINOMENU
Expand Down Expand Up @@ -664,29 +663,28 @@ result doDisplayReverse(eventMask e, navNode &nav, prompt &item) {
}

TOGGLE(displayReverse, activeDisplayReverse, "Orient: ", doNothing, noEvent, wrapStyle
,VALUE("Normal", false, doDisplayReverse, enterEvent)
,VALUE("Reversed", true, doDisplayReverse, enterEvent));

,VALUE("Normal", false, doDisplayReverse, enterEvent)
,VALUE("Reversed", true, doDisplayReverse, enterEvent));

TOGGLE(displayShowTemperature, activeDisplayShowTemperature, "Temp: ", doNothing, noEvent, wrapStyle
,VALUE("Hide", false, doDisplayReverse, enterEvent)
,VALUE("Show", true, doDisplayReverse, enterEvent));
,VALUE("Hide", false, doNothing, enterEvent)
,VALUE("Show", true, doNothing, enterEvent));

TOGGLE(displayShowHumidity, activeDisplayShowHumidity, "Humidity: ", doNothing, noEvent, wrapStyle
,VALUE("Hide", false, doDisplayReverse, enterEvent)
,VALUE("Show", true, doDisplayReverse, enterEvent));
,VALUE("Hide", false, doNothing, enterEvent)
,VALUE("Show", true, doNothing, enterEvent));

TOGGLE(displayShowBattery, activeDisplayShowBattery, "Battery: ", doNothing, noEvent, wrapStyle
,VALUE("Hide", false, doDisplayReverse, enterEvent)
,VALUE("Show", true, doDisplayReverse, enterEvent));
,VALUE("Hide", false, doNothing, enterEvent)
,VALUE("Show", true, doNothing, enterEvent));

TOGGLE(displayShowCO2, activeDisplayShowCO2, "CO2: ", doNothing, noEvent, wrapStyle
,VALUE("Hide", false, doDisplayReverse, enterEvent)
,VALUE("Show", true, doDisplayReverse, enterEvent));
,VALUE("Hide", false, doNothing, enterEvent)
,VALUE("Show", true, doNothing, enterEvent));

TOGGLE(displayShowPM25, activeDisplayShowPM25, "PM2.5: ", doNothing, noEvent, wrapStyle
,VALUE("Hide", false, doDisplayReverse, enterEvent)
,VALUE("Show", true, doDisplayReverse, enterEvent));
,VALUE("Hide", false, doNothing, enterEvent)
,VALUE("Show", true, doNothing, enterEvent));

MENU(displayConfigMenu, "Display Config", doNothing, noEvent, wrapStyle
#ifdef ARDUINO_LILYGO_T_DISPLAY_S3
Expand Down Expand Up @@ -1183,11 +1181,14 @@ bool menuEntryCharacterReceived() {
}

void menuLoop() {
#ifdef DEBUG_ARDUINOMENU
if (shouldRedrawDisplay) Serial.println("-->[MENU] Entering menu loop with shouldRedrawDisplay: " + String(shouldRedrawDisplay) + " and redrawDisplayOnNextLoop: " + String(redrawDisplayOnNextLoop));
#endif
if (isDownloadingBLE) return; // Do not run the menu if downloading BLE

if ((inMenu) && isMenuDirty) {
#ifdef DEBUG_ARDUINOMENU
Serial.println("-->[MENU] Menu is dirty. Restarting menu...");
#ifdef DEBUG_ARDUINOMENU
Serial.println("-->[MENU] Menu is dirty. Restarting menu...");
#endif
isMenuDirty = false;
mainMenu.dirty = true;
Expand All @@ -1212,6 +1213,9 @@ void menuLoop() {

if (!menuInitialized) {
#if defined(SUPPORT_TFT) || defined(SUPPORT_OLED) || defined(SUPPORT_EINK)
#ifdef DEBUG_ARDUINOMENU
if (shouldRedrawDisplay) Serial.println("-->[MENU] Displaying values while waiting for Improv-WiFi to start with shouldRedrawDisplay: " + String(shouldRedrawDisplay) + " and redrawDisplayOnNextLoop: " + String(redrawDisplayOnNextLoop));
#endif
displayShowValues(shouldRedrawDisplay);
#endif
shouldRedrawDisplay = false;
Expand All @@ -1235,22 +1239,11 @@ void menuLoop() {
#ifdef DEBUG_ARDUINOMENU
static unsigned long lastPrintTime = 0;
if (millis() - lastPrintTime >= 1000) {
Serial.println("-->[MENU] menuLoop");
Serial.println("-->[MENU] menuLoop. shouldRedrawDisplay: " + String(shouldRedrawDisplay) + " and redrawDisplayOnNextLoop: " + String(redrawDisplayOnNextLoop));
lastPrintTime = millis();
}
#endif

#ifdef CONFIG_IDF_TARGET_ESP32S3
// Workaround: Try to avoid Serial TX buffer full if it's not connected to a receiving device. Looks like the issue is just with ESP32 S3
/* if ((Serial.availableForWrite() < 100) || (!workingOnExternalPower)) {
Serial.println("[MENU] Serial TX buffer full or not connected to a receiving device. Restarting Serial...");
Serial.end();
delay(10);
Serial.begin(115200);
}
*/
#endif

if (activeWIFI) {
activeMQTTMenu[0].enable();
} else {
Expand Down
12 changes: 10 additions & 2 deletions CO2_Gadget_TFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,18 @@ void showCO2units(int32_t posX, int32_t posY, bool forceRedraw) {

void displayShowValues(bool forceRedraw = false) {
uint8_t currentDatum = tft.getTextDatum();
if (redrawDisplayOnNextLoop) {
shouldRedrawDisplay = true;
redrawDisplayOnNextLoop = false;
}
if (shouldRedrawDisplay) {
forceRedraw = true;
Serial.println("-->[TFT ] Forcing display redraw");
}
tft.unloadFont();
if (forceRedraw) {
// Serial.println("-->[TFT ] Displaying values. Force Redraw: " + String(forceRedraw ? "true" : "false"));
Serial.println("-->[TFT ] Displaying values. Force Redraw: " + String(forceRedraw ? "true" : "false"));
tft.fillScreen(TFT_BLACK); // Remove previous remains in the screen
spr.fillSprite(TFT_BLACK); // Remove previous remains in the screen
}
showCO2(co2, elementPosition.co2X, elementPosition.co2Y, elementPosition.pixelsToBaseline, forceRedraw);
showCO2units(elementPosition.co2UnitsX, elementPosition.co2UnitsY, forceRedraw);
Expand All @@ -668,6 +675,7 @@ void displayShowValues(bool forceRedraw = false) {
showBLEIcon(elementPosition.bleIconX, elementPosition.bleIconY, forceRedraw);
showEspNowIcon(elementPosition.espNowIconX, elementPosition.espNowIconY, forceRedraw);
forceRedraw = false;
shouldRedrawDisplay = false;

// Revert the datum setting
tft.loadFont(SMALL_FONT);
Expand Down
20 changes: 13 additions & 7 deletions CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ void initWebServer() {
};
// <CO2-GADGET_IP>/settings?ToggleDisplayReverse
if (request->hasParam("ToggleDisplayReverse")) {
Serial.println("-->[DISP] Toggle display reverse");
Serial.println("-->[WEBS] Toggle display reverse");
displayReverse = !displayReverse;
#if defined(SUPPORT_TFT) || defined(SUPPORT_OLED) || defined(SUPPORT_EINK)
setDisplayReverse(displayReverse);
Expand All @@ -1203,23 +1203,29 @@ void initWebServer() {
};
// <CO2-GADGET_IP>/settings?setDisplayBrightness
if (request->hasParam("setDisplayBrightness")) {
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
inputString = request->getParam("setDisplayBrightness")->value();
Serial.println("-->[DISP] Set display brightness");
Serial.println("-->[WEBS] Set display brightness");
DisplayBrightness = inputString.toInt();
setDisplayBrightness(DisplayBrightness);
if (inMenu) isMenuDirty = true;
#else
Serial.println("-->[WEBS] Display brightness not supported");
#endif
request->send(200, "text/plain", "OK. Set Display brightness");
};
// <CO2-GADGET_IP>/settings?showTemp=${inputShowTemp}&showHumidity=${inputShowHumidity}&showBattery=${inputShowBattery}
if (request->hasParam("showTemp")) {
if (request->hasParam("showTemp") || request->hasParam("showHumidity") || request->hasParam("showBattery")) {
displayShowTemperature = (request->getParam("showTemp")->value() == "true" || request->getParam("showTemp")->value() == "1");
displayShowHumidity = (request->getParam("showHumidity")->value() == "true" || request->getParam("showHumidity")->value() == "1");
displayShowBattery = (request->getParam("showBattery")->value() == "true" || request->getParam("showBattery")->value() == "1");
Serial.println("-->[DISP] showTemp(" + request->getParam("showTemp")->value() + ") - showHumidity(" + request->getParam("showHumidity")->value() + ") - showBAttery(" + request->getParam("showBattery")->value() + ") in display");
if (!inMenu) shouldRedrawDisplay = true;
request->send(200, "text/plain", "OK. show/hide Temp/Humidity/Battery in display");
Serial.println("-->[WEBS] showTemp(" + request->getParam("showTemp")->value() + ") - showHumidity(" + request->getParam("showHumidity")->value() + ") - showBAttery(" + request->getParam("showBattery")->value() + ") in display");
if (!inMenu) {
Serial.println("-->[WEBS] Set shouldRedrawDisplay to true");
redrawDisplayOnNextLoop = true;
}
request->send(200, "text/plain", "OK. Showing/hidding Temp/Humidity/Battery in display");
};

// <CO2-GADGET_IP>/settings?displayShowBatteryVoltage=true
if (request->hasParam("displayShowBatteryVoltage")) {
String inputString = request->getParam("displayShowBatteryVoltage")->value();
Expand Down
13 changes: 7 additions & 6 deletions webserver/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ <h1>CO2 Gadget Preferences</h1>

<div class="form-group flex-align-center">
<label for="co2OrangeRange">Orange level:</label>
<input type="number" id="co2OrangeRange" name="co2OrangeRange" value="" onchange="sanityData()">
<input type="number" id="co2OrangeRange" name="co2OrangeRange" value="" onchange="sanityCheckData()">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">CO2 level to be considered "warning".</span>
</div>

<div class="form-group flex-align-center">
<label for="co2RedRange">Red level:</label>
<input type="number" id="co2RedRange" name="co2RedRange" value="" onchange="sanityData()">
<input type="number" id="co2RedRange" name="co2RedRange" value="" onchange="sanityCheckData()">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">CO2 level to be considered "danger".</span>
</div>
Expand Down Expand Up @@ -510,21 +510,21 @@ <h1>CO2 Gadget Preferences</h1>

<div class="form-group flex-align-center">
<label for="showTemp">Show Temperature:</label>
<input type="checkbox" id="showTemp" name="showTemp" onchange="showTempHumBatt()>
<input type="checkbox" id="showTemp" name="showTemp" onchange="showTempHumBatt()">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">Show temperature readings on the display.</span>
</div>

<div class="form-group flex-align-center">
<label for="showHumidity">Show Humidity:</label>
<input type="checkbox" id="showHumidity" name="showHumidity" onchange="showTempHumBatt()>
<input type="checkbox" id="showHumidity" name="showHumidity" onchange="showTempHumBatt()">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">Show humidity readings on the display.</span>
</div>

<div class="form-group flex-align-center">
<label for="showBattery">Show Battery:</label>
<input type="checkbox" id="showBattery" name="showBattery" onchange="showTempHumBatt()>
<input type="checkbox" id="showBattery" name="showBattery" onchange="showTempHumBatt()">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">Show battery level on the display.</span>
</div>
Expand Down Expand Up @@ -559,7 +559,8 @@ <h1>CO2 Gadget Preferences</h1>
</div>
<div class="form-group flex-align-center" id="displayBrightDiv">
<label for="DisplayBright">Display Brightness:</label>
<input type="number" id="DisplayBright" name="DisplayBright" value="" min="5" max="255" step="5" onchange="if(sanityData()) setDisplayBrightness();">
<input type="number" id="DisplayBright" name="DisplayBright" value="" min="5" max="255" step="5"
onchange="if(sanityCheckData()) setDisplayBrightness();">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">Set the display brightness. Lower values will decrease the brightness of the display.</span>
</div>
Expand Down
Loading

0 comments on commit 38e9ec8

Please sign in to comment.