From c5c070725671bb1fc56d21ce8b0f8c9815389e7d Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 30 Dec 2023 17:02:40 -0300 Subject: [PATCH] starting new powerManagment --- src/LoRa_APRS_Tracker.cpp | 11 ++--- src/keyboard_utils.cpp | 4 +- src/menu_utils.cpp | 10 ++--- src/power_utils.cpp | 91 +++++++++++++++++++++++++++++++++++++++ src/power_utils.h | 14 +++++- src/station_utils.cpp | 6 +-- 6 files changed, 119 insertions(+), 17 deletions(-) diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index d884290..5ddeab0 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -25,7 +25,7 @@ #include "utils.h" Configuration Config; -PowerManagement powerManagement; +//PowerManagement powerManagement; HardwareSerial neo6m_gps(1); TinyGPSPlus gps; BluetoothSerial SerialBT; @@ -33,7 +33,7 @@ BluetoothSerial SerialBT; OneButton userButton = OneButton(BUTTON_PIN, true, true); #endif -String versionDate = "2023.12.27"; +String versionDate = "2023.12.30"; int myBeaconsIndex = 0; int myBeaconsSize = Config.beacons.size(); @@ -103,7 +103,8 @@ void setup() { logger.setDebugLevel(logging::LoggerLevel::LOGGER_LEVEL_INFO); #endif - powerManagement.setup(); + //powerManagement.setup(); + POWER_Utils::setup(); setup_display(); if (Config.notification.buzzerActive) { @@ -153,7 +154,7 @@ void setup() { KEYBOARD_Utils::setup(); } - powerManagement.lowerCpuFrequency(); + //powerManagement.lowerCpuFrequency(); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Smart Beacon is: %s", Utils::getSmartBeaconState()); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Setup Done!"); menuDisplay = 0; @@ -166,7 +167,7 @@ void loop() { miceActive = Config.validateMicE(currentBeacon->micE); } - powerManagement.batteryManager(); + //powerManagement.batteryManager(); if (!Config.simplifiedTrackerMode) { #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) userButton.tick(); diff --git a/src/keyboard_utils.cpp b/src/keyboard_utils.cpp index a5844f9..950052c 100644 --- a/src/keyboard_utils.cpp +++ b/src/keyboard_utils.cpp @@ -12,7 +12,7 @@ extern Configuration Config; extern logging::Logger logger; -extern PowerManagement powerManagement; +//extern PowerManagement powerManagement; extern bool sendUpdate; extern int menuDisplay; extern uint32_t menuTime; @@ -364,7 +364,7 @@ namespace KEYBOARD_Utils { ESP.restart(); } else if (menuDisplay==260) { show_display("", "", " POWER OFF ...", 2000); - powerManagement.shutdown(); + //powerManagement.shutdown(); } } else if (key == 181) { // Arrow Up diff --git a/src/menu_utils.cpp b/src/menu_utils.cpp index 6b26116..07d29c0 100644 --- a/src/menu_utils.cpp +++ b/src/menu_utils.cpp @@ -16,7 +16,7 @@ extern int menuDisplay; extern Beacon *currentBeacon; extern Configuration Config; extern TinyGPSPlus gps; -extern PowerManagement powerManagement; +//extern PowerManagement powerManagement; extern std::vector loadedAPRSMessages; extern int messagesIterator; extern uint32_t menuTime; @@ -386,7 +386,7 @@ namespace MENU_Utils { fifthRowMainMenu = "LAST Rx = " + MSG_Utils::getLastHeardTracker(); - if (powerManagement.getBatteryInfoIsConnected()) { + /*if (powerManagement.getBatteryInfoIsConnected()) { String batteryVoltage = powerManagement.getBatteryInfoVoltage(); String batteryCharge = powerManagement.getBatteryInfoCurrent(); #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA_V2_1_GPS) || defined(TTGO_T_LORA_V2_1_TNC) @@ -421,9 +421,9 @@ namespace MENU_Utils { sixthRowMainMenu = "Battery " + String(batteryVoltage) + "V " + batteryCharge + "%"; } #endif - } else { - sixthRowMainMenu = "No Battery Connected" ; - } + } else {*/ + sixthRowMainMenu = "No Battery Connected" ; + //} show_display(String(firstRowMainMenu), String(secondRowMainMenu), String(thirdRowMainMenu), diff --git a/src/power_utils.cpp b/src/power_utils.cpp index 6beb74c..cbc689e 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -11,6 +11,8 @@ extern bool disableGPS; float lora32BatReadingCorr = 6.5; // % of correction to higher value to reflect the real battery voltage (adjust this to your needs) + +/* // cppcheck-suppress unusedFunction bool PowerManagement::begin(TwoWire &port) { #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA_V2_1_GPS) || defined(TTGO_T_LORA_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) @@ -295,4 +297,93 @@ void PowerManagement::shutdown() { #if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262) PMU.shutdown(); #endif +} + +*/ + +#if defined(TTGO_T_Beam_V1_0) +XPowersAXP192 PMU; +#endif +#if defined(TTGO_T_Beam_V1_2) +XPowersAXP2101 PMU; +#endif + +namespace POWER_Utils { + + void + + bool begin(TwoWire &port) { + #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA_V2_1_GPS) || defined(TTGO_T_LORA_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) + return true; // nor powerManagment chip for this boards (only a few measure battery voltage). + #endif + #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) + bool result = axp.begin(port, AXP192_SLAVE_ADDRESS); + if (!result) { + axp.setDCDC1Voltage(3300); + } + return result; + #endif + #if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262) + bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, I2C_SDA, I2C_SCL); + if (result) { + PMU.disableDC2(); + PMU.disableDC3(); + PMU.disableDC4(); + PMU.disableDC5(); + PMU.disableALDO1(); + PMU.disableALDO4(); + PMU.disableBLDO1(); + PMU.disableBLDO2(); + PMU.disableDLDO1(); + PMU.disableDLDO2(); + + PMU.setDC1Voltage(3300); + PMU.enableDC1(); + } + return result; + #endif + } + + void setup() { + Serial.println("starting setup"); + Wire.end(); + #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) + Wire.begin(SDA, SCL); + if (!begin(Wire)) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!"); + } else { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!"); + } + /*activateLoRa(); + activateOLED(); + if (disableGPS) { + deactivateGPS(); + } else { + activateGPS(); + } + activateMeasurement();*/ + #endif + #if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262) + Wire.begin(SDA, SCL); + if (begin(Wire)) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP2101", "init done!"); + } else { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP2101", "init failed!"); + } + /*activateLoRa(); + activateOLED(); + if (disableGPS) { + deactivateGPS(); + } else { + activateGPS(); + } + activateMeasurement();*/ + /*PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_200MA); + PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); + PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); + PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_800MA); + PMU.setSysPowerDownVoltage(2600);*/ + #endif + } + } \ No newline at end of file diff --git a/src/power_utils.h b/src/power_utils.h index 442c0b6..a281cb2 100644 --- a/src/power_utils.h +++ b/src/power_utils.h @@ -2,7 +2,9 @@ #define POWER_UTILS_H_ #include -#if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA_V2_1_GPS) || defined(TTGO_T_LORA_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) +#include "XPowersLib.h" + +/*#if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA_V2_1_GPS) || defined(TTGO_T_LORA_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) // The V0.7 boards have no power managment components connected to TwoWire. // Battery charging is controlled by a TP5400 IC indepemdetly from the ESP32. // Wire.h must be included to maitain software compatibility with V1.0 and 1.2 boards. @@ -64,6 +66,14 @@ private: bool BatteryIsConnected; String batteryVoltage; String batteryChargeDischargeCurrent; -}; +};*/ + +/////////////////////////////// +namespace POWER_Utils { + + bool begin(TwoWire &port); + void setup(); + +} #endif diff --git a/src/station_utils.cpp b/src/station_utils.cpp index 32ac8fe..768f904 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -15,7 +15,7 @@ extern Configuration Config; extern Beacon *currentBeacon; extern logging::Logger logger; extern TinyGPSPlus gps; -extern PowerManagement powerManagement; +//extern PowerManagement powerManagement; extern std::vector lastHeardStation; extern std::vector lastHeardStation_temp; extern int myBeaconsIndex; @@ -410,8 +410,8 @@ namespace STATION_Utils { } } if (Config.sendBatteryInfo) { - String batteryVoltage = powerManagement.getBatteryInfoVoltage(); - String batteryChargeCurrent = powerManagement.getBatteryInfoCurrent(); + String batteryVoltage = "0";//powerManagement.getBatteryInfoVoltage(); + String batteryChargeCurrent = "0";//powerManagement.getBatteryInfoCurrent(); #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) packet += " Bat=" + batteryVoltage + "V (" + batteryChargeCurrent + "mA)"; #endif