2019-12-27 15:05:35 +00:00
|
|
|
#pragma once
|
2020-11-15 14:05:51 +00:00
|
|
|
#include <cstdint>
|
2019-12-27 15:05:35 +00:00
|
|
|
#include <drivers/include/nrfx_saadc.h>
|
2021-01-14 20:22:36 +00:00
|
|
|
#include <array>
|
|
|
|
#include <numeric>
|
2019-12-27 15:05:35 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
2021-01-14 21:11:17 +00:00
|
|
|
|
2019-12-27 15:05:35 +00:00
|
|
|
class Battery {
|
|
|
|
public:
|
2021-04-04 12:51:22 +00:00
|
|
|
|
2019-12-27 15:05:35 +00:00
|
|
|
void Init();
|
|
|
|
void Update();
|
2021-04-04 12:51:22 +00:00
|
|
|
|
|
|
|
int PercentRemaining();
|
|
|
|
float Voltage();
|
|
|
|
|
2019-12-27 15:05:35 +00:00
|
|
|
bool IsCharging() const { return isCharging; }
|
|
|
|
bool IsPowerPresent() const { return isPowerPresent; }
|
|
|
|
|
|
|
|
private:
|
2019-12-27 16:05:09 +00:00
|
|
|
static constexpr uint32_t chargingPin = 12;
|
|
|
|
static constexpr uint32_t powerPresentPin = 19;
|
|
|
|
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
|
2021-04-04 12:51:22 +00:00
|
|
|
|
2019-12-27 15:05:35 +00:00
|
|
|
bool isCharging = false;
|
|
|
|
bool isPowerPresent = false;
|
2021-04-04 12:51:22 +00:00
|
|
|
|
|
|
|
static void SaadcEventHandler(nrfx_saadc_evt_t const * p_event);
|
|
|
|
void SaadcInit();
|
|
|
|
|
2019-12-27 15:05:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|