TTGO Beam v10 (AXP192) battery monitor enhanced

This commit is contained in:
Verkehrsrot 2019-09-18 22:38:39 +02:00
parent ec3873f921
commit c8531ca466
3 changed files with 28 additions and 16 deletions

View File

@ -16,6 +16,7 @@ void AXP192_power(bool on);
#endif
void AXP192_init(void);
void AXP192_displaypower(void);
uint16_t read_voltage(void);
void calibrate_voltage(void);
uint8_t getBattLevel(void);

View File

@ -31,7 +31,8 @@ void doHousekeeping() {
ESP_LOGD(TAG, "LMiCtask %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(lmicTask), eTaskGetState(lmicTask));
ESP_LOGD(TAG, "Lorasendtask %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(lorasendTask), eTaskGetState(lorasendTask));
uxTaskGetStackHighWaterMark(lorasendTask),
eTaskGetState(lorasendTask));
#endif
#if (HAS_GPS)
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
@ -57,6 +58,12 @@ void doHousekeeping() {
#if (defined BAT_MEASURE_ADC || defined HAS_PMU)
batt_voltage = read_voltage();
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
#ifdef HAS_PMU
if (I2C_MUTEX_LOCK()) {
AXP192_displaypower();
I2C_MUTEX_UNLOCK();
}
#endif // HAS_PMU
#endif
// display BME680/280 sensor data

View File

@ -16,9 +16,10 @@ void pover_event_IRQ(void) {
// put your power event handler code here
if (pmu.isVbusOverVoltageIRQ())
ESP_LOGI(TAG, "USB voltage too high.");
ESP_LOGI(TAG, "USB voltage %.1fV too high.", pmu.getVbusVoltage());
if (pmu.isVbusPlugInIRQ())
ESP_LOGI(TAG, "USB plugged.");
ESP_LOGI(TAG, "USB plugged, %.0fmAh @ %.1fV", pmu.getVbusCurrent(),
pmu.getVbusVoltage());
if (pmu.isVbusRemoveIRQ())
ESP_LOGI(TAG, "USB unplugged.");
@ -27,7 +28,7 @@ void pover_event_IRQ(void) {
if (pmu.isBattRemoveIRQ())
ESP_LOGI(TAG, "Battery was removed.");
if (pmu.isChargingIRQ())
ESP_LOGI(TAG, "Battery is charging.");
ESP_LOGI(TAG, "Battery charging.");
if (pmu.isChargingDoneIRQ())
ESP_LOGI(TAG, "Battery charging done.");
if (pmu.isBattTempLowIRQ())
@ -74,6 +75,17 @@ void AXP192_power(bool on) {
}
}
void AXP192_displaypower(void) {
if (pmu.isBatteryConnect())
if (pmu.isChargeing())
ESP_LOGI(TAG, "Battery charging @ %.0fmAh", pmu.getBattChargeCurrent());
else
ESP_LOGI(TAG, "Battery discharging @ %0.fmAh",
pmu.getBattDischargeCurrent());
else
ESP_LOGI(TAG, "No Battery");
}
void AXP192_init(void) {
// block i2c bus access
@ -89,8 +101,7 @@ void AXP192_init(void) {
AXP192_power(true);
// I2C access of AXP202X library currently is not mutexable
// so we need to disable AXP interrupts
// so we better should disable AXP interrupts... ?
#ifdef PMU_INT
pinMode(PMU_INT, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PMU_INT), PMUIRQ, FALLING);
@ -101,14 +112,7 @@ void AXP192_init(void) {
#endif // PMU_INT
ESP_LOGI(TAG, "AXP192 PMU initialized.");
if (pmu.isBatteryConnect())
if (pmu.isChargeing())
ESP_LOGI(TAG, "Battery deteced, charging.");
else
ESP_LOGI(TAG, "Battery deteced, not charging.");
else
ESP_LOGI(TAG, "No Battery deteced.");
AXP192_displaypower();
}
I2C_MUTEX_UNLOCK(); // release i2c bus access
} else