update with battery info

This commit is contained in:
richonguzman 2023-06-29 00:35:29 -04:00
parent 2bdd70a71d
commit 412e128716
4 changed files with 89 additions and 65 deletions

View File

@ -21,7 +21,7 @@
#include "SPIFFS.h"
#include "utils.h"
#define VERSION "2023.06.26"
#define VERSION "2023.06.29"
Configuration Config;
PowerManagement powerManagement;

View File

@ -111,6 +111,7 @@ void showOnScreen() {
if (powerManagement.getBatteryInfoIsConnected()) {
String batteryVoltage = powerManagement.getBatteryInfoVoltage();
String batteryChargeCurrent = powerManagement.getBatteryInfoCurrent();
#ifdef TTGO_T_Beam_V1_0
if (batteryChargeCurrent.toInt() == 0) {
sixthRowMainMenu = "Battery Charged " + batteryVoltage + "V";
} else if (batteryChargeCurrent.toInt() > 0) {
@ -118,6 +119,17 @@ void showOnScreen() {
} else {
sixthRowMainMenu = "Battery " + batteryVoltage + "V " + batteryChargeCurrent + "mA";
}
#endif
#ifdef TTGO_T_Beam_V1_2
batteryVoltage = batteryVoltage.toFloat()/1000;
if (powerManagement.isChargeing() && batteryChargeCurrent!="100") {
sixthRowMainMenu = "Bat: " + String(batteryVoltage) + "V (charging)";
} else if (!powerManagement.isChargeing() && batteryChargeCurrent=="100") {
sixthRowMainMenu = "Battery Charged " + String(batteryVoltage) + "V";
} else {
sixthRowMainMenu = "Battery " + String(batteryVoltage) + "V " + batteryChargeCurrent + "%";
}
#endif
} else {
sixthRowMainMenu = "No Battery Connected" ;
}

View File

@ -8,14 +8,14 @@ extern logging::Logger logger;
// cppcheck-suppress unusedFunction
bool PowerManagement::begin(TwoWire &port) {
#ifdef TTGO_T_Beam_V1_0
#ifdef TTGO_T_Beam_V1_0
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
if (!result) {
axp.setDCDC1Voltage(3300);
}
return result;
#endif
#ifdef TTGO_T_Beam_V1_2
#endif
#ifdef TTGO_T_Beam_V1_2
bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, I2C_SDA, I2C_SCL);
if (!result) {
PMU.setDC1Voltage(3300);
@ -50,104 +50,132 @@ bool PowerManagement::begin(TwoWire &port) {
PMU.disableBLDO2();
}
return result;
#endif
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateLoRa() {
#ifdef TTGO_T_Beam_V1_0
#ifdef TTGO_T_Beam_V1_0
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
#endif
#ifdef TTGO_T_Beam_V1_2
#endif
#ifdef TTGO_T_Beam_V1_2
PMU.setALDO2Voltage(3300);
PMU.enableALDO2();
#endif
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::deactivateLoRa() {
#ifdef TTGO_T_Beam_V1_0
#ifdef TTGO_T_Beam_V1_0
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
#endif
#ifdef TTGO_T_Beam_V1_2
#endif
#ifdef TTGO_T_Beam_V1_2
PMU.disableALDO2();
#endif
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateGPS() {
#ifdef TTGO_T_Beam_V1_0
#ifdef TTGO_T_Beam_V1_0
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
#endif
#ifdef TTGO_T_Beam_V1_2
#endif
#ifdef TTGO_T_Beam_V1_2
PMU.setALDO3Voltage(3300);
PMU.enableALDO3();
#endif
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::deactivateGPS() {
#ifdef TTGO_T_Beam_V1_0
#ifdef TTGO_T_Beam_V1_0
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
#endif
#ifdef TTGO_T_Beam_V1_2
#endif
#ifdef TTGO_T_Beam_V1_2
PMU.disableALDO3();
#endif
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateOLED() {
//axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
#ifdef TTGO_T_Beam_V1_0
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::decativateOLED() {
//axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
#ifdef TTGO_T_Beam_V1_0
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::disableChgLed() {
//axp.setChgLEDMode(AXP20X_LED_OFF);
#ifdef TTGO_T_Beam_V1_0
axp.setChgLEDMode(AXP20X_LED_OFF);
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::enableChgLed() {
//axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
#ifdef TTGO_T_Beam_V1_0
axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateMeasurement() {
//axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
#ifdef TTGO_T_Beam_V1_0
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
#endif
}
// cppcheck-suppress unusedFunction
void PowerManagement::deactivateMeasurement() {
//axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
#ifdef TTGO_T_Beam_V1_0
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
#endif
}
// cppcheck-suppress unusedFunction
double PowerManagement::getBatteryVoltage() {
//return axp.getBattVoltage() / 1000.0;
return 1.0;
#ifdef TTGO_T_Beam_V1_0
return axp.getBattVoltage() / 1000.0;
#endif
#ifdef TTGO_T_Beam_V1_2
return PMU.getBattVoltage() / 1000.0;
#endif
}
// cppcheck-suppress unusedFunction
double PowerManagement::getBatteryChargeDischargeCurrent() {
/*if (axp.isChargeing()) {
#ifdef TTGO_T_Beam_V1_0
if (axp.isChargeing()) {
return axp.getBattChargeCurrent();
}
return -1.0 * axp.getBattDischargeCurrent();*/
return 1.0;
return -1.0 * axp.getBattDischargeCurrent();
#endif
#ifdef TTGO_T_Beam_V1_2
return PMU.getBatteryPercent();
#endif
}
bool PowerManagement::isBatteryConnected() {
//return axp.isBatteryConnect();
return true;
#ifdef TTGO_T_Beam_V1_0
return axp.isBatteryConnect();
#endif
#ifdef TTGO_T_Beam_V1_2
return PMU.isBatteryConnect();
#endif
}
bool PowerManagement::isChargeing() {
//return axp.isChargeing();
return true;
#ifdef TTGO_T_Beam_V1_0
return axp.isChargeing();
#endif
#ifdef TTGO_T_Beam_V1_2
return PMU.isCharging();
#endif
}
void PowerManagement::setup() {
@ -180,40 +208,20 @@ void PowerManagement::setup() {
PMU.enableBattVoltageMeasure();
PMU.enableSystemVoltageMeasure();
//PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF);
/*uint8_t charge_status = PMU.getChargerStatus();
if (charge_status == XPOWERS_AXP2101_CHG_TRI_STATE) {
Serial.println("tri_charge");
} else if (charge_status == XPOWERS_AXP2101_CHG_PRE_STATE) {
Serial.println("pre_charge");
} else if (charge_status == XPOWERS_AXP2101_CHG_CC_STATE) {
Serial.println("constant charge");
} else if (charge_status == XPOWERS_AXP2101_CHG_CV_STATE) {
Serial.println("constant voltage");
} else if (charge_status == XPOWERS_AXP2101_CHG_DONE_STATE) {
Serial.println("charge done");
} else if (charge_status == XPOWERS_AXP2101_CHG_STOP_STATE) {
Serial.println("not chargin");
}*/
/*Serial.print("getBattVoltage:"); Serial.print(PMU.getBattVoltage()); Serial.println("mV");
Serial.print("getVbusVoltage:"); Serial.print(PMU.getVbusVoltage()); Serial.println("mV");
Serial.print("getSystemVoltage:"); Serial.print(PMU.getSystemVoltage()); Serial.println("mV");
*/
//Serial.print("getBattVoltage:"); Serial.print(PMU.getBattVoltage()); Serial.println("mV");
//Serial.print("getVbusVoltage:"); Serial.print(PMU.getVbusVoltage()); Serial.println("mV");
//Serial.print("getSystemVoltage:"); Serial.print(PMU.getSystemVoltage()); Serial.println("mV");
#endif
}
void PowerManagement::lowerCpuFrequency() {
#if defined(TTGO_T_Beam_V1_0)
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
if (setCpuFrequencyMhz(80)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "CPU frequency set to 80MHz");
} else {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "CPU frequency unchanged");
}
#endif
#endif
}
void PowerManagement::handleChargingLed() {
@ -225,15 +233,18 @@ void PowerManagement::handleChargingLed() {
}
void PowerManagement::obtainBatteryInfo() {
#ifdef TTGO_T_Beam_V1_0
static unsigned int rate_limit_check_battery = 0;
if (!(rate_limit_check_battery++ % 60))
BatteryIsConnected = isBatteryConnected();
if (BatteryIsConnected) {
#ifdef TTGO_T_Beam_V1_0
batteryVoltage = String(getBatteryVoltage(), 2);
#endif
#ifdef TTGO_T_Beam_V1_2
batteryVoltage = String(PMU.getBattVoltage());
#endif
batteryChargeDischargeCurrent = String(getBatteryChargeDischargeCurrent(), 0);
}
#endif
}
String PowerManagement::getBatteryInfoVoltage() {
@ -249,7 +260,7 @@ bool PowerManagement::getBatteryInfoIsConnected() {
}
void PowerManagement::batteryManager() {
#ifdef TTGO_T_Beam_V1_0
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
obtainBatteryInfo();
handleChargingLed();
#endif

View File

@ -24,9 +24,10 @@ public:
String getBatteryInfoCurrent();
bool getBatteryInfoIsConnected();
void batteryManager();
bool isChargeing();
private:
bool isChargeing();
void activateLoRa();
void deactivateLoRa();