2020-11-08 13:14:56 +00:00
|
|
|
|
|
|
|
#include "power_management.h"
|
|
|
|
|
|
|
|
// cppcheck-suppress uninitMemberVar
|
2021-10-14 21:31:56 +00:00
|
|
|
PowerManagement::PowerManagement() {
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
bool PowerManagement::begin(TwoWire &port) {
|
|
|
|
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
|
|
|
if (!result) {
|
|
|
|
axp.setDCDC1Voltage(3300);
|
|
|
|
}
|
|
|
|
return result;
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::activateLoRa() {
|
|
|
|
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::deactivateLoRa() {
|
|
|
|
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::activateGPS() {
|
|
|
|
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::deactivateGPS() {
|
|
|
|
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::activateOLED() {
|
|
|
|
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::decativateOLED() {
|
|
|
|
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2022-05-13 18:32:38 +00:00
|
|
|
void PowerManagement::disableChgLed() {
|
|
|
|
axp.setChgLEDMode(AXP20X_LED_OFF);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cppcheck-suppress unusedFunction
|
2022-05-13 18:32:38 +00:00
|
|
|
void PowerManagement::enableChgLed() {
|
|
|
|
axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 11:22:05 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::activateMeasurement() {
|
|
|
|
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
|
2020-11-09 22:09:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 11:22:05 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
void PowerManagement::deactivateMeasurement() {
|
|
|
|
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
|
2020-11-09 22:09:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 11:22:05 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
double PowerManagement::getBatteryVoltage() {
|
|
|
|
return axp.getBattVoltage() / 1000.0;
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 11:22:05 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2021-10-14 21:31:56 +00:00
|
|
|
double PowerManagement::getBatteryChargeDischargeCurrent() {
|
|
|
|
if (axp.isChargeing()) {
|
|
|
|
return axp.getBattChargeCurrent();
|
|
|
|
}
|
|
|
|
return -1.0 * axp.getBattDischargeCurrent();
|
2020-11-08 13:14:56 +00:00
|
|
|
}
|
2021-04-19 20:34:04 +00:00
|
|
|
|
2021-10-14 21:31:56 +00:00
|
|
|
bool PowerManagement::isBatteryConnect() {
|
|
|
|
return axp.isBatteryConnect();
|
2021-04-19 20:34:04 +00:00
|
|
|
}
|
2021-09-11 09:48:59 +00:00
|
|
|
|
2022-05-13 18:32:38 +00:00
|
|
|
bool PowerManagement::isChargeing() {
|
|
|
|
return axp.isChargeing();
|
2021-09-11 09:48:59 +00:00
|
|
|
}
|