LoRa_APRS_Tracker/src/power_management.cpp

87 lines
2.1 KiB
C++
Raw Normal View History

#include "power_management.h"
// cppcheck-suppress uninitMemberVar
2021-10-14 21:31:56 +00:00
PowerManagement::PowerManagement() {
}
// 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;
}
// cppcheck-suppress unusedFunction
2021-10-14 21:31:56 +00:00
void PowerManagement::activateLoRa() {
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
}
// cppcheck-suppress unusedFunction
2021-10-14 21:31:56 +00:00
void PowerManagement::deactivateLoRa() {
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
2021-10-14 21:31:56 +00:00
void PowerManagement::activateGPS() {
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
}
// cppcheck-suppress unusedFunction
2021-10-14 21:31:56 +00:00
void PowerManagement::deactivateGPS() {
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
2021-10-14 21:31:56 +00:00
void PowerManagement::activateOLED() {
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
}
// cppcheck-suppress unusedFunction
2021-10-14 21:31:56 +00:00
void PowerManagement::decativateOLED() {
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
void PowerManagement::disableChgLed() {
axp.setChgLEDMode(AXP20X_LED_OFF);
}
// cppcheck-suppress unusedFunction
void PowerManagement::enableChgLed() {
axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL);
}
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);
}
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);
}
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;
}
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();
}
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
bool PowerManagement::isChargeing() {
return axp.isChargeing();
2021-09-11 09:48:59 +00:00
}