InfiniTime/src/components/battery/BatteryController.h

54 lines
1.1 KiB
C
Raw Normal View History

#pragma once
2020-11-15 09:05:51 -05:00
#include <cstdint>
#include <drivers/include/nrfx_saadc.h>
#include <array>
#include <numeric>
namespace Pinetime {
namespace Controllers {
class Battery {
2021-04-24 05:00:45 -04:00
public:
Battery();
void Init();
void Update();
int PercentRemaining() const {
return percentRemaining;
}
uint16_t Voltage() const {
return voltage;
}
bool IsCharging() const {
return isCharging;
}
bool IsPowerPresent() const {
return isPowerPresent;
}
2021-04-08 11:15:57 -04:00
2021-04-24 05:00:45 -04:00
private:
static Battery* instance;
nrf_saadc_value_t saadc_value;
static constexpr uint32_t chargingPin = 12;
static constexpr uint32_t powerPresentPin = 19;
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
uint16_t voltage = 0;
int percentRemaining = -1;
bool isCharging = false;
bool isPowerPresent = false;
void SaadcInit();
void SaadcEventHandler(nrfx_saadc_evt_t const* p_event);
static void adcCallbackStatic(nrfx_saadc_evt_t const* event);
bool isReading = false;
};
}
}