Skip to content

Commit

Permalink
Merge pull request melkati#189 from melkati/development
Browse files Browse the repository at this point in the history
Sync Development Branch
  • Loading branch information
melkati authored Mar 2, 2024
2 parents 3c7363a + 2dd7700 commit 836ad71
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 333 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/release3_beta.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Beta Release V2.91
name: Beta Release V2.93

# # # # # # # # # # #
# To create new Beta version and upload so web server, just commit with a message with the format "Beta v*.*.*" (Beta v1.0.1, Beta v1.1.12, Beta v2.1.123, etc)
Expand All @@ -24,15 +24,15 @@ jobs:
strategy:
matrix:
environment:
# - esp32dev
# - esp32dev_OLED
- esp32dev
- esp32dev_OLED
- TTGO_TDISPLAY
- TTGO_TDISPLAY_SANDWICH
- TDISPLAY_S3
# - esp32dev_ST7789_240x320
- esp32dev_ST7789_240x320

env:
CHIP_FAMILY: ${{ matrix.environment == 'TDISPLAY_S3_beta' && 'ESP32-S3' || 'ESP32' }}
CHIP_FAMILY: ${{ matrix.environment == 'TDISPLAY_S3' && 'ESP32-S3' || 'ESP32' }}

timeout-minutes: 30

Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
case "${{ matrix.environment }}" in
"esp32dev_beta")
CHIP_FAMILY="ESP32";;
"TDISPLAY_S3_beta")
"TDISPLAY_S3")
CHIP_FAMILY="ESP32-S3";;
# Add more cases for other environments as needed
*)
Expand Down Expand Up @@ -135,13 +135,15 @@ jobs:
echo "::set-output name=betamanifest::$(cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json)"
- name: Read beta manifest files
if: steps.check_version.outputs.VERSION != ''
run: |
echo "Beta Manifest:"
echo ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json
echo "Beta Manifest file contents read with cat:"
cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json
- name: Copy beta manifest files
if: steps.check_version.outputs.VERSION != ''
run: |
mkdir ./beta_firmware
cp ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json
Expand Down
5 changes: 4 additions & 1 deletion CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ uint64_t lastTimeESPNowPublished = 0; // Time of last ESP-NOW transmission
uint16_t co2OrangeRange = 700;
uint16_t co2RedRange = 1000;

// Variables for Improv-Serial
uint16_t timeToWaitForImprov = 5; // Time in seconds to wait for improv serial

#ifdef BUILD_GIT
#undef BUILD_GIT
#endif // ifdef BUILD_GIT
Expand Down Expand Up @@ -552,7 +555,7 @@ void setup() {
initMQTT();
#endif
menu_init();
buttonsInit();
initButtons();
if (WiFi.status() == WL_CONNECTED) {
Serial.println("");
printLargeASCII(WiFi.localIP().toString().c_str());
Expand Down
24 changes: 12 additions & 12 deletions CO2_Gadget_Battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ void readBatteryVoltage() {
}
batteryVoltageNow /= 3;
batteryVoltage = batteryVoltageNow;
batteryLevel = battery.level(batteryVoltage*1000);
batteryLevel = battery.level(batteryVoltage * 1000);
lastTimeBatteryRead = millis();
// If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), assume it's working on external power
workingOnExternalPower = (batteryVoltageNow * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100));

// If battery voltage is more than 9% of the fully charged battery voltage (~4.58V) or if battery voltage is less than 1V (no battery connected to sense pin), then assume that the device is working on external power.
workingOnExternalPower = (batteryVoltageNow * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)) || (batteryVoltageNow < 1000);

// publishMQTTLogData("Battery Level: " + String(batteryLevel) + "% Battery voltage changed from: " + String(lastBatteryVoltage) + "V to " + String(batteryVoltage) + "V");
}
}
Expand All @@ -67,14 +67,14 @@ void readBatteryVoltage() {

void batteryLoop() {
float batteryVoltageNow = 0;
readBatteryVoltage();
// Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage: %.4fV\n", batteryLevel, batteryVoltageNow);
if (!inMenu) {
if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level
// Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage);
lastBatteryVoltage = batteryVoltage;
}
readBatteryVoltage();
// Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage: %.4fV\n", batteryLevel, batteryVoltageNow);
if (!inMenu) {
if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level
// Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage);
lastBatteryVoltage = batteryVoltage;
}
}
}

#endif // CO2_Gadget_Battery_h
11 changes: 10 additions & 1 deletion CO2_Gadget_Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ void IRAM_ATTR buttonUpISR() {
}
}

void IRAM_ATTR buttonDownISR() {
if (actualDisplayBrightness == 0) // Turn on the display only if it's OFF
{
shouldWakeUpDisplay = true;
lastTimeButtonPressed = millis();
}
}

// void doubleClick(Button2& btn) {
// Serial.println("-->[BUTT] Test double click...");
// displayNotification("Test functionality", "double click", notifyInfo);
// }

void buttonsInit() {
void initButtons() {
// Interrupt Service Routine to turn on the display on button UP press
attachInterrupt(BTN_UP, buttonUpISR, RISING);
attachInterrupt(BTN_DWN, buttonUpISR, RISING);

btnUp.setLongClickTime(LONGCLICK_TIME_MS);
btnUp.setLongClickHandler([](Button2 &b) { nav.doNav(enterCmd); });
Expand Down
138 changes: 83 additions & 55 deletions CO2_Gadget_Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -871,17 +871,6 @@ serialOut outSerial(Serial, serialTops);
#define White RGB565(255, 255, 255)
#define DarkerOrange RGB565(255, 140, 0)

// TFT color table
// const colorDef<uint16_t> colors[6] MEMMODE = {
// //{{disabled normal,disabled selected}, {enabled normal, enabled selected, enabled editing}}
// {{(uint16_t)Black, (uint16_t)Black}, {(uint16_t)Black, (uint16_t)Blue, (uint16_t)Blue}}, // bgColor
// {{(uint16_t)White, (uint16_t)White}, {(uint16_t)White, (uint16_t)White, (uint16_t)White}}, // fgColor
// {{(uint16_t)Red, (uint16_t)Red}, {(uint16_t)Yellow, (uint16_t)Yellow, (uint16_t)Yellow}}, // valColor
// {{(uint16_t)White, (uint16_t)White}, {(uint16_t)White, (uint16_t)White, (uint16_t)White}}, // unitColor
// {{(uint16_t)White, (uint16_t)Gray}, {(uint16_t)Black, (uint16_t)Red, (uint16_t)White}}, // cursorColor
// {{(uint16_t)White, (uint16_t)Yellow}, {(uint16_t)Black, (uint16_t)Blue, (uint16_t)Red}}, // titleColor
// };

const colorDef<uint16_t> colors[6] MEMMODE = {
//{{disabled normal,disabled selected}, {enabled normal, enabled selected, enabled editing}}
{{(uint16_t)Black, (uint16_t)Black}, {(uint16_t)Black, (uint16_t)Blue, (uint16_t)Blue}}, // bgColor
Expand Down Expand Up @@ -919,6 +908,7 @@ panelsList pList(panels, nodes, 1); // a list of panels and nodes
idx_t eSpiTops[MAX_DEPTH] = {0};
TFT_eSPIOut eSpiOut(tft, colors, eSpiTops, pList, fontW, fontH + 1);
menuOut *constMEM outputs[] MEMMODE = {&outSerial, &eSpiOut}; // list of output devices
menuOut *constMEM outputsNoSerial[] MEMMODE = {&eSpiOut}; // list of output devices
#endif // SUPPORT_TFT

#ifdef SUPPORT_OLED
Expand Down Expand Up @@ -1030,79 +1020,117 @@ void loadTempArraysWithActualValues() {

// when menu is suspended
result idle(menuOut &o, idleEvent e) {
if (e == idleStart) {
switch (e) {
case idleStart:
#ifdef DEBUG_ARDUINOMENU
Serial.println("-->[MENU] Event idleStart");
Serial.println("-->[MENU] Event idleStart");
#endif
setInMenu(false);
} else if (e == idling) { // When out of menu (CO2 Monitor is doing his business)
// setInMenu(false);
// nav.poll();

#if defined(SUPPORT_TFT) || defined(SUPPORT_OLED)
displayShowValues(true);
#endif
break;
case idling:
#ifdef DEBUG_ARDUINOMENU
Serial.println("-->[MENU] Event iddling");
Serial.println("-->[MENU] Event iddling");
#endif
#if defined(SUPPORT_TFT) || defined(SUPPORT_OLED)
// displayShowValues();
displayShowValues(false);
#endif
} else if (e == idleEnd) {
break;
case idleEnd:
#ifdef DEBUG_ARDUINOMENU
Serial.println("-->[MENU] Event idleEnd");
Serial.println("-->[MENU] Event idleEnd");
#endif
setInMenu(true);
loadTempArraysWithActualValues();
} else {
setInMenu(true);
// displayNotification("Enter menu", notifyInfo);
// delay(1000);
loadTempArraysWithActualValues();
break;
default:
#ifdef DEBUG_ARDUINOMENU
Serial.print("-->[MENU] Unhandled event: ");
Serial.println(e);
Serial.print("-->[MENU] Unhandled event: ");
Serial.println(e);
#endif
break;
}
// displayNotification("Idle end", notifyInfo);
// delay(1000);
return proceed;
}

void menuLoop() {
uint16_t timeToWaitForImprov = 5; // Time to wait for Improv-WiFi to connect on startup
if (Serial.available() && Serial.peek() == 0x2A) { // 0x2A is the '*' character.
// inMenu = true;
// if (inMenu) {
nav.doInput(); // Do input, even if no display, as serial menu needs this
// }
}

if (millis() < timeInitializationCompleted + timeToWaitForImprov * 1000) { // Wait before starting the menu to avoid issues with Improv-WiFi
#if defined(SUPPORT_TFT) || defined(SUPPORT_OLED)
displayShowValues();
#endif
void menuLoopTFT() {
#ifdef SUPPORT_TFT
if (millis() < (timeInitializationCompleted + timeToWaitForImprov * 1000)) { // Wait before starting the menu to avoid issues with Improv-WiFi
displayShowValues(false);
return;
}

if (activeWIFI) {
activeMQTTMenu[0].enable();
} else {
activeMQTTMenu[0].disable();
}

#if defined(SUPPORT_TFT)
if ((wifiChanged) && (!inMenu)) {
wifiChanged = false;
displayNotification("To clear display", notifyInfo);
delay(1000);
tft.fillScreen(TFT_BLACK);
displayNotification("Display cleared", notifyInfo);
delay(1000);
}
if (inMenu) {
nav.poll(); // this device only draws when needed
}
nav.doOutput();

nav.doInput();
if (nav.sleepTask) {
tft.unloadFont();
displayShowValues();
tft.loadFont(SMALL_FONT);
displayShowValues(false);
} else {
if (nav.changed(0)) {
nav.doOutput();
}
}
#elif defined(SUPPORT_OLED)
#endif
}

void menuLoopOLED() {
#ifdef SUPPORT_OLED
if (millis() < (timeInitializationCompleted + timeToWaitForImprov * 1000)) { // Wait before starting the menu to avoid issues with Improv-WiFi
displayShowValues(false);
return;
}

if (nav.sleepTask) {
displayShowValues();
displayShowValues(false);
} else {
if (nav.changed(0)) {
u8g2.firstPage();
do nav.doOutput();
while (u8g2.nextPage());
}
}
#endif
}

void menuLoop() {
// Time to wait for Improv-WiFi to connect on startup. 0x2A is the '*' character.
uint16_t timeToWaitForImprov = 5;
if (Serial.available() && Serial.peek() == 0x2A) {
nav.doInput(); // Do input, even if no display, as serial menu needs this
}

// Workaround: Try to avoid Serial TX buffer full if it's not connected to a receiving device
if ((Serial.availableForWrite() < 100) || (!workingOnExternalPower)) {
Serial.end();
delay(10);
Serial.begin(115200);
}

if (activeWIFI) {
activeMQTTMenu[0].enable();
} else {
activeMQTTMenu[0].disable();
}

#ifdef SUPPORT_TFT
menuLoopTFT();
#elif defined(SUPPORT_OLED)
menuLoopOLED();
#else // For serial only output
if (!nav.sleepTask) {
if (nav.changed(0)) {
Expand All @@ -1117,8 +1145,8 @@ void menu_init() {
tft.loadFont(SMALL_FONT);
#endif
nav.idleTask = idle; // function to be called when menu is suspended
nav.idleOn(idle);
// nav.timeOut = 30; // Removed timeout as it was causing issues with the display clean at exit from menu by timeout
nav.idleOn(idle); // start the menu in idle state
nav.timeOut = 10;
nav.showTitle = true;
options->invertFieldKeys = true;
nav.useUpdateEvent = true;
Expand Down
13 changes: 9 additions & 4 deletions CO2_Gadget_OLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <U8g2lib.h>
#include "bootlogo.h"
#include "icons.h"
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Frame Buffer: clearBuffer/sendBuffer. More RAM usage, Faster
// U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Page Buffer: firstPage/nextPage. Less RAM usage, Slower
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE); // Frame Buffer: clearBuffer/sendBuffer. More RAM usage, Faster
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Frame Buffer: u8g2.clearBuffer, u8g2.sendBuffer. Less RAM usage, Slower

char oled_msg[20];
int displayWidth = 128;
Expand Down Expand Up @@ -83,12 +83,17 @@ void initDisplay() {
delay(1000);
}

void displayShowValues() {
void displayShowValues(bool forceRedraw = false) {
if ((co2 == 0) || (co2 > 9999)) return;
String co2Str = String(co2);
if (co2Str.length() < 4) {
co2Str = " " + co2Str;
}
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_7Segments_26x42_mn);
u8g2.setCursor(0, 44);
u8g2.print(co2);
u8g2.print(co2Str);
u8g2.setFont(u8g2_font_5x7_tf);
u8g2.setCursor(110, 51);
u8g2.print("ppm");
Expand Down
2 changes: 1 addition & 1 deletion CO2_Gadget_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) {

// Send a successful response
// request->send(200, "text/plain", "Preferences saved successfully");
Serial.println("-->[PREF] Preferences saved successfully @ handleSavePreferencesfromJSON()");
// Serial.println("-->[PREF] Preferences saved successfully @ handleSavePreferencesfromJSON()");
putPreferences();
return true;
}
Expand Down
Loading

0 comments on commit 836ad71

Please sign in to comment.