Skip to content

Commit

Permalink
Merge pull request #127 from melkati/development
Browse files Browse the repository at this point in the history
Merge Development branch with new feature and fixes
  • Loading branch information
melkati authored Jan 18, 2024
2 parents e0e2173 + 7ef0076 commit 8b2c711
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 15 deletions.
16 changes: 11 additions & 5 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*****************************************************************************************************/
Expand Down Expand Up @@ -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
{
Expand All @@ -385,7 +393,6 @@ void displayLoop() {
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
turnOffDisplay();
#endif
actualDisplayBrightness = 0;
}
}

Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion CO2_Gadget_BLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion CO2_Gadget_OLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
14 changes: 9 additions & 5 deletions CO2_Gadget_TFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,26 @@
#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;

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() {
Expand All @@ -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) {
Expand Down
120 changes: 120 additions & 0 deletions CO2_Gadget_WIFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b2c711

Please sign in to comment.