From df536fc5a894b066ef3325e077b228676a248f60 Mon Sep 17 00:00:00 2001 From: "eMariete.com" Date: Fri, 17 Dec 2021 00:11:52 +0100 Subject: [PATCH 1/3] First refactory to support OLED (tested TFT still working) --- CO2_Gadget.ino | 5 +-- CO2_Gadget_Buttons.h | 7 +++- CO2_Gadget_Menu.h | 33 +++++++++++++++++-- CO2_Gadget_OLED.h | 71 +++++++++++++++++++++++++--------------- CO2_Gadget_Preferences.h | 6 ++-- CO2_Gadget_TFT.h | 32 ++++++++---------- platformio.ini | 27 ++++++++++++--- 7 files changed, 123 insertions(+), 58 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 5c70ec9d..8a8d03be 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -32,6 +32,7 @@ bool debugSensors = false; bool inMenu = false; bool bleInitialized = false; int8_t selectedCO2Sensor = -1; +uint32_t DisplayBrightness = 100; // Variables to control automatic display off to save power bool displayOffOnExternalPower = false; @@ -234,8 +235,8 @@ void displayLoop() { return; if (millis() > nextTimeToDisplayOff) { - Serial.println("-->[MAIN] Turning off display to save power"); - setTFTBrightness(0); // Turn off the display + Serial.println("-->[MAIN] Turning off display to save power"); + turnOffDisplay(); nextTimeToDisplayOff = nextTimeToDisplayOff + (timeToDisplayOff * 1000); } } diff --git a/CO2_Gadget_Buttons.h b/CO2_Gadget_Buttons.h index 1a07b4af..f7070008 100644 --- a/CO2_Gadget_Buttons.h +++ b/CO2_Gadget_Buttons.h @@ -6,7 +6,12 @@ Button2 btnUp(BTN_UP); // Initialize the up button Button2 btnDwn(BTN_DWN); // Initialize the down button void IRAM_ATTR buttonUpISR() { - setTFTBrightness(TFTBrightness); // Turn on the display at TFTBrightness brightness + #ifdef SUPPORT_TFT + setTFTBrightness(DisplayBrightness); // Turn on the display at DisplayBrightness brightness + #endif + #ifdef SUPPORT_OLED + setOLEDBrightness(DisplayBrightness); // Turn on the display at DisplayBrightness brightness + #endif nextTimeToDisplayOff = millis() + (timeToDisplayOff*1000); } diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index a6217651..9e11ca2c 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -10,7 +10,13 @@ // clang-format on #include #include +#ifdef SUPPORT_TFT #include +#endif + +#ifdef SUPPORT_OLED +#include +#endif // #include #include //must include this even if not doing web output... @@ -195,12 +201,17 @@ result doSavePreferences(eventMask e, navNode &nav, prompt &item) { result doSetTFTBrightness(eventMask e, navNode &nav, prompt &item) { #ifdef DEBUG_ARDUINOMENU - Serial.printf("-->[MENU] Setting TFT brightness at %d", TFTBrightness); + Serial.printf("-->[MENU] Setting TFT brightness at %d", DisplayBrightness); Serial.print(F("-->[MENU] action1 event:")); Serial.println(e); Serial.flush(); #endif - setTFTBrightness(TFTBrightness); +#ifdef SUPPORT_FTF + setTFTBrightness(DisplayBrightness); +#endif +#ifdef SUPPORT_OLED + setOLEDBrightness(DisplayBrightness); +#endif return proceed; } @@ -507,7 +518,7 @@ TOGGLE(displayOffOnExternalPower, activeDisplayOffMenuOnBattery, "Off on USB: ", ,VALUE("OFF", false, doNothing, noEvent)); MENU(displayConfigMenu, "Display Config", doNothing, noEvent, wrapStyle - ,FIELD(TFTBrightness, "Brightness:", "", 10, 255, 10, 10, doSetTFTBrightness, anyEvent, wrapStyle) + ,FIELD(DisplayBrightness, "Brightness:", "", 10, 255, 10, 10, doSetTFTBrightness, anyEvent, wrapStyle) ,FIELD(timeToDisplayOff, "Time To Off:", "", 0, 900, 5, 5, doNothing, noEvent, wrapStyle) ,SUBMENU(activeDisplayOffMenuOnBattery) ,EXIT(" -U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/U8X8_PIN_NONE); +// #include +#include +U8X8_SH1106_128X64_NONAME_HW_I2C u8g2(/* reset=*/U8X8_PIN_NONE); +// U8G2_SSD1306_128X64_NONAME_HW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); + + char oled_msg[20]; int displayWidth = 128; int displayHeight = 64; -#endif +void setOLEDBrightness(uint32_t newBrightness) { + Serial.printf("Setting screen brightness value at %d\n (unfunctional. TO DO", newBrightness); +} + +void turnOffDisplay() { + setOLEDBrightness(0); // Turn off the display +} void initDisplayOLED() { #if defined SUPPORT_OLED - u8x8.begin(); - u8x8.setPowerSave(0); - u8x8.setFont(u8x8_font_chroma48medium8_r); - u8x8.drawString(0, 1, " eMariete.com"); - u8x8.drawString(0, 2, " Sensirion"); - u8x8.drawString(0, 3, "CO2 Gadget"); - u8x8.drawString(0, 4, "Concentration Monitor"); + u8g2.begin(); + u8g2.setPowerSave(0); + u8g2.setFont(u8x8_font_chroma48medium8_r); + u8g2.drawString(0, 1, " eMariete.com"); + u8g2.drawString(0, 2, " Sensirion"); + u8g2.drawString(0, 3, "CO2 Gadget"); + u8g2.drawString(0, 4, "Concentration Monitor"); #endif } void showValuesOLED(String text) { #if defined SUPPORT_OLED - u8x8.clearLine(2); - u8x8.clearLine(3); - u8x8.setFont(u8x8_font_chroma48medium8_r); - u8x8.drawString(0, 4, "CO2: "); - u8x8.setFont(u8x8_font_courB18_2x3_r); + u8g2.clearLine(2); + u8g2.clearLine(3); + u8g2.setFont(u8x8_font_chroma48medium8_r); + u8g2.drawString(0, 4, "CO2: "); + u8g2.setFont(u8x8_font_courB18_2x3_r); sprintf(oled_msg, "%4d", co2); // If parameter string then: co2.c_str() - u8x8.drawString(4, 3, oled_msg); - u8x8.setFont(u8x8_font_chroma48medium8_r); - u8x8.drawString(12, 4, "ppm"); + u8g2.drawString(4, 3, oled_msg); + u8g2.setFont(u8x8_font_chroma48medium8_r); + u8g2.drawString(12, 4, "ppm"); - u8x8.clearLine(6); + u8g2.clearLine(6); sprintf(oled_msg, "T:%.1fC RH:%.0f%%", temp, hum); - u8x8.drawUTF8(0, 6, oled_msg); + u8g2.drawUTF8(0, 6, oled_msg); if (activeWIFI) { - if (WiFiMulti.run() != WL_CONNECTED) { - u8x8.clearLine(7); - u8x8.drawUTF8(0, 6, "WiFi unconnected"); + if (WiFi.status() != WL_CONNECTED) { + u8g2.clearLine(7); + u8g2.drawUTF8(0, 6, "WiFi unconnected"); } else { - u8x8.clearLine(7); + u8g2.clearLine(7); IPAddress ip = WiFi.localIP(); sprintf(oled_msg, "%s", ip.toString().c_str()); // sprintf("IP:%u.%u.%u.%u\n", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & // 0xff, ip >> 24); - u8x8.drawString(0, 7, oled_msg); + u8g2.drawString(0, 7, oled_msg); } } #endif -} \ No newline at end of file +} + +#endif // SUPPORT_OLED +#endif // CO2_Gadget_OLED_h diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index adebb778..f68718e2 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -11,7 +11,7 @@ void printPreferences() { ((autoSelfCalibration) ? "Enabled" : "Disabled")); Serial.printf("co2OrangeRange:\t #%d#\n", co2OrangeRange); Serial.printf("co2RedRange:\t #%d#\n", co2RedRange); - Serial.printf("TFTBrightness:\t #%d#\n", TFTBrightness); + Serial.printf("DisplayBrightness:\t #%d#\n", DisplayBrightness); Serial.printf("activeBLE is:\t#%s#\n", ((activeBLE) ? "Enabled" : "Disabled")); Serial.printf("activeWIFI is:\t#%s#\n", ((activeWIFI) ? "Enabled" : "Disabled")); Serial.printf("activeMQTT is:\t#%s#\n", ((activeMQTT) ? "Enabled" : "Disabled")); @@ -46,7 +46,7 @@ void initPreferences() { autoSelfCalibration = preferences.getBool("autoSelfCal", false); co2OrangeRange = preferences.getUInt("co2OrangeRange", 700); co2RedRange = preferences.getUInt("co2RedRange", 1000); - TFTBrightness = preferences.getUInt("TFTBrightness", 100); + DisplayBrightness = preferences.getUInt("DisplayBrightness", 100); activeBLE = preferences.getBool("activeBLE", true); activeWIFI = preferences.getBool("activeWIFI", false); activeMQTT = preferences.getBool("activeMQTT", false); @@ -101,7 +101,7 @@ void putPreferences() { preferences.putBool("autoSelfCal", autoSelfCalibration); preferences.putUInt("co2OrangeRange", co2OrangeRange); preferences.putUInt("co2RedRange", co2RedRange); - preferences.putUInt("TFTBrightness", TFTBrightness); + preferences.putUInt("DisplayBrightness", DisplayBrightness); preferences.putBool("activeBLE", activeBLE); preferences.putBool("activeWIFI", activeWIFI); preferences.putBool("activeMQTT", activeMQTT); diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 4b834154..77f1e35b 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -1,4 +1,10 @@ + +#ifndef CO2_Gadget_TFT_h +#define CO2_Gadget_TFT_h + +#ifdef SUPPORT_TFT + // clang-format off /*****************************************************************************************************/ /********* *********/ @@ -6,7 +12,6 @@ /********* *********/ /*****************************************************************************************************/ // clang-format on -#if defined SUPPORT_TFT #include #include @@ -23,12 +28,10 @@ // RAM: [== ] 21.4% (used 69976 bytes from 327680 bytes) // Flash: [==========] 95.3% (used 1874104 bytes from 1966080 bytes) -uint32_t TFTBrightness = 100; uint16_t iconDefaultColor = TFT_CYAN; TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke library, pins defined in User_Setup.h -#endif void setTFTBrightness(uint32_t newBrightness) { Serial.printf("Setting screen brightness value at %d\n", newBrightness); @@ -36,25 +39,25 @@ void setTFTBrightness(uint32_t newBrightness) { // dark;255=totally shiny } +void turnOffDisplay() { + setTFTBrightness(0); // Turn off the display +} + void initDisplayTFT() { -#if defined SUPPORT_TFT pinMode(BACKLIGHT_PIN, OUTPUT); ledcSetup(0, 5000, 8); // 0-15, 5000, 8 ledcAttachPin(BACKLIGHT_PIN, 0); // TFT_BL, 0 - 15 - setTFTBrightness(TFTBrightness); + setTFTBrightness(DisplayBrightness); tft.init(); tft.setRotation(1); -#endif } void displaySplashScreenTFT() { -#if defined SUPPORT_TFT tft.fillScreen(TFT_WHITE); tft.setSwapBytes(true); tft.pushImage(60, 12, 118, 40, eMarieteLogo); tft.pushImage(10, 50, 92, 72, CO2Logo); tft.pushImage(112, 67, 122, 46, GadgetLogo); -#endif } void showBatteryIconTFT() { @@ -121,36 +124,29 @@ void showMQTTIconTFT(int32_t posX, int32_t posY) { } void showTemperatureTFT() { -#if defined SUPPORT_TFT // Draw Voltaje number if (temp >= 30) tft.setTextColor(TFT_ORANGE, TFT_BLACK); else if (temp >= 10) tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK); - else tft.setTextColor(TFT_SKYBLUE, TFT_BLACK); - + else tft.setTextColor(TFT_SKYBLUE, TFT_BLACK); tft.setTextDatum(BL_DATUM); tft.setSwapBytes(true); tft.pushImage(2, tft.height()-22, 16, 16, iconTemperature); tft.drawString(String(temp, 1) + "~" , 22 , tft.height()-2); - #endif } void showHumidity() { -#if defined SUPPORT_TFT if (hum<=25) tft.setTextColor(TFT_WHITE, TFT_RED); else if (hum<40) tft.setTextColor(TFT_ORANGE, TFT_BLACK); else if (hum<=60) tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK); else if (hum<75) tft.setTextColor(TFT_SKYBLUE, TFT_BLACK); else tft.setTextColor(TFT_RED, TFT_SKYBLUE); - tft.setTextDatum(BR_DATUM); tft.setSwapBytes(true); tft.pushImage(tft.width()-60, tft.height()-22, 16, 16, iconHumidity); tft.drawString(String(hum, 0) + "%", tft.width()-6, tft.height()-2); -#endif } void showVoltageTFT(int32_t posX, int32_t posY) { -#if defined SUPPORT_TFT // Draw Voltaje number uint16_t battery_voltage = battery.voltage(); if (battery_voltage <= 3.6) { @@ -162,10 +158,8 @@ void showVoltageTFT(int32_t posX, int32_t posY) { } else { tft.setTextColor(TFT_BLUE, TFT_BLACK); } - tft.setTextDatum(TR_DATUM); tft.drawString(String(battery_voltage, 1) + "V", posX, posY); -#endif } void showBLEDeviceIdTFT(int32_t posX, int32_t posY) { @@ -223,3 +217,5 @@ void showValuesTFT(uint16_t co2) { tft.setTextSize(2); #endif } +#endif // SUPPORT_WEBCONFIG +#endif // CO2_Gadget_TFT_h \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index dd488279..052a6620 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ src_dir = . data_dir = data ; build_dir = ${sysenv.TEMP}/pio-build/$PROJECT_HASH -default_envs = esp32dev, esp32dev-sandwich, TTGO_TDISPLAY, TTGO_TDISPLAY_SANDWICH +default_envs = esp32dev, esp32dev-sandwich, TTGO_TDISPLAY, TTGO_TDISPLAY_SANDWICH, esp32dev_OLED [common_env_data] framework = arduino @@ -52,7 +52,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.5."\" - -D CO2_GADGET_REV="\"000"\" + -D CO2_GADGET_REV="\"000-Feature-OLED"\" -D CORE_DEBUG_LEVEL=0 -D TTGO_TDISPLAY=1 -D ENABLE_PIN=27 ; Reserved for the future to enable the sensor @@ -62,7 +62,6 @@ build_flags = ; -D SUPPORT_OTA ; Needs SUPPORT_WIFI - CURRENTLY NOT WORKING AWAITING FIX ; -D SUPPORT_MDNS ; Needs SUPPORT_WIFI -D SUPPORT_MQTT ; Needs SUPPORT_WIFI - -D SUPPORT_TFT ; -D DEBUG_ARDUINOMENU [env:esp32dev] @@ -112,7 +111,8 @@ lib_deps = ${common_env_data.lib_deps} build_flags = ${common_env_data.build_flags} - -Os + -Os + -D SUPPORT_TFT -DUSER_SETUP_LOADED=1 -DST7789_DRIVER=1 -DENABLE_TFT=1 @@ -153,6 +153,7 @@ lib_deps = build_flags = ${common_env_data.build_flags} -Os + -D SUPPORT_TFT -DUSER_SETUP_LOADED=1 -DST7789_DRIVER=1 -DENABLE_TFT=1 @@ -178,3 +179,21 @@ build_flags = -DSPI_READ_FREQUENCY=6000000 -D UNITHOSTNAME="\"CO2-Gadget-S"\" -D ALTERNATIVE_I2C_PINS + +[env:esp32dev_OLED] +platform = espressif32 +board = esp32dev +framework = ${common_env_data.framework} +upload_speed = ${common_env_data.upload_speed} +monitor_speed = ${common_env_data.monitor_speed} +upload_port = ${common_env_data.upload_port} +monitor_port = ${common_env_data.monitor_port} +monitor_filters = ${common_env_data.monitor_filters} +board_build.partitions = ${common_env_data.board_build.partitions} +lib_deps = + ${common_env_data.lib_deps} + olikraus/U8g2@^2.32.6 +build_flags = + ${common_env_data.build_flags} + -D UNITHOSTNAME="\"CO2-Gadget"\" + -D SUPPORT_OLED \ No newline at end of file From 46aa46fb46896be1522593d2b656c56152c8e94b Mon Sep 17 00:00:00 2001 From: "eMariete.com" Date: Fri, 17 Dec 2021 21:24:36 +0100 Subject: [PATCH 2/3] First OLED working version with menu --- CO2_Gadget.ino | 16 ++++- CO2_Gadget_Menu.h | 95 +++++++++++++++++++++++------ CO2_Gadget_OLED.h | 84 +++++++++++++------------- CO2_Gadget_Preferences.h | 4 +- CO2_Gadget_Sensors.h | 12 +--- CO2_Gadget_TFT.h | 3 +- bootlogo.h | 127 ++++++++++++++++++++++++++++++++++++++- platformio.ini | 30 +++++---- 8 files changed, 282 insertions(+), 89 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 8a8d03be..6df07c03 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -8,7 +8,7 @@ /**/ // #define SUPPORT_OTA // Needs SUPPORT_WIFI - CURRENTLY NOT WORKING AWAITING FIX /**/ #define SUPPORT_TFT /**/ #define DEBUG_ARDUINOMENU -#define UNITHOSTNAME "CO2-Gadget" +/**/ #define UNITHOSTNAME "CO2-Gadget" /**/ // #define ALTERNATIVE_I2C_PINS // For the compact build as shown at https://emariete.com/medidor-co2-display-tft-color-ttgo-t-display-sensirion-scd30/ /**/ #endif /*****************************************************************************************************/ @@ -45,6 +45,16 @@ uint64_t lastButtonUpTimeStamp = millis(); // Last time button UP was pressed #endif // ifdef BUILD_GIT #define BUILD_GIT __DATE__ +#undef I2C_SDA +#undef I2C_SCL +#ifdef ALTERNATIVE_I2C_PINS +#define I2C_SDA 22 +#define I2C_SCL 21 +#else +#define I2C_SDA 21 +#define I2C_SCL 22 +#endif + #include #include "driver/adc.h" #include "soc/soc.h" // disable brownout problems @@ -261,6 +271,8 @@ void setup() { delay(100); initDisplayOLED(); delay(1000); + displaySplashScreenOLED(); + delay(1000); #endif #if defined SUPPORT_TFT initDisplayTFT(); @@ -292,5 +304,5 @@ void loop() { #endif displayLoop(); buttonsLoop(); - nav.poll(); // this device only draws when needed + menuLoop(); } diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index 9e11ca2c..c5e75f2f 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -10,14 +10,16 @@ // clang-format on #include #include + #ifdef SUPPORT_TFT #include #endif #ifdef SUPPORT_OLED #include +#include #endif -// #include + #include //must include this even if not doing web output... using namespace Menu; @@ -539,8 +541,8 @@ MENU(configMenu, "Configuration", doNothing, noEvent, wrapStyle MENU(informationMenu, "Information", doNothing, noEvent, wrapStyle ,FIELD(battery_voltage, "Battery", "V", 0, 9, 0, 0, doNothing, noEvent, noStyle) - ,OP("Comp" BUILD_GIT, doNothing, noEvent) - ,OP("Version" CO2_GADGET_VERSION CO2_GADGET_REV, doNothing, noEvent) + ,OP("Comp " BUILD_GIT, doNothing, noEvent) + ,OP("Version " CO2_GADGET_VERSION CO2_GADGET_REV, doNothing, noEvent) ,EDIT("IP", tempIPAddress, alphaNum, doNothing, noEvent, wrapStyle) ,EDIT("BLE Dev. Id", tempBLEDeviceId, alphaNum, doNothing, noEvent, wrapStyle) ,EXIT(" colors[6] MEMMODE = { {{(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)DarkerOrange, (uint16_t)Red}}, // titleColor - Menu title color }; +#endif + +#ifdef SUPPORT_OLED +// define menu colors -------------------------------------------------------- +//each color is in the format: +// {{disabled normal,disabled selected},{enabled normal,enabled selected, enabled editing}} +// this is a monochromatic color table +const colorDef colors[6] MEMMODE={ + {{0,0},{0,1,1}},//bgColor + {{1,1},{1,0,0}},//fgColor + {{1,1},{1,0,0}},//valColor + {{1,1},{1,0,0}},//unitColor + {{0,1},{0,0,1}},//cursorColor + {{1,1},{1,0,0}},//titleColor +}; +#endif // clang-format on #define MAX_DEPTH 4 @@ -625,29 +643,50 @@ serialOut outSerial(Serial, serialTops); #endif #ifdef SUPPORT_OLED -#define tft_WIDTH 128 -#define tft_HEIGHT 64 -#define fontW 12 -#define fontH 18 +#define fontX 5 +#define fontY 10 +// #define MENUFONT u8g2_font_7x13_mf +// #define fontX 7 +// #define fontY 16 +#define offsetX 1 +#define offsetY 2 +#define U8_Width 128 +#define U8_Height 64 +#define USE_HWI2C +#define fontMarginX 2 +#define fontMarginY 2 #endif +#ifdef SUPPORT_TFT const panel panels[] MEMMODE = {{0, 0, tft_WIDTH / fontW, tft_HEIGHT / fontH}}; navNode *nodes[sizeof(panels) / sizeof(panel)]; // navNodes to store navigation status panelsList pList(panels, nodes, 1); // a list of panels and nodes idx_t eSpiTops[MAX_DEPTH] = {0}; -#ifdef SUPPORT_TFT TFT_eSPIOut eSpiOut(tft, colors, eSpiTops, pList, fontW, fontH + 1); -menuOut *constMEM outputs[] MEMMODE = {&outSerial, - &eSpiOut}; // list of output devices +menuOut *constMEM outputs[] MEMMODE = {&outSerial, &eSpiOut}; // list of output devices +outputsList out(outputs, sizeof(outputs) / sizeof(menuOut *)); // outputs list controller #endif + #ifdef SUPPORT_OLED -u8g2Out eOledOut(u8g2, colors, eSpiTops, pList, fontW, fontH + 1); -menuOut *constMEM outputs[] MEMMODE = {&outSerial, - &eOledOut}; // list of output devices +// u8g2Out oledOut(u8g2, colors, eSpiTops, pList, fontW, fontH + 1); +// u8g2Out oledOut(u8g2,colors,gfx_tops,gfxPanels,fontX,fontY,offsetX,offsetY,fontMarginX,fontMarginY); +// menuOut *constMEM outputs[] MEMMODE = {&outSerial, &oledOut}; // list of output devices +//define output device oled +idx_t gfx_tops[MAX_DEPTH]; +PANELS(gfxPanels,{0,0,U8_Width/fontX,U8_Height/fontY}); +u8g2Out oledOut(u8g2,colors,gfx_tops,gfxPanels,fontX,fontY,offsetX,offsetY,fontMarginX,fontMarginY); + +//define outputs controller +menuOut* outputs[]{&outSerial,&oledOut};//list of output devices +outputsList out(outputs,sizeof(outputs)/sizeof(menuOut*));//outputs list controller + +MENU_INPUTS(in,&serial); +// MENU_OUTPUTS(out,MAX_DEPTH +// ,U8G2_OUT(u8g2,colors,fontX,fontY,offsetX,offsetY,{0,0,U8_Width/fontX,U8_Height/fontY}) +// ,SERIAL_OUT(Serial) +// ); #endif -outputsList out(outputs, - sizeof(outputs) / sizeof(menuOut *)); // outputs list controller NAVROOT(nav, mainMenu, MAX_DEPTH, serial, out); @@ -760,7 +799,6 @@ void loadTempArraysWithActualValues() { // when menu is suspended result idle(menuOut &o, idleEvent e) { -#if defined SUPPORT_TFT if (e == idleStart) { #ifdef DEBUG_ARDUINOMENU Serial.println("-->[MENU] Event idleStart"); @@ -772,7 +810,12 @@ result idle(menuOut &o, idleEvent e) { Serial.println("-->[MENU] Event iddling"); Serial.flush(); #endif + #if defined SUPPORT_TFT showValuesTFT(co2); + #endif + #if defined SUPPORT_OLED + showValuesOLED(co2); + #endif readBatteryVoltage(); } else if (e == idleEnd) { #ifdef DEBUG_ARDUINOMENU @@ -789,6 +832,24 @@ result idle(menuOut &o, idleEvent e) { #endif } return proceed; +} + +void menuLoop() { +#ifdef SUPPORT_TFT + nav.poll(); // this device only draws when needed +#endif + +#ifdef SUPPORT_OLED + nav.doInput(); + if (nav.sleepTask) { + showValuesOLED(co2); + } else { + if (nav.changed(0)) { + u8g2.firstPage(); + do nav.doOutput(); + while (u8g2.nextPage()); + } + } #endif } diff --git a/CO2_Gadget_OLED.h b/CO2_Gadget_OLED.h index c546b5f5..76eb1a93 100644 --- a/CO2_Gadget_OLED.h +++ b/CO2_Gadget_OLED.h @@ -13,13 +13,21 @@ // clang-format on // #include #include -U8X8_SH1106_128X64_NONAME_HW_I2C u8g2(/* reset=*/U8X8_PIN_NONE); +#include "bootlogo.h" +#include "icons.h" +// U8X8_SH1106_128X64_NONAME_HW_I2C u8g2(/* reset=*/U8X8_PIN_NONE); // U8G2_SSD1306_128X64_NONAME_HW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); - +// U8G2_SSD1306_128X64_VCOMH0_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, I2C_SCL, I2C_SDA);//allow contrast change +// U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, I2C_SCL, I2C_SDA); +// U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); +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 char oled_msg[20]; int displayWidth = 128; int displayHeight = 64; +// #define MENUFONT u8g2_font_6x10_mf +#define MENUFONT u8g2_font_5x8_mf void setOLEDBrightness(uint32_t newBrightness) { Serial.printf("Setting screen brightness value at %d\n (unfunctional. TO DO", newBrightness); @@ -29,48 +37,42 @@ void turnOffDisplay() { setOLEDBrightness(0); // Turn off the display } -void initDisplayOLED() { -#if defined SUPPORT_OLED - u8g2.begin(); - u8g2.setPowerSave(0); - u8g2.setFont(u8x8_font_chroma48medium8_r); - u8g2.drawString(0, 1, " eMariete.com"); - u8g2.drawString(0, 2, " Sensirion"); - u8g2.drawString(0, 3, "CO2 Gadget"); - u8g2.drawString(0, 4, "Concentration Monitor"); -#endif +void displaySplashScreenOLED() { + u8g2.clearDisplay(); + u8g2.firstPage(); + do { + // u8g2.drawXBMP(30, 0, 59, 20, eMarieteLogo); + // u8g2.drawXBM(7, 23, 46, 36, CO2Logo); + // u8g2.drawXBM(60, 32, 61, 23, GadgetLogo); + u8g2.drawXBM(0, 0, 128, 64, splash); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); } -void showValuesOLED(String text) { -#if defined SUPPORT_OLED - u8g2.clearLine(2); - u8g2.clearLine(3); - u8g2.setFont(u8x8_font_chroma48medium8_r); - u8g2.drawString(0, 4, "CO2: "); - u8g2.setFont(u8x8_font_courB18_2x3_r); - sprintf(oled_msg, "%4d", co2); // If parameter string then: co2.c_str() - u8g2.drawString(4, 3, oled_msg); - u8g2.setFont(u8x8_font_chroma48medium8_r); - u8g2.drawString(12, 4, "ppm"); - - u8g2.clearLine(6); - sprintf(oled_msg, "T:%.1fC RH:%.0f%%", temp, hum); - u8g2.drawUTF8(0, 6, oled_msg); +void initDisplayOLED() { + Serial.printf("-->[OLED] Initialized: \t#%s#\n", + ((u8g2.begin()) ? "OK" : "Failed")); + u8g2.firstPage(); + do { + u8g2.setFont(u8g2_font_ncenB12_tr); + u8g2.drawStr(0, 15, " eMariete.com"); + u8g2.drawStr(0, 33, " CO2 Gadget"); + u8g2.drawStr(0, 51, " Air Quality"); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); +} - if (activeWIFI) { - if (WiFi.status() != WL_CONNECTED) { - u8g2.clearLine(7); - u8g2.drawUTF8(0, 6, "WiFi unconnected"); - } else { - u8g2.clearLine(7); - IPAddress ip = WiFi.localIP(); - sprintf(oled_msg, "%s", ip.toString().c_str()); - // sprintf("IP:%u.%u.%u.%u\n", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & - // 0xff, ip >> 24); - u8g2.drawString(0, 7, oled_msg); - } - } -#endif +void showValuesOLED(uint16_t co2) { + u8g2.firstPage(); + do { + u8g2.setFont(u8g2_font_7Segments_26x42_mn); + u8g2.setCursor(0, 44); + u8g2.print(co2); + u8g2.setFont(u8g2_font_5x7_tf); + u8g2.setCursor(110, 51); + u8g2.print("ppm"); + } while (u8g2.nextPage()); + u8g2.setFont(MENUFONT); } #endif // SUPPORT_OLED diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index f68718e2..a350ae8d 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -46,7 +46,7 @@ void initPreferences() { autoSelfCalibration = preferences.getBool("autoSelfCal", false); co2OrangeRange = preferences.getUInt("co2OrangeRange", 700); co2RedRange = preferences.getUInt("co2RedRange", 1000); - DisplayBrightness = preferences.getUInt("DisplayBrightness", 100); + DisplayBrightness = preferences.getUInt("DisplayBright", 100); activeBLE = preferences.getBool("activeBLE", true); activeWIFI = preferences.getBool("activeWIFI", false); activeMQTT = preferences.getBool("activeMQTT", false); @@ -101,7 +101,7 @@ void putPreferences() { preferences.putBool("autoSelfCal", autoSelfCalibration); preferences.putUInt("co2OrangeRange", co2OrangeRange); preferences.putUInt("co2RedRange", co2RedRange); - preferences.putUInt("DisplayBrightness", DisplayBrightness); + preferences.putUInt("DisplayBright", DisplayBrightness); preferences.putBool("activeBLE", activeBLE); preferences.putBool("activeWIFI", activeWIFI); preferences.putBool("activeMQTT", activeMQTT); diff --git a/CO2_Gadget_Sensors.h b/CO2_Gadget_Sensors.h index 7a90ff4b..6183b320 100644 --- a/CO2_Gadget_Sensors.h +++ b/CO2_Gadget_Sensors.h @@ -1,15 +1,5 @@ #include -#undef I2C_SDA -#undef I2C_SCL -#ifdef ALTERNATIVE_I2C_PINS -#define I2C_SDA 22 -#define I2C_SCL 21 -#else -#define I2C_SDA 21 -#define I2C_SCL 22 -#endif - bool firstCO2SensorInit = true; bool pendingCalibration = false; bool newReadingsAvailable = false; @@ -56,7 +46,7 @@ void onSensorDataError(const char *msg) { Serial.println(msg); } void initSensors() { const int8_t None = -1, AUTO = 0, MHZ19 = 4, CM1106 = 5, SENSEAIRS8 = 6, FAKE=127; if (firstCO2SensorInit) { - Serial.printf("-->[SENS] Using CanAirIO Sensorlib v%s Rev:%d", CSL_VERSION, CSL_REVISION); + Serial.printf("-->[SENS] Using sensorlib v%s Rev:%d", CSL_VERSION, CSL_REVISION); firstCO2SensorInit = false; } diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 77f1e35b..6d20b506 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -192,7 +192,6 @@ void showCO2TFT(uint16_t co2) { } void showValuesTFT(uint16_t co2) { -#if defined SUPPORT_TFT if (co2 > 9999) { co2 = 9999; } @@ -215,7 +214,7 @@ void showValuesTFT(uint16_t co2) { // set default font for menu tft.setFreeFont(NULL); tft.setTextSize(2); -#endif } + #endif // SUPPORT_WEBCONFIG #endif // CO2_Gadget_TFT_h \ No newline at end of file diff --git a/bootlogo.h b/bootlogo.h index b48f199d..7399c66a 100644 --- a/bootlogo.h +++ b/bootlogo.h @@ -1,3 +1,5 @@ +#ifdef SUPPORT_TFT + // http://javl.github.io/image2cpp/ // static const unsigned short bootlogo PROGMEM [32400] = { @@ -439,4 +441,127 @@ static const unsigned short GadgetLogo PROGMEM [] = { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffbf, 0x853e, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x3ddf, 0xefdf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffbf, 0x8d5e, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x253e, 0xcf9f, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffbf, 0xbdde, 0x0bfd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x03fd, 0x0cbe, 0x869f, 0xe7bf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, -0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffdf, 0xf7bf, 0xef7f, 0xe75f, 0xd71f, 0xceff, 0xcf1f, 0xd73f, 0xe77f, 0xef9f, 0xf7df, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; \ No newline at end of file +0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffdf, 0xf7bf, 0xef7f, 0xe75f, 0xd71f, 0xceff, 0xcf1f, 0xd73f, 0xe77f, 0xef9f, 0xf7df, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; +#endif + +#ifdef SUPPORT_OLED +// 128x64 +const uint8_t splash[] PROGMEM = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x08,0xc0,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x18,0xc0,0x01,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x1c,0x80,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x1d,0x00,0x01,0x80, + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe5,0x9f,0x43,0x12, + 0x8b,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xe7,0xbf,0xef, + 0xbf,0xef,0xf7,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x6c,0x1a, + 0xcc,0x90,0x99,0xb1,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x6e, + 0x18,0x6c,0xb8,0x9d,0xb9,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0, + 0x6e,0x98,0xcf,0x98,0x8f,0xf1,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xc0,0xe4,0xd8,0xed,0xb8,0x81,0x39,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x80,0x61,0x98,0x4c,0x90,0x81,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0xc0,0x6f,0xb8,0xef,0xb8,0x9f,0xf1,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x47,0x98,0x4d,0x10,0x0e,0x63,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x06,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x00,0x03,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc7,0x87,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x0f,0xf2,0x3e, + 0x81,0x0f,0xe0,0x0f,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x1f,0x18, + 0x3e,0xc0,0x3f,0xf0,0x0f,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x0d, + 0x0c,0x76,0x80,0x3f,0xf8,0x06,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x70, + 0x00,0xc6,0xdf,0x00,0x38,0x38,0x00,0x00,0xe0,0x00,0x00,0x00,0x03,0x00,0x00, + 0x70,0x00,0xe6,0xfd,0x01,0x38,0x38,0x00,0x00,0xe0,0x00,0x00,0x80,0x03,0x00, + 0x00,0x78,0x00,0x63,0xf7,0x01,0x38,0x78,0x00,0x0b,0xfa,0xf0,0xc3,0x85,0x03, + 0x00,0x00,0x70,0x68,0xf2,0xdf,0x28,0x38,0x38,0x80,0x1f,0xff,0xfc,0xe7,0xe7, + 0x1f,0x00,0x00,0x78,0x78,0xb2,0xfd,0x7d,0x3c,0x3c,0x80,0x3f,0xef,0xdc,0xf1, + 0xee,0x0b,0x00,0x00,0x70,0x00,0xf7,0xb7,0x01,0x1c,0x38,0x08,0x38,0xe7,0x8c, + 0x73,0x8e,0x03,0x00,0x00,0x78,0x00,0x7e,0xff,0x01,0x1e,0x78,0x1c,0xb8,0xe3, + 0x8e,0x73,0x8e,0x03,0x00,0x00,0x70,0x00,0xde,0xbb,0x01,0x0f,0x3c,0x1c,0x3d, + 0xe7,0x9c,0xf3,0x8f,0x03,0x00,0x00,0x78,0x00,0xf6,0xfe,0x00,0x07,0x38,0x9c, + 0xbf,0xe7,0x8c,0xf3,0x85,0x03,0x00,0x00,0x70,0x00,0xfc,0xef,0x80,0x07,0x78, + 0x9c,0x31,0xe3,0xfc,0x71,0x80,0x03,0x00,0x00,0xf0,0x00,0xdc,0x3d,0xc0,0x13, + 0x78,0xdc,0xb9,0xe7,0xf8,0x71,0x80,0x03,0x00,0x00,0xf0,0x1f,0x71,0x6f,0xc1, + 0x7f,0xf0,0x9f,0x3d,0xf7,0x38,0xe0,0x84,0x03,0x00,0x00,0xe0,0x9f,0xf3,0x1f, + 0xc3,0x7f,0xf0,0x9f,0x3f,0xff,0xb8,0xe0,0x9f,0x03,0x00,0x00,0x80,0x85,0xe0, + 0x16,0x86,0x2a,0x40,0x17,0x33,0x4e,0xfc,0xc3,0x07,0x03,0x00,0x00,0x00,0x00, + 0xb0,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0xd0,0x03,0x00,0x00,0x00,0x00,0x00, + 0x00,0xe0,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00, + 0x00,0x00,0x60,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0xdc,0x03,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x03,0x00,0x00, + 0x00,0x00,0x00,0x00,0xc0,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x00, + 0xf0,0x03,0x00,0x00,0x00,0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0xfc,0x0f,0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0xfe,0x3f,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0xff,0x3f,0x00,0x00,0x00,0x80,0x05,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0xff,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x80,0xff,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x14,0x00,0x00,0xc0,0xff,0xff,0x00,0x00,0x00,0x00,0x01,0x00,0x00, + 0x00,0x00,0x00,0x52,0x00,0x00,0xc0,0x3f,0xfe,0x00,0x00,0x00,0x00,0x0c,0x00, + 0x00,0x00,0x00,0x00,0x18,0x00,0x00,0xc0,0x1f,0xfe,0x00,0x00,0x00,0x00,0x30, + 0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0xc0,0x1f,0xfe,0x00,0x00,0x00,0x00, + 0xc0,0x03,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0xc0,0x1f,0xfe,0x00,0x00,0x00, + 0x00,0x00,0x2f,0x00,0x00,0x00,0xc0,0x03,0x00,0x00,0x80,0x3f,0xff,0x00,0x00, + 0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,0x80,0x3f,0x7f,0x00, + 0x00,0x00,0x00,0x00,0xe0,0x1f,0x00,0x80,0x7e,0x00,0x00,0x00,0x80,0x3f,0x7f, + 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xaf,0xfe,0x0f,0x00,0x00,0x00,0x00,0x1f, + 0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0xff,0xff,0x01,0x00,0x00,0x00,0x00, + 0x1e,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xfe,0x17,0x00,0x00,0x00,0x00, + 0x00,0x1c,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00 }; + +// 59x20 +const uint8_t eMarieteLogo[] PROGMEM = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x30,0x18,0x00,0x50, + 0x00,0x03,0x00,0x00,0x10,0x10,0x00,0x10,0x00,0x01,0x00,0x40,0x30,0x18,0x00, + 0x00,0x00,0x01,0x00,0x10,0x52,0x14,0x08,0x10,0x84,0x02,0x00,0x00,0x54,0x94, + 0xc7,0x13,0xa3,0xe5,0x01,0xe4,0x50,0x14,0x44,0xa4,0x0c,0x05,0x02,0x20,0x51, + 0x94,0x28,0x92,0x0a,0x61,0x01,0xa2,0x52,0xca,0x4c,0x90,0x02,0xa1,0x02,0x20, + 0x90,0x92,0x48,0x90,0x08,0x21,0x02,0x90,0xa8,0x8a,0x24,0x90,0x08,0x21,0x02, + 0xa4,0x90,0x92,0x4c,0x10,0x85,0xa2,0x02,0x40,0x14,0x29,0x43,0x20,0x0b,0x41, + 0x01,0x08,0x02,0x00,0x08,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + +// 46x36 +const uint8_t CO2Logo[] PROGMEM = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x40, + 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00, + 0x00,0x10,0x00,0x80,0x00,0x00,0x00,0x30,0x00,0x40,0x01,0x00,0x00,0x40,0xe8, + 0xa1,0x00,0x00,0x00,0x00,0x9a,0x06,0x00,0x00,0x68,0x81,0x82,0x0d,0x40,0x05, + 0xd4,0x02,0x41,0x35,0x40,0x0b,0x0c,0xc0,0xa8,0x2d,0x40,0x0c,0x0a,0x80,0xb8, + 0x5a,0x00,0x18,0x0a,0x40,0xd4,0x55,0x00,0x14,0x0a,0xa2,0xac,0x2e,0x04,0x08, + 0x06,0x4d,0xb4,0x75,0x1a,0x0c,0x02,0xa2,0x6a,0x2d,0x02,0x14,0x06,0x40,0x5d, + 0x6b,0x00,0x06,0x0a,0xc0,0xd6,0x5a,0x00,0x05,0x0a,0x40,0xb5,0x35,0x00,0x03, + 0x06,0x80,0x6b,0x2b,0x80,0x02,0x04,0x00,0x5d,0x1d,0x40,0x01,0x0a,0x00,0xab, + 0x05,0xc0,0x00,0x0c,0x20,0x74,0x4b,0xa0,0x0a,0xf4,0x31,0xaa,0xc6,0x60,0x15, + 0x50,0x11,0xdc,0x02,0x81,0x0a,0x00,0x00,0x54,0x03,0x00,0x00,0x00,0x00,0xb4, + 0x06,0x00,0x00,0x00,0x00,0xa8,0x01,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, + 0x00,0x00,0xd8,0x01,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0xd8, + 0x01,0x00,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00 }; + +// 61x23 +const uint8_t GadgetLogo[] PROGMEM = { + 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xec,0x01,0x00,0x30,0x00,0x00,0x00, + 0x00,0x14,0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x30,0x00,0x00, + 0x00,0x00,0x06,0x00,0x00,0x20,0x00,0x00,0x00,0x02,0x02,0x00,0x00,0x10,0x00, + 0x00,0x00,0x01,0x06,0x40,0x01,0x36,0xb4,0xc1,0x82,0x0a,0x0a,0xa0,0x87,0x55, + 0x6a,0xa1,0xa2,0x03,0x06,0x00,0x84,0x10,0x82,0x30,0x06,0x02,0x02,0x02,0x4c, + 0x31,0x86,0x21,0x84,0x02,0x06,0x01,0xc4,0x20,0x82,0x30,0x0c,0x01,0x0a,0x43, + 0x8b,0x30,0x86,0xd1,0x03,0x03,0x06,0xa2,0x4c,0x11,0x44,0x31,0x00,0x01,0x02, + 0x25,0x84,0x31,0xba,0x20,0x80,0x02,0x0e,0x23,0x4c,0x20,0x28,0x50,0x00,0x01, + 0xa8,0x62,0x8a,0x59,0x08,0x20,0x00,0x03,0xb4,0x41,0x85,0x16,0x94,0xe0,0x0e, + 0x01,0x40,0x82,0x08,0x20,0x74,0x01,0x01,0x02,0x00,0x00,0x00,0x00,0x80,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x88, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x01,0x00,0x00,0x00,0x00,0x00,0x00, + 0x04,0x00,0x00,0x00 }; +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 052a6620..38cb1122 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,24 +18,25 @@ default_envs = esp32dev, esp32dev-sandwich, TTGO_TDISPLAY, TTGO_TDISPLAY_SANDWIC framework = arduino upload_speed = 921600 monitor_speed = 115200 -monitor_port = COM13 -upload_port = COM13 +monitor_port = COM6 +upload_port = COM6 monitor_filters = time board_build.partitions = CO2_Gadget_Partitions.csv ; Others at Windows at C:\Users\%USER%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.5\tools\partitions ; board_build.partitions = min_spiffs.csv lib_deps = - ESP Async WebServer + me-no-dev/ESP Async WebServer @ ^1.2.3 lennarthennigs/Button2@^1.6.5 ; git+https://github.com/kike-canaries/canairio_sensorlib.git#devel hpsaturn/CanAirIO Air Quality Sensors Library@^0.4.2 ; D:\Documentos\PlatformIO\Projects\arduino-ble-gadget\src git+https://github.com/melkati/arduino-ble-gadget.git#setSampleIntervalMs ; sensirion/Sensirion Gadget BLE Arduino Lib@^0.10.0 - https://github.com/Bodmer/TFT_eSPI.git + bodmer/TFT_eSPI @ ^2.3.89 ; https://github.com/melkati/TFT_eSPI.git - neu-rah/ArduinoMenu library@^4.21.3 + neu-rah/ArduinoMenu library @ ^4.21.4 + neu-rah/streamFlow @ 0.0.0-alpha+sha.bf16ce8926 knolleary/PubSubClient @ ^2.8 - https://github.com/rlogiacco/BatterySense.git + rlogiacco/Battery Sense @ ^1.1.2 build_flags = ; If you want you can keep sensitive data in a file, you can define it in environment variables so you don't need a credentials.h file with your secrets ; @@ -52,17 +53,16 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.5."\" - -D CO2_GADGET_REV="\"000-Feature-OLED"\" + -D CO2_GADGET_REV="\"004-Feature-OLED"\" -D CORE_DEBUG_LEVEL=0 - -D TTGO_TDISPLAY=1 -D ENABLE_PIN=27 ; Reserved for the future to enable the sensor - -D BACKLIGHT_PIN=4 ; Pin used for backlight -D ENABLE_PIN_HIGH=1 ; Should be ENABLE_PIN high or low to enable the sensor? -D WIFI_PRIVACY ; Uncomment to hide WiFi password in the menu -; -D SUPPORT_OTA ; Needs SUPPORT_WIFI - CURRENTLY NOT WORKING AWAITING FIX +; -D SUPPORT_OTA ; Needs SUPPORT_WIFI - CURRENTLY NOT WORKING ; -D SUPPORT_MDNS ; Needs SUPPORT_WIFI -D SUPPORT_MQTT ; Needs SUPPORT_WIFI -; -D DEBUG_ARDUINOMENU + -D DEBUG_ARDUINOMENU +; -D MENU_DEBUG ; Needs streamFlow library [env:esp32dev] platform = espressif32 @@ -111,8 +111,10 @@ lib_deps = ${common_env_data.lib_deps} build_flags = ${common_env_data.build_flags} - -Os + -Os -D SUPPORT_TFT + -D TTGO_TDISPLAY=1 + -D BACKLIGHT_PIN=4 ; Pin used for backlight -DUSER_SETUP_LOADED=1 -DST7789_DRIVER=1 -DENABLE_TFT=1 @@ -154,6 +156,8 @@ build_flags = ${common_env_data.build_flags} -Os -D SUPPORT_TFT + -D TTGO_TDISPLAY=1 + -D BACKLIGHT_PIN=4 ; Pin used for backlight -DUSER_SETUP_LOADED=1 -DST7789_DRIVER=1 -DENABLE_TFT=1 @@ -195,5 +199,5 @@ lib_deps = olikraus/U8g2@^2.32.6 build_flags = ${common_env_data.build_flags} - -D UNITHOSTNAME="\"CO2-Gadget"\" + -D UNITHOSTNAME="\"CO2-Gadget-OLED"\" -D SUPPORT_OLED \ No newline at end of file From ffa5b5d074de8fd73e45427ee824fbbd9eacd7a1 Mon Sep 17 00:00:00 2001 From: "eMariete.com" Date: Fri, 17 Dec 2021 21:53:53 +0100 Subject: [PATCH 3/3] Some code clean up --- CO2_Gadget.ino | 1 - CO2_Gadget_Menu.h | 62 ++++++++++++++++++----------------------------- platformio.ini | 8 +++--- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 6df07c03..88676ad8 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -268,7 +268,6 @@ void setup() { initPreferences(); initBattery(); #if defined SUPPORT_OLED - delay(100); initDisplayOLED(); delay(1000); displaySplashScreenOLED(); diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index c5e75f2f..5a12a5b5 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -568,6 +568,13 @@ MENU(mainMenu, "CO2 Gadget", doNothing, noEvent, wrapStyle ,SUBMENU(subMenu) ,EXIT(" colors[6] MEMMODE = { {{(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)DarkerOrange, (uint16_t)Red}}, // titleColor - Menu title color }; + +#define tft_WIDTH 240 +#define tft_HEIGHT 135 +#define fontW 12 +#define fontH 18 + +const panel panels[] MEMMODE = {{0, 0, tft_WIDTH / fontW, tft_HEIGHT / fontH}}; +navNode *nodes[sizeof(panels) / + sizeof(panel)]; // navNodes to store navigation status +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 +outputsList out(outputs, sizeof(outputs) / sizeof(menuOut *)); // outputs list controller #endif #ifdef SUPPORT_OLED @@ -624,25 +645,7 @@ const colorDef colors[6] MEMMODE={ {{0,1},{0,0,1}},//cursorColor {{1,1},{1,0,0}},//titleColor }; -#endif -// clang-format on - -#define MAX_DEPTH 4 - -serialIn serial(Serial); -// define serial output device -idx_t serialTops[MAX_DEPTH] = {0}; -serialOut outSerial(Serial, serialTops); - -#ifdef SUPPORT_TFT -#define tft_WIDTH 240 -#define tft_HEIGHT 135 -#define fontW 12 -#define fontH 18 -#endif - -#ifdef SUPPORT_OLED #define fontX 5 #define fontY 10 // #define MENUFONT u8g2_font_7x13_mf @@ -655,23 +658,7 @@ serialOut outSerial(Serial, serialTops); #define USE_HWI2C #define fontMarginX 2 #define fontMarginY 2 -#endif -#ifdef SUPPORT_TFT -const panel panels[] MEMMODE = {{0, 0, tft_WIDTH / fontW, tft_HEIGHT / fontH}}; -navNode *nodes[sizeof(panels) / - sizeof(panel)]; // navNodes to store navigation status -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 -outputsList out(outputs, sizeof(outputs) / sizeof(menuOut *)); // outputs list controller -#endif - -#ifdef SUPPORT_OLED -// u8g2Out oledOut(u8g2, colors, eSpiTops, pList, fontW, fontH + 1); -// u8g2Out oledOut(u8g2,colors,gfx_tops,gfxPanels,fontX,fontY,offsetX,offsetY,fontMarginX,fontMarginY); -// menuOut *constMEM outputs[] MEMMODE = {&outSerial, &oledOut}; // list of output devices //define output device oled idx_t gfx_tops[MAX_DEPTH]; PANELS(gfxPanels,{0,0,U8_Width/fontX,U8_Height/fontY}); @@ -682,11 +669,8 @@ menuOut* outputs[]{&outSerial,&oledOut};//list of output devices outputsList out(outputs,sizeof(outputs)/sizeof(menuOut*));//outputs list controller MENU_INPUTS(in,&serial); -// MENU_OUTPUTS(out,MAX_DEPTH -// ,U8G2_OUT(u8g2,colors,fontX,fontY,offsetX,offsetY,{0,0,U8_Width/fontX,U8_Height/fontY}) -// ,SERIAL_OUT(Serial) -// ); #endif +// clang-format on NAVROOT(nav, mainMenu, MAX_DEPTH, serial, out); @@ -854,7 +838,7 @@ void menuLoop() { } void menu_init() { - nav.idleTask = idle; // function to be used when menu is suspended + nav.idleTask = idle; // function to be called when menu is suspended nav.idleOn(idle); nav.timeOut = 30; nav.showTitle = true; diff --git a/platformio.ini b/platformio.ini index 38cb1122..f146a960 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,8 +18,8 @@ default_envs = esp32dev, esp32dev-sandwich, TTGO_TDISPLAY, TTGO_TDISPLAY_SANDWIC framework = arduino upload_speed = 921600 monitor_speed = 115200 -monitor_port = COM6 -upload_port = COM6 +monitor_port = COM13 +upload_port = COM13 monitor_filters = time board_build.partitions = CO2_Gadget_Partitions.csv ; Others at Windows at C:\Users\%USER%\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.5\tools\partitions ; board_build.partitions = min_spiffs.csv @@ -34,7 +34,7 @@ lib_deps = bodmer/TFT_eSPI @ ^2.3.89 ; https://github.com/melkati/TFT_eSPI.git neu-rah/ArduinoMenu library @ ^4.21.4 - neu-rah/streamFlow @ 0.0.0-alpha+sha.bf16ce8926 + ; neu-rah/streamFlow @ 0.0.0-alpha+sha.bf16ce8926 ; Needed for -D MENU_DEBUG knolleary/PubSubClient @ ^2.8 rlogiacco/Battery Sense @ ^1.1.2 build_flags = @@ -53,7 +53,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.5."\" - -D CO2_GADGET_REV="\"004-Feature-OLED"\" + -D CO2_GADGET_REV="\"005-Feature-OLED"\" -D CORE_DEBUG_LEVEL=0 -D ENABLE_PIN=27 ; Reserved for the future to enable the sensor -D ENABLE_PIN_HIGH=1 ; Should be ENABLE_PIN high or low to enable the sensor?