diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index 42355f11..b065a6a0 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -680,7 +680,12 @@ TOGGLE(displayShowPM25, activeDisplayShowPM25, "PM2.5: ", doNothing, noEvent, wr ,VALUE("Show", true, doDisplayReverse, enterEvent)); MENU(displayConfigMenu, "Display Config", doNothing, noEvent, wrapStyle +#ifdef ARDUINO_LILYGO_T_DISPLAY_S3 + ,FIELD(DisplayBrightness, "Brightness:", "", 1, 16, 1, 1, doSetDisplayBrightness, anyEvent, wrapStyle) +#endif +#ifdef TTGO_TDISPLAY || ST7789_240x320 ,FIELD(DisplayBrightness, "Brightness:", "", 10, 255, 10, 10, doSetDisplayBrightness, anyEvent, wrapStyle) +#endif ,FIELD(timeToDisplayOff, "Time To Off:", "", 0, 900, 5, 5, doNothing, noEvent, wrapStyle) ,SUBMENU(activeDisplayOffMenuOnBattery) ,SUBMENU(activeDisplayReverse) diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index 51cdf764..3d6e3e57 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -101,7 +101,11 @@ void initPreferences() { autoSelfCalibration = preferences.getBool("autoSelfCal", false); co2OrangeRange = preferences.getUInt("co2OrangeRange", 700); co2RedRange = preferences.getUInt("co2RedRange", 1000); +#ifdef LILYGO_T_DISPLAY_S3 + DisplayBrightness = preferences.getUInt("DisplayBright", 8); +#else DisplayBrightness = preferences.getUInt("DisplayBright", 100); +#endif neopixelBrightness = preferences.getUInt("neopixBright", 50); selectedNeopixelType = preferences.getUInt("selNeopxType", NEO_GRB + NEO_KHZ800); activeBLE = preferences.getBool("activeBLE", true); @@ -171,7 +175,7 @@ void initPreferences() { // Retrieve buzzer preferences toneBuzzerBeep = preferences.getUInt("toneBzrBeep", BUZZER_TONE_MED); // Frequency of the buzzer beep durationBuzzerBeep = preferences.getUInt("durBzrBeep", DURATION_BEEP_MEDIUM); // Duration of the buzzer beep - timeBetweenBuzzerBeeps = preferences.getUInt("timeBtwnBzr", 65535); // Time between consecutive beeps + timeBetweenBuzzerBeeps = preferences.getUInt("timeBtwnBzr", 65535); // Time between consecutive beeps rootTopic.trim(); mqttClientId.trim(); @@ -186,7 +190,7 @@ void initPreferences() { #ifdef DEBUG_PREFERENCES printPreferences(); #endif -upgradePreferences(); + upgradePreferences(); } void putPreferences() { @@ -251,9 +255,9 @@ void putPreferences() { preferences.putBool("showPM25", displayShowPM25); // Buzzer preferences - preferences.putUInt("toneBzrBeep", toneBuzzerBeep); // Buzzer frequency - preferences.putUInt("durBzrBeep", durationBuzzerBeep); // Buzzer duration - preferences.putUInt("timeBtwnBzr", timeBetweenBuzzerBeeps); // Time between beeps + preferences.putUInt("toneBzrBeep", toneBuzzerBeep); // Buzzer frequency + preferences.putUInt("durBzrBeep", durationBuzzerBeep); // Buzzer duration + preferences.putUInt("timeBtwnBzr", timeBetweenBuzzerBeeps); // Time between beeps preferences.end(); @@ -315,9 +319,9 @@ String getPreferencesAsJson() { doc["measInterval"] = preferences.getInt("measInterval", 10); // Buzzer preferences - doc["toneBzrBeep"] = preferences.getUInt("toneBzrBeep", 1000); // Buzzer frequency - doc["durBzrBeep"] = preferences.getUInt("durBzrBeep", 100); // Buzzer duration - doc["timeBtwnBzr"] = preferences.getUInt("timeBtwnBzr", 65535); // Time between beeps + doc["toneBzrBeep"] = preferences.getUInt("toneBzrBeep", 1000); // Buzzer frequency + doc["durBzrBeep"] = preferences.getUInt("durBzrBeep", 100); // Buzzer duration + doc["timeBtwnBzr"] = preferences.getUInt("timeBtwnBzr", 65535); // Time between beeps preferences.end(); @@ -388,9 +392,9 @@ String getActualSettingsAsJson() { doc["measInterval"] = measurementInterval; // Buzzer preferences - doc["toneBzrBeep"] = toneBuzzerBeep; // Buzzer frequency - doc["durBzrBeep"] = durationBuzzerBeep; // Buzzer duration - doc["timeBtwnBzr"] = timeBetweenBuzzerBeeps; // Time between beeps + doc["toneBzrBeep"] = toneBuzzerBeep; // Buzzer frequency + doc["durBzrBeep"] = durationBuzzerBeep; // Buzzer duration + doc["timeBtwnBzr"] = timeBetweenBuzzerBeeps; // Time between beeps String preferencesJson; serializeJson(doc, preferencesJson); @@ -440,12 +444,12 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { rootTopic = JsonDocument["rootTopic"].as().c_str(); batteryDischargedMillivolts = JsonDocument["batDischgd"]; batteryFullyChargedMillivolts = JsonDocument["batChargd"]; - if (vRef != JsonDocument["vRef"]) { // If battery reference changed, apply it + if (vRef != JsonDocument["vRef"]) { // If battery reference changed, apply it vRef = JsonDocument["vRef"]; battery.begin(vRef, voltageDividerRatio, &asigmoidal); readBatteryVoltage(); } - vRef = JsonDocument["vRef"]; + vRef = JsonDocument["vRef"]; mqttClientId = JsonDocument["mqttClientId"].as().c_str(); mqttBroker = JsonDocument["mqttBroker"].as().c_str(); mqttUser = JsonDocument["mqttUser"].as().c_str(); @@ -483,9 +487,9 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { displayShowPM25 = JsonDocument["showPM25"]; // Buzzer preferences - toneBuzzerBeep = JsonDocument["toneBzrBeep"]; // Buzzer frequency - durationBuzzerBeep = JsonDocument["durBzrBeep"]; // Buzzer duration - timeBetweenBuzzerBeeps = JsonDocument["timeBtwnBzr"]; // Time between beeps + toneBuzzerBeep = JsonDocument["toneBzrBeep"]; // Buzzer frequency + durationBuzzerBeep = JsonDocument["durBzrBeep"]; // Buzzer duration + timeBetweenBuzzerBeeps = JsonDocument["timeBtwnBzr"]; // Time between beeps // mqttPass = JsonDocument["mqttPass"].as().c_str(); // wifiPass = JsonDocument["wifiPass"].as().c_str(); diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 14daee6e..9d093110 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -200,12 +200,16 @@ void setDisplayBrightness(uint16_t newBrightness) { #endif #ifdef ARDUINO_LILYGO_T_DISPLAY_S3 if (actualDisplayBrightness != newBrightness) { - // Serial.printf("\n-->[TFT ] DisplayBrightness value at %d\n", DisplayBrightness); - // Serial.printf("-->[TFT ] Old actualDisplayBrightness value at %d\n", actualDisplayBrightness); - // Serial.printf("-->[TFT ] New actualDisplayBrightness value at %d\n", newBrightness); - if (newBrightness == 0) { + uint16_t dif, i; + if (newBrightness > actualDisplayBrightness) + dif = 16 - (newBrightness - actualDisplayBrightness); + else + dif = actualDisplayBrightness - newBrightness; + + // Serial.printf("-->[TFT ] Change brightness %d levels", dif); + for (i = 1; i <= dif; i++) { digitalWrite(TFT_BACKLIGHT, LOW); - } else { + delayMicroseconds(20); digitalWrite(TFT_BACKLIGHT, HIGH); } actualDisplayBrightness = newBrightness; @@ -274,6 +278,10 @@ void initBacklight() { delay(20); digitalWrite(TFT_BACKLIGHT, HIGH); digitalWrite(TFT_POWER_ON_BATTERY, HIGH); + actualDisplayBrightness = 16; // At the beginning brightness is at maximum level + if (DisplayBrightness > 16) // Prevent malfunction if upper values are stored in preferences + DisplayBrightness = 16; + setDisplayBrightness(DisplayBrightness); #endif } diff --git a/platformio.ini b/platformio.ini index 1208a423..d40b67a9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -242,6 +242,7 @@ build_flags = -DRED_PIN=01 ; GPIO to go HIGH on red color range -DBLUE_PIN=03 ; GPIO to go HIGH on orange color range -DSUPPORT_TFT + -DLILYGO_T_DISPLAY_S3 -DLV_LVGL_H_INCLUDE_SIMPLE ; -DARDUINO_USB_CDC_ON_BOOT=1 ; -DARDUINO_USB_MODE=1