Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix m5stickc lib issues #290

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/batterylib/battery_m5stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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() {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/batterylib/battery_m5stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <battery.hpp>
#ifdef M5STICKCPLUS
#include <M5StickCPlus.h>
#include <M5Unified.h>
#endif

#define BATTERY_MIN_V 3.4
Expand All @@ -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();
Expand Down
64 changes: 38 additions & 26 deletions lib/gui-utils-tft/src/TFTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ 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);
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
Expand Down Expand Up @@ -97,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);
Expand All @@ -131,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);
Expand Down Expand Up @@ -174,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);
}

Expand All @@ -189,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();
Expand Down Expand Up @@ -258,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");
}
Expand Down Expand Up @@ -302,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");
Expand All @@ -324,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");
}

Expand All @@ -334,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");
Expand Down Expand Up @@ -453,7 +464,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);
Expand Down Expand Up @@ -483,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());
}

Expand Down Expand Up @@ -862,7 +873,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
Expand Down
11 changes: 6 additions & 5 deletions lib/gui-utils-tft/src/TFTUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <SPI.h>
#ifdef M5STICKCPLUS
#include <M5StickCPlus.h>
#include <M5Unified.h>
#else
#include <TFT_eSPI.h>
#endif
Expand Down Expand Up @@ -50,9 +50,11 @@ class GUIUserPreferencesCallbacks;
class TFTUtils {
public:
TFTUtils(void){};

#ifndef M5STICKCPLUS
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

#else
M5GFX tft;
#endif
enum WIFI_MODE { WIFI_OFF, WIFI_ON };

void displayInit();
Expand Down Expand Up @@ -132,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
Expand Down
6 changes: 3 additions & 3 deletions lib/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void powerCompleteShutdown(){
esp_deep_sleep_start();
#endif
#ifdef M5STICKCPLUS
M5.Axp.PowerOff();
M5.Power.powerOff();
#endif
}

Expand All @@ -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
Expand All @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ lib_ignore =
lorawan

[env:M5STICKCPLUS]
platform = espressif32 @ 6.9.0
extends = tft_common
lib_deps =
${common.lib_deps}
https://github.com/hpsaturn/M5StickC-Plus.git
m5stack/M5Unified@0.1.10

[env:TTGO_TDISPLAY]
extends = tft_common
Expand Down
Loading