Skip to content

Commit

Permalink
Merge pull request #229 from melkati/Coscolin-development-sanity-web
Browse files Browse the repository at this point in the history
Coscolin development sanity web
  • Loading branch information
melkati authored Jun 10, 2024
2 parents a6d1032 + 38e9ec8 commit b3ed9db
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 77 deletions.
32 changes: 17 additions & 15 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@

/*****************************************************************************************************/

#define SUPPORT_CAPTIVE_PORTAL // Please, don't disable this.
#define SUPPORT_CAPTIVE_PORTAL // Please, don't disable this.

// Functions and enum definitions
void reverseButtons(bool reversed); // Defined in CO2_Gadget_Buttons.h
void outputsLoop(); // Defined in CO2_Gadget_Main.h
void publishMQTTLogData(String logData); // Defined in CO2_Gadget_MQTT.h
void putPreferences(); // Defined in CO2_Gadget_Preferences.h
void menuLoop(); // Defined in CO2_Gadget_Menu.h
void setDisplayReverse(bool reverse); // Defined in CO2_Gadget_TFT.h or CO2_Gadget_OLED.h or CO2_Gadget_EINK.h
void reverseButtons(bool reversed); // Defined in CO2_Gadget_Buttons.h
void outputsLoop(); // Defined in CO2_Gadget_Main.h
void publishMQTTLogData(String logData); // Defined in CO2_Gadget_MQTT.h
void putPreferences(); // Defined in CO2_Gadget_Preferences.h
void menuLoop(); // Defined in CO2_Gadget_Menu.h
void setDisplayReverse(bool reverse); // Defined in CO2_Gadget_TFT.h or CO2_Gadget_OLED.h or CO2_Gadget_EINK.h
void setDisplayBrightness(uint16_t newBrightness); // Defined in CO2_Gadget_TFT.h or CO2_Gadget_OLED.h
// void setBLEHistoryInterval(uint64_t interval); // Defined in CO2_Gadget_BLE.h

// Define enum for toneBuzzerBeep
Expand Down Expand Up @@ -130,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
11 changes: 10 additions & 1 deletion CO2_Gadget_TFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,17 @@ 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
}
showCO2(co2, elementPosition.co2X, elementPosition.co2Y, elementPosition.pixelsToBaseline, forceRedraw);
Expand All @@ -667,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
62 changes: 50 additions & 12 deletions CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,57 +717,57 @@ String getCO2GadgetFeaturesAsJson() {
JsonDocument doc;
#ifdef SUPPORT_BLE
doc["BLE"] = true;
#else
#else
doc["BLE"] = false;
#endif
#ifdef SUPPORT_BUZZER
doc["Buzzer"] = true;
#else
#else
doc["Buzzer"] = false;
#endif
#ifdef SUPPORT_ESPNOW
doc["ESPNow"] = true;
#else
#else
doc["ESPNow"] = false;
#endif
#ifdef SUPPORT_MDNS
doc["mDNS"] = true;
#else
#else
doc["mDNS"] = false;
#endif
#ifdef SUPPORT_MQTT
doc["MQTT"] = true;
#else
#else
doc["MQTT"] = false;
#endif
#ifdef SUPPORT_MQTT_DISCOVERY
doc["MQTTDiscovery"] = true;
#else
#else
doc["MQTTDiscovery"] = false;
#endif
#ifdef SUPPORT_OTA
doc["OTA"] = true;
#else
#else
doc["OTA"] = false;
#endif
#ifdef SUPPORT_TFT
doc["TFT"] = true;
#else
#else
doc["TFT"] = false;
#endif
#ifdef SUPPORT_EINK
doc["EINK"] = true;
#else
#else
doc["EINK"] = false;
#endif
#ifdef SUPPORT_OLED
doc["OLED"] = true;
#else
#else
doc["OLED"] = false;
#endif
#ifdef SUPPORT_CAPTIVE_PORTAL
doc["CaptivePortal"] = true;
#else
#else
doc["CaptivePortal"] = false;
#endif

Expand Down Expand Up @@ -861,7 +861,7 @@ String getCaptivePortalStatusAsJson() {
if (captivePortalDebug) doc["captivePortalDebug"] = captivePortalDebug;

#ifdef DEBUG_CAPTIVE_PORTAL
// doc["captivePortalDebug"] = true;
// doc["captivePortalDebug"] = true;
#endif

String output;
Expand Down Expand Up @@ -1188,6 +1188,44 @@ void initWebServer() {
}
}
};
// <CO2-GADGET_IP>/settings?ToggleDisplayReverse
if (request->hasParam("ToggleDisplayReverse")) {
Serial.println("-->[WEBS] Toggle display reverse");
displayReverse = !displayReverse;
#if defined(SUPPORT_TFT) || defined(SUPPORT_OLED) || defined(SUPPORT_EINK)
setDisplayReverse(displayReverse);
reverseButtons(displayReverse);
if (inMenu) isMenuDirty = true;
#else
reverseButtons(displayReverse);
#endif
request->send(200, "text/plain", "OK. Display reversed");
};
// <CO2-GADGET_IP>/settings?setDisplayBrightness
if (request->hasParam("setDisplayBrightness")) {
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
inputString = request->getParam("setDisplayBrightness")->value();
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") || 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("-->[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
4 changes: 3 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; Release v0.14.006

[platformio]
src_dir = .
data_dir = data
Expand All @@ -10,7 +12,7 @@ extra_configs = platformio_extra_configs.ini
[version]
build_flags =
-D CO2_GADGET_VERSION="\"0.14."\"
-D CO2_GADGET_REV="\"006-development"\"
-D CO2_GADGET_REV="\"006"\"

;****************************************************************************************
;*** You can disable features by commenting the line with a semicolon at the beginning
Expand Down
15 changes: 8 additions & 7 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="">
<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="">
<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">
<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">
<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">
<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 @@ -553,13 +553,14 @@ <h1>CO2 Gadget Preferences</h1>

<div class="form-group flex-align-center" id="displayReverseDiv">
<label for="displayReverse">Display Reverse:</label>
<input type="checkbox" id="displayReverse" name="displayReverse">
<input type="checkbox" id="displayReverse" name="displayReverse" onchange="toggleDisplayReverse()">
<span class="tooltip-icon">ℹ️</span>
<span class="tooltip-text">Reverse the display orientation.</span>
</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">
<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 b3ed9db

Please sign in to comment.