diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 2315136b..797262ec 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -144,7 +144,7 @@ bool displayNotification(String notificationText, String notificationText2, noti bool displayNotification(String notificationText, notificationTypes notificationType) { return true; } #endif #if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) -void setDisplayBrightness(uint32_t newBrightness); +// void setDisplayBrightness(uint32_t newBrightness); #endif /*****************************************************************************************************/ @@ -365,10 +365,18 @@ void readingsLoop() { } void displayLoop() { + +#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) + if (actualDisplayBrightness != DisplayBrightness) { + setDisplayBrightness(DisplayBrightness); + actualDisplayBrightness = DisplayBrightness; + } +#endif + if (timeToDisplayOff == 0) // TFT Always ON return; - // If configured not to turn off the display on external power and actual voltage is more than those of a maximum loaded batery + 5%, do nothing and return + // If configured not to turn off the display on external power and actual voltage is more than those of a maximum loaded batery + 5% (so asume it's working on external power), do nothing and return if ((!displayOffOnExternalPower) && (battery_voltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 5 / 100))) { if (actualDisplayBrightness == 0) // When USB connected & TFT is OFF -> Turn Display ON { @@ -385,7 +393,6 @@ void displayLoop() { #if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) turnOffDisplay(); #endif - actualDisplayBrightness = 0; } } @@ -408,7 +415,7 @@ void utilityLoop() { Serial.printf("-->[BATT] Battery voltage: %.2fV. Increasing CPU frequency to 240MHz\n", battery_voltage); Serial.flush(); Serial.end(); - setCpuFrequencyMhz(240); // High CPU frequency when working on USB power + setCpuFrequencyMhz(240); // High CPU frequency when working on external power Serial.begin(115200); lastCheckedVoltage = battery_voltage; } else if (battery_voltage < 4.5 && actualCPUFrequency != 80) { @@ -420,7 +427,6 @@ void utilityLoop() { lastCheckedVoltage = battery_voltage; } else if (battery_voltage != lastCheckedVoltage) { // The voltage has changed, but the CPU frequency is already at the desired value. - // Handle any additional actions needed in this case. lastCheckedVoltage = battery_voltage; } } diff --git a/CO2_Gadget_BLE.h b/CO2_Gadget_BLE.h index 515318c5..4459d708 100644 --- a/CO2_Gadget_BLE.h +++ b/CO2_Gadget_BLE.h @@ -2,8 +2,12 @@ #define CO2_Gadget_BLE_h #include "Sensirion_Gadget_BLE.h" +#include "WifiMultiLibraryWrapper.h" + NimBLELibraryWrapper lib; -DataProvider provider(lib, DataType::T_RH_CO2_ALT); +WifiMultiLibraryWrapper wifi; +DataProvider provider(lib, DataType::T_RH_CO2_ALT, true, false, false, &wifi); +// DataProvider provider(lib, DataType::T_RH_CO2_ALT); void initBLE() { if (activeBLE) { diff --git a/CO2_Gadget_OLED.h b/CO2_Gadget_OLED.h index c819bf6c..d9e1bc47 100644 --- a/CO2_Gadget_OLED.h +++ b/CO2_Gadget_OLED.h @@ -27,10 +27,12 @@ int displayHeight = 64; void setDisplayBrightness(uint32_t newBrightness) { Serial.printf("-->[OLED] Setting display brightness value at %d\n", newBrightness); u8g2.setContrast(newBrightness); + actualDisplayBrightness = DisplayBrightness; } void turnOffDisplay() { - setDisplayBrightness(0); // Turn off the display + setDisplayBrightness(0); // Turn off the display + actualDisplayBrightness = 0; } void displaySplashScreen() { diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index ad5977ab..9aa0ecfe 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -368,7 +368,7 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { if (DisplayBrightness != JsonDocument["DisplayBright"]) { DisplayBrightness = JsonDocument["DisplayBright"]; #if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) - setDisplayBrightness(DisplayBrightness); + // setDisplayBrightness(DisplayBrightness); #endif } neopixelBrightness = JsonDocument["neopixBright"]; diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 84238e9a..eb55d915 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -26,8 +26,8 @@ #define FF90 &ArchivoNarrow_Regular10pt7b #define FF95 &FontCO2GadgetDigits50pt7b -// RAM: [== ] 21.4% (used 69976 bytes from 327680 bytes) -// Flash: [==========] 95.3% (used 1874104 bytes from 1966080 bytes) +// RAM: [=== ] 29.6% (used 97060 bytes from 327680 bytes) +// Flash: [======= ] 71.8% (used 1411157 bytes from 1966080 bytes) uint16_t iconDefaultColor = TFT_CYAN; @@ -35,13 +35,17 @@ TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke library, pins defined in User_Setup.h void setDisplayBrightness(uint32_t newBrightness) { + Serial.printf("-->[TFT ] Actual display brightness value at %d\n", actualDisplayBrightness); Serial.printf("-->[TFT ] Setting display brightness value at %d\n", newBrightness); - ledcWrite(0, newBrightness); // 0-15, 0-255 (with 8 bit resolution); 0=totally + ledcWrite(BACKLIGHT_PWM_CHANNEL, newBrightness); // 0-15, 0-255 (with 8 bit resolution); 0=totally // dark;255=totally shiny + Serial.printf("-->[TFT ] Actual display brightness value (ledcRead) at %d\n", ledcRead(BACKLIGHT_PWM_CHANNEL)); + actualDisplayBrightness = DisplayBrightness; } void turnOffDisplay() { setDisplayBrightness(0); // Turn off the display + actualDisplayBrightness = 0; } void displaySplashScreen() { @@ -55,8 +59,8 @@ void displaySplashScreen() { void initDisplay() { Serial.printf("-->[TFT ] Initializing display\n"); pinMode(BACKLIGHT_PIN, OUTPUT); - ledcSetup(0, 5000, 8); // 0-15, 5000, 8 - ledcAttachPin(BACKLIGHT_PIN, 0); // TFT_BL, 0 - 15 + ledcSetup(BACKLIGHT_PWM_CHANNEL, BACKLIGHT_PWM_FREQUENCY, 8); // 0-15, 5000, 8 + ledcAttachPin(BACKLIGHT_PIN, BACKLIGHT_PWM_CHANNEL); // TFT_BL, 0 - 15 setDisplayBrightness(DisplayBrightness); tft.init(); if (displayReverse) { diff --git a/CO2_Gadget_WIFI.h b/CO2_Gadget_WIFI.h index 52974ae2..48a98f6d 100644 --- a/CO2_Gadget_WIFI.h +++ b/CO2_Gadget_WIFI.h @@ -17,6 +17,123 @@ WiFiClient espClient; AsyncWebServer server(80); +void printSmallChar(char c, int row) { + switch (c) { + case '0': + switch (row) { + case 0: Serial.print(" 000 "); break; + case 1: Serial.print("0 0"); break; + case 2: Serial.print("0 0"); break; + case 3: Serial.print("0 0"); break; + case 4: Serial.print(" 000 "); break; + } + break; + case '1': + switch (row) { + case 0: Serial.print(" 1 "); break; + case 1: Serial.print(" 11 "); break; + case 2: Serial.print(" 1 "); break; + case 3: Serial.print(" 1 "); break; + case 4: Serial.print(" 111 "); break; + } + break; + case '2': + switch (row) { + case 0: Serial.print(" 222 "); break; + case 1: Serial.print(" 2"); break; + case 2: Serial.print(" 22 "); break; + case 3: Serial.print(" 2 "); break; + case 4: Serial.print(" 2222"); break; + } + break; + case '3': + switch (row) { + case 0: Serial.print(" 333 "); break; + case 1: Serial.print(" 3"); break; + case 2: Serial.print(" 33 "); break; + case 3: Serial.print(" 3"); break; + case 4: Serial.print(" 333 "); break; + } + break; + case '4': + switch (row) { + case 0: Serial.print("4 4"); break; + case 1: Serial.print("4 4"); break; + case 2: Serial.print("44444"); break; + case 3: Serial.print(" 4"); break; + case 4: Serial.print(" 4"); break; + } + break; + case '5': + switch (row) { + case 0: Serial.print("55555"); break; + case 1: Serial.print("5 "); break; + case 2: Serial.print("555 "); break; + case 3: Serial.print(" 5"); break; + case 4: Serial.print("555 "); break; + } + break; + case '6': + switch (row) { + case 0: Serial.print(" 666 "); break; + case 1: Serial.print("6 "); break; + case 2: Serial.print("6666 "); break; + case 3: Serial.print("6 6"); break; + case 4: Serial.print(" 666 "); break; + } + break; + case '7': + switch (row) { + case 0: Serial.print("77777"); break; + case 1: Serial.print(" 7"); break; + case 2: Serial.print(" 7 "); break; + case 3: Serial.print(" 7 "); break; + case 4: Serial.print(" 7 "); break; + } + break; + case '8': + switch (row) { + case 0: Serial.print(" 888 "); break; + case 1: Serial.print("8 8"); break; + case 2: Serial.print(" 888 "); break; + case 3: Serial.print("8 8"); break; + case 4: Serial.print(" 888 "); break; + } + break; + case '9': + switch (row) { + case 0: Serial.print(" 999 "); break; + case 1: Serial.print("9 9"); break; + case 2: Serial.print(" 9999"); break; + case 3: Serial.print(" 9"); break; + case 4: Serial.print(" 999 "); break; + } + break; + case '.': + switch (row) { + case 0: Serial.print(" "); break; + case 1: Serial.print(" "); break; + case 2: Serial.print(" "); break; + case 3: Serial.print(" "); break; + case 4: Serial.print(" o "); break; + } + break; + default: + Serial.print(" "); // Default character for unhandled + break; + } +} + +void printLargeASCII(const char* text) { + for (int row = 0; row < 5; row++) { // 5 rows for each character + for (int i = 0; i < strlen(text); i++) { + printSmallChar(text[i], row); + Serial.print(" "); // Space between characters + } + Serial.println(); // New line after each row of characters + } +} + void onWifiSettingsChanged(std::string ssid, std::string password) { Serial.print("-->[WiFi] WifiSetup: SSID = "); Serial.print(ssid.c_str()); @@ -467,6 +584,9 @@ void initWifi() { Serial.println(MACAddress); Serial.print("-->[WiFi] WiFi connected - IP = "); Serial.println(WiFi.localIP()); + Serial.println(""); + printLargeASCII(WiFi.localIP().toString().c_str()); + Serial.println(""); #ifdef SUPPORT_MDNS mDNSName = WiFi.getHostname(); initMDNS(); diff --git a/platformio.ini b/platformio.ini index bd3be216..58b92242 100644 --- a/platformio.ini +++ b/platformio.ini @@ -57,7 +57,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.8."\" - -D CO2_GADGET_REV="\"010"\" + -D CO2_GADGET_REV="\"013-development"\" -D CORE_DEBUG_LEVEL=0 -DNEOPIXEL_PIN=26 ; Pinnumber for button for down/next and back / exit actions -DNEOPIXEL_COUNT=16 ; How many neopixels to control @@ -152,6 +152,8 @@ build_flags = -DSUPPORT_TFT -DTTGO_TDISPLAY=1 -DBACKLIGHT_PIN=4 ; Pin used for backlight + -DBACKLIGHT_PWM_CHANNEL=0 ; PWM Channel used for backlight + -DBACKLIGHT_PWM_FREQUENCY=1000 ; PWM Frequency used for backlight -DUSER_SETUP_LOADED=1 -DST7789_DRIVER=1 -DENABLE_TFT=1 @@ -198,7 +200,9 @@ build_flags = -DBTN_DWN=0 ; Pinnumber for button for down/next and back / exit actions -DSUPPORT_TFT -DTTGO_TDISPLAY=1 - -DBACKLIGHT_PIN=4 ; Pin used for backlight + -DBACKLIGHT_PIN=4 ; Pin used for backlight + -DBACKLIGHT_PWM_CHANNEL=1 ; PWM Channel used for backlight + -DBACKLIGHT_PWM_FREQUENCY=5000 ; PWM Frequency used for backlight -DUSER_SETUP_LOADED=1 -DST7789_DRIVER=1 -DENABLE_TFT=1