forked from xiaozhi/xiaozhi-esp32
* Reconstruct Audio Code * Remove old IoT implementation * Add MQTT-UDP documentation * OTA升级失败时,可以继续使用
31 lines
858 B
C++
31 lines
858 B
C++
#ifndef ADC_BATTERY_MONITOR_H
|
|
#define ADC_BATTERY_MONITOR_H
|
|
|
|
#include <functional>
|
|
#include <driver/gpio.h>
|
|
#include <adc_battery_estimation.h>
|
|
#include <esp_timer.h>
|
|
|
|
class AdcBatteryMonitor {
|
|
public:
|
|
AdcBatteryMonitor(adc_unit_t adc_unit, adc_channel_t adc_channel, float upper_resistor, float lower_resistor, gpio_num_t charging_pin = GPIO_NUM_NC);
|
|
~AdcBatteryMonitor();
|
|
|
|
bool IsCharging();
|
|
bool IsDischarging();
|
|
uint8_t GetBatteryLevel();
|
|
|
|
void OnChargingStatusChanged(std::function<void(bool)> callback);
|
|
|
|
private:
|
|
gpio_num_t charging_pin_;
|
|
adc_battery_estimation_handle_t adc_battery_estimation_handle_ = nullptr;
|
|
esp_timer_handle_t timer_handle_ = nullptr;
|
|
bool is_charging_ = false;
|
|
std::function<void(bool)> on_charging_status_changed_;
|
|
|
|
void CheckBatteryStatus();
|
|
};
|
|
|
|
#endif // ADC_BATTERY_MONITOR_H
|