From c57111e76397129c3388ef51ea157f221d46bce0 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 15 Jan 2025 17:51:45 +0100 Subject: [PATCH 1/3] migrated to M5Stack Unified Library. (fail in execution) --- lib/batterylib/battery_m5stack.cpp | 19 ++++++++++--------- lib/batterylib/battery_m5stack.hpp | 4 ++-- lib/gui-utils-tft/src/TFTUtils.cpp | 21 ++++++++++++++++----- lib/gui-utils-tft/src/TFTUtils.hpp | 8 +++++--- lib/power/power.cpp | 6 +++--- platformio.ini | 3 ++- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/lib/batterylib/battery_m5stack.cpp b/lib/batterylib/battery_m5stack.cpp index 2d98eace..d327d1b2 100644 --- a/lib/batterylib/battery_m5stack.cpp +++ b/lib/batterylib/battery_m5stack.cpp @@ -4,7 +4,7 @@ void Battery_M5STACK::init(bool debug) { this->debug = debug; - M5.Axp.EnableCoulombcounter(); // Enable Coulomb counter. + // M5.Axp.EnableCoulombcounter(); // Enable Coulomb counter. setLimits(BATTERY_MIN_V, BATTERY_MAX_V, BATTCHARG_MIN_V, BATTCHARG_MAX_V); } @@ -13,12 +13,12 @@ float Battery_M5STACK::getVoltage() { } void Battery_M5STACK::update() { - curv = M5.Axp.GetBatVoltage(); - vusb = M5.Axp.GetVBusVoltage(); + curv = M5.Power.getBatteryVoltage(); + // vusb = M5.Power.getUsbOutput(); } bool Battery_M5STACK::isCharging() { - return M5.axp.GetVBusVoltage() > btCharVMax; + return M5.Power.getUsbOutput(); } int Battery_M5STACK::getCharge() { @@ -31,11 +31,12 @@ int Battery_M5STACK::getCharge() { void Battery_M5STACK::printValues() { if (!debug) return; - Serial.printf("-->[BATT] AXP Temp \t: %.1fC \tC: %03d\r\n", M5.Axp.GetTempInAXP192(), getCharge()); //Get the temperature of AXP192 - Serial.printf("-->[BATT] AXP Bat Volts \t: %.3fv \tI: %.3fma\r\n", curv, M5.Axp.GetBatCurrent()); //Output voltage and current of Bat - Serial.printf("-->[BATT] AXP USB Volts \t: %.3fv \tI: %.3fma\r\n", M5.Axp.GetVBusVoltage(), M5.Axp.GetVBusCurrent()); //Output current and voltage of USB - Serial.printf("-->[BATT] AXP 5V Volts \t: %.3fv \tI: %.3fma\r\n", M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent()); - Serial.printf("-->[BATT] AXP Bat power \t: %.3fmw\r\n", M5.Axp.GetBatPower()); + // Serial.printf("-->[BATT] AXP Temp \t: %.1fC \tC: %03d\r\n", M5.Power.GetTempInAXP192(), getCharge()); //Get the temperature of AXP192 + Serial.printf("-->[BATT] AXP Bat Volts \t: %.3fv \tI: %.3fma\r\n", curv, M5.Power.getBatteryVoltage()); //Output voltage and current of Bat + // Serial.printf("-->[BATT] AXP USB Volts \t: %.3fv \tI: %.3fma\r\n", M5.Axp.GetVBusVoltage(), M5.Axp.GetVBusCurrent()); //Output current and voltage of USB + Serial.printf("-->[BATT] AXP Bat Level \t: %.3fv \tI: %.3fma\r\n", M5.Power.getBatteryLevel(), M5.Power.getBatteryCurrent()); + // Serial.printf("-->[BATT] AXP 5V Volts \t: %.3fv \tI: %.3fma\r\n", M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent()); + // Serial.printf("-->[BATT] AXP Bat power \t: %.3fmw\r\n", M5.Axp.GetBatPower()); } #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_M5STACKBATTERY) diff --git a/lib/batterylib/battery_m5stack.hpp b/lib/batterylib/battery_m5stack.hpp index 9eac1cb3..8e8adf9e 100644 --- a/lib/batterylib/battery_m5stack.hpp +++ b/lib/batterylib/battery_m5stack.hpp @@ -3,7 +3,7 @@ #include #ifdef M5STICKCPLUS -#include +#include #endif #define BATTERY_MIN_V 3.4 @@ -13,7 +13,7 @@ class Battery_M5STACK : public Battery { public: - float vusb = 0.0; + // float vusb = 0.0; void init(bool debug = false); float getVoltage(); float getCurrent(); diff --git a/lib/gui-utils-tft/src/TFTUtils.cpp b/lib/gui-utils-tft/src/TFTUtils.cpp index d4a576af..94684b0d 100644 --- a/lib/gui-utils-tft/src/TFTUtils.cpp +++ b/lib/gui-utils-tft/src/TFTUtils.cpp @@ -31,8 +31,17 @@ void TFTUtils::displayInit() { pinMode(BUTTON_L, INPUT_PULLUP); pinMode(BUTTON_R, INPUT); #ifdef M5STICKCPLUS - M5.begin(true,true,false); // Initialize M5Stack without serial messages - M5.Beep.end(); + auto cfg = M5.config(); + M5.begin(cfg); + M5.Display.setBrightness(50); + int w = M5.Display.width(); + int h = M5.Display.height(); + tft.createSprite(w, h); + // tft.fillRect(0, 0, w, 20, tft.color565(50, 50, 50)); + // tft.pushSprite(&M5.Display, 0, 0); + + // M5.begin(true,true,false); // Initialize M5Stack without serial messages + // M5.Beep.end(); pinMode(36, INPUT); // UART port alternative for this board gpio_pulldown_dis(GPIO_NUM_25); // 36 and 25 pins share the same port gpio_pullup_dis(GPIO_NUM_25); // https://docs.m5stack.com/en/core/m5stickc_plus @@ -250,7 +259,8 @@ void TFTUtils::updateBrightness() { void TFTUtils::invertScreen(){ inv = !inv; - tft.invertDisplay(inv); + M5.Display.invertDisplay(inv); + // tft.invertDisplay(inv); updateInvertValue(); if(mGUICallBacks != nullptr) getInstance()->mGUICallBacks->onColorsInverted(inv); } @@ -453,7 +463,7 @@ void TFTUtils::suspend() { welcomeAddMessage("Suspending.."); delay(2000); #ifdef M5STICKCPLUS - M5.Axp.PowerOff(); + M5.Power.powerOff(); #else int r = digitalRead(TFT_BL); digitalWrite(TFT_BL, !r); @@ -862,7 +872,8 @@ void TFTUtils::setBrightness(uint32_t value) { void TFTUtils::notifyBrightness() { #ifdef M5STICKCPLUS - M5.Axp.ScreenBreath(brightness); + // M5.Axp.ScreenBreath(brightness); + M5.Display.setBrightness(brightness); #else ledcWrite(pwmLedChannelTFT, brightness); #endif diff --git a/lib/gui-utils-tft/src/TFTUtils.hpp b/lib/gui-utils-tft/src/TFTUtils.hpp index e37e668f..44531030 100644 --- a/lib/gui-utils-tft/src/TFTUtils.hpp +++ b/lib/gui-utils-tft/src/TFTUtils.hpp @@ -3,7 +3,7 @@ #include #ifdef M5STICKCPLUS -#include +#include #else #include #endif @@ -50,9 +50,11 @@ class GUIUserPreferencesCallbacks; class TFTUtils { public: TFTUtils(void){}; - +#ifndef M5STICKCPLUS TFT_eSPI tft = TFT_eSPI(); // Invoke custom library - +#else + M5Canvas tft; +#endif enum WIFI_MODE { WIFI_OFF, WIFI_ON }; void displayInit(); diff --git a/lib/power/power.cpp b/lib/power/power.cpp index c726d193..6df899a3 100644 --- a/lib/power/power.cpp +++ b/lib/power/power.cpp @@ -29,7 +29,7 @@ void powerCompleteShutdown(){ esp_deep_sleep_start(); #endif #ifdef M5STICKCPLUS - M5.Axp.PowerOff(); + M5.Power.powerOff(); #endif } @@ -48,7 +48,7 @@ void powerDeepSleepTimer(int seconds) { Serial.flush(); prepairShutdown(); #ifdef M5STICKCPLUS - M5.Axp.DeepSleep(seconds*1000000); + M5.Power.deepSleep(seconds*1000000); #endif esp_sleep_enable_timer_wakeup(seconds * 1000000ULL); #ifdef TTGO_TDISPLAY @@ -65,7 +65,7 @@ void powerLightSleepTimer(int seconds) { esp_light_sleep_start(); #endif #ifdef M5STICKCPLUS - M5.Axp.LightSleep(seconds*1000000); + M5.Power.lightSleep(seconds*1000000); #endif } diff --git a/platformio.ini b/platformio.ini index cb664cf8..f76ae043 100644 --- a/platformio.ini +++ b/platformio.ini @@ -119,7 +119,8 @@ lib_ignore = extends = tft_common lib_deps = ${common.lib_deps} - https://github.com/hpsaturn/M5StickC-Plus.git + m5stack/M5Unified@0.1.10 + ; https://github.com/hpsaturn/M5StickC-Plus.git [env:TTGO_TDISPLAY] extends = tft_common From 05b47a42c966967b9ab235ec1e24a5ecca0d1827 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 15 Jan 2025 19:33:09 +0100 Subject: [PATCH 2/3] fix compiling issue #281 but is working but have font issues --- lib/gui-utils-tft/src/TFTUtils.cpp | 69 +++++++++++++++--------------- lib/gui-utils-tft/src/TFTUtils.hpp | 5 +-- platformio.ini | 2 - 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/lib/gui-utils-tft/src/TFTUtils.cpp b/lib/gui-utils-tft/src/TFTUtils.cpp index 94684b0d..925c8d5a 100644 --- a/lib/gui-utils-tft/src/TFTUtils.cpp +++ b/lib/gui-utils-tft/src/TFTUtils.cpp @@ -33,15 +33,9 @@ void TFTUtils::displayInit() { #ifdef M5STICKCPLUS auto cfg = M5.config(); M5.begin(cfg); - M5.Display.setBrightness(50); - int w = M5.Display.width(); - int h = M5.Display.height(); - tft.createSprite(w, h); - // tft.fillRect(0, 0, w, 20, tft.color565(50, 50, 50)); - // tft.pushSprite(&M5.Display, 0, 0); - - // M5.begin(true,true,false); // Initialize M5Stack without serial messages - // M5.Beep.end(); + tft = M5.Display; + tft.setBrightness(80); + M5.update(); pinMode(36, INPUT); // UART port alternative for this board gpio_pulldown_dis(GPIO_NUM_25); // 36 and 25 pins share the same port gpio_pullup_dis(GPIO_NUM_25); // https://docs.m5stack.com/en/core/m5stickc_plus @@ -62,8 +56,8 @@ void TFTUtils::displayInit() { void TFTUtils::showWelcome() { tft.fillScreen(TFT_BLACK); tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK); - tft.setFreeFont(&Orbitron_Medium_20); tft.setCursor(2,20); + tft.setFont(&Orbitron_Medium_20); tft.print("CanAirIO "); tft.setTextFont(2); tft.setTextColor(TFT_WHITE, TFT_BLACK); @@ -106,18 +100,19 @@ void TFTUtils::showStatus() { void TFTUtils::showMain() { showStatus(); - tft.setCursor(RCOLSTART, 204, 1); + tft.setTextFont(1); + tft.setCursor(RCOLSTART, 204); tft.println("BATT:"); updateBatteryValue(); - - tft.setCursor(RCOLSTART, 152, 2); + tft.setTextFont(2); + tft.setCursor(RCOLSTART, 152); tft.println("HEALTH:"); tft.setTextColor(TFT_WHITE, lightblue); - tft.setCursor(4, 152, 2); + tft.setCursor(4, 152); tft.println("TEMP:"); - tft.setCursor(4, 192, 2); + tft.setCursor(4, 192); tft.println("HUM: "); tft.fillRect(68, 152, 1, 74, TFT_GREY); @@ -140,18 +135,20 @@ void TFTUtils::showWindowBike(){ holdR = 0; delay(100); showStatus(); - tft.setCursor(80, 204, 1); + tft.setTextFont(1); + tft.setCursor(80, 204); tft.println("BATT:"); updateBatteryValue(); - tft.setCursor(80, 152, 2); + tft.setTextFont(2); + tft.setCursor(80, 152); tft.println("HEALTH:"); tft.setTextColor(TFT_WHITE, lightblue); - tft.setCursor(4, 152, 2); + tft.setCursor(4, 152); tft.println("KM:"); - tft.setCursor(4, 192, 2); + tft.setCursor(4, 192); tft.println("TIME: "); tft.fillRect(68, 152, 1, 74, TFT_GREY); @@ -183,7 +180,7 @@ void TFTUtils::refreshInfoWindow() { tft.setTextFont(2); tft.setTextPadding(5); tft.setTextDatum(CR_DATUM); - tft.setCursor(0, 50, 2); + tft.setCursor(0, 50); tft.println(_info); } @@ -198,26 +195,27 @@ void TFTUtils::showSetup() { tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.drawLine(18,44,117,44,TFT_GREY); + tft.setTextFont(2); tft.setTextColor(TFT_WHITE, lightblue); - tft.setCursor(MARGINL, SSTART, 2); + tft.setCursor(MARGINL, SSTART); tft.println("BRIGHT:"); - tft.setCursor(MARGINL, SSTART+PRESETH, 2); + tft.setCursor(MARGINL, SSTART+PRESETH); tft.println("COLORS:"); - tft.setCursor(MARGINL, SSTART+PRESETH*2, 2); + tft.setCursor(MARGINL, SSTART+PRESETH*2); tft.println("WiFi:"); - tft.setCursor(MARGINL, SSTART+PRESETH*3, 2); + tft.setCursor(MARGINL, SSTART+PRESETH*3); tft.println("STIME:"); - tft.setCursor(MARGINL, SSTART+PRESETH*4, 2); + tft.setCursor(MARGINL, SSTART+PRESETH*4); tft.println("CALIBRT:"); - tft.setCursor(MARGINL, SSTART+PRESETH*5, 2); + tft.setCursor(MARGINL, SSTART+PRESETH*5); tft.println("INFO:"); - tft.setCursor(MARVALL, SSTART+PRESETH*5, 2); + tft.setCursor(MARVALL, SSTART+PRESETH*5); tft.println(String(VERSION)); updateInvertValue(); @@ -259,8 +257,7 @@ void TFTUtils::updateBrightness() { void TFTUtils::invertScreen(){ inv = !inv; - M5.Display.invertDisplay(inv); - // tft.invertDisplay(inv); + tft.invertDisplay(inv); updateInvertValue(); if(mGUICallBacks != nullptr) getInstance()->mGUICallBacks->onColorsInverted(inv); } @@ -268,7 +265,8 @@ void TFTUtils::invertScreen(){ void TFTUtils::updateInvertValue(){ tft.fillRect(MARVALL, SSTART+PRESETH, 54, 13, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setCursor(MARVALL, SSTART+PRESETH, 2); + tft.setTextFont(2); + tft.setCursor(MARVALL, SSTART+PRESETH); if(inv) tft.println("normal"); else tft.println("inverted"); } @@ -312,7 +310,8 @@ void TFTUtils::updateWifiMode(){ if (state < 1) return; tft.fillRect(MARVALL, SSTART+PRESETH*2, 54, 13, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setCursor(MARVALL, SSTART+PRESETH*2, 2); + tft.setTextFont(2); + tft.setCursor(MARVALL, SSTART+PRESETH*2); if(_wifi_enable) tft.println("On"); else if (_pax_enable) tft.println("PAX"); else tft.println("Off"); @@ -334,7 +333,8 @@ void TFTUtils::updateSampleTime() { if (state < 1) return; tft.fillRect(MARVALL, SSTART + PRESETH * 3, 54, 13, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setCursor(MARVALL, SSTART + PRESETH * 3, 2); + tft.setTextFont(2); + tft.setCursor(MARVALL, SSTART + PRESETH * 3); tft.println("" + String(_sample_time) + "s"); } @@ -344,7 +344,8 @@ void TFTUtils::updateCalibrationField(){ calibretts = millis(); tft.fillRect(MARVALL, SSTART + PRESETH * 4, 54, 13, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setCursor(MARVALL, SSTART + PRESETH * 4, 2); + tft.setTextFont(2); + tft.setCursor(MARVALL, SSTART + PRESETH * 4); if (_calibration_counter > 0){ log_i("[TGUI] coundown to calibration: %i",_calibration_counter); tft.println("" + String(_calibration_counter--) + "s"); @@ -493,7 +494,7 @@ void TFTUtils::displayMainUnit(String uName, String uSymbol) { void TFTUtils::displayBottomLine(String msg) { tft.setTextFont(1); tft.fillRect(1, 230, 99, 8, TFT_BLACK); - tft.setCursor(2, 232, 1); + tft.setCursor(2, 232); tft.println(msg.substring(0,16).c_str()); } diff --git a/lib/gui-utils-tft/src/TFTUtils.hpp b/lib/gui-utils-tft/src/TFTUtils.hpp index 44531030..5137ee3d 100644 --- a/lib/gui-utils-tft/src/TFTUtils.hpp +++ b/lib/gui-utils-tft/src/TFTUtils.hpp @@ -53,7 +53,7 @@ class TFTUtils { #ifndef M5STICKCPLUS TFT_eSPI tft = TFT_eSPI(); // Invoke custom library #else - M5Canvas tft; + M5GFX tft; #endif enum WIFI_MODE { WIFI_OFF, WIFI_ON }; @@ -134,8 +134,7 @@ class TFTUtils { const int pwmLedChannelTFT = 0; #ifdef M5STICKCPLUS - int backlight[5] = {5, 20, 30, 50, 80}; - + int backlight[5] = {60, 65, 70, 90, 120}; #else int backlight[5] = {10, 30, 60, 120, 220}; #endif diff --git a/platformio.ini b/platformio.ini index f80b7a97..9b98ec10 100644 --- a/platformio.ini +++ b/platformio.ini @@ -116,12 +116,10 @@ lib_ignore = lorawan [env:M5STICKCPLUS] -platform = espressif32 @ 6.9.0 extends = tft_common lib_deps = ${common.lib_deps} m5stack/M5Unified@0.1.10 - ; https://github.com/hpsaturn/M5StickC-Plus.git [env:TTGO_TDISPLAY] extends = tft_common From a15ccc82cbaffec8af1dd5eb24048489a95722cc Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 15 Jan 2025 19:49:16 +0100 Subject: [PATCH 3/3] restored primitive call for TFTeSPI old API --- lib/gui-utils-tft/src/TFTUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gui-utils-tft/src/TFTUtils.cpp b/lib/gui-utils-tft/src/TFTUtils.cpp index 925c8d5a..c1ee043e 100644 --- a/lib/gui-utils-tft/src/TFTUtils.cpp +++ b/lib/gui-utils-tft/src/TFTUtils.cpp @@ -56,8 +56,8 @@ void TFTUtils::displayInit() { void TFTUtils::showWelcome() { tft.fillScreen(TFT_BLACK); tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK); + tft.setFreeFont(&Orbitron_Medium_20); tft.setCursor(2,20); - tft.setFont(&Orbitron_Medium_20); tft.print("CanAirIO "); tft.setTextFont(2); tft.setTextColor(TFT_WHITE, TFT_BLACK);