summaryrefslogtreecommitdiff
path: root/src/components/battery/BatteryController.h
blob: 9bc942c950bdf9c755e03054a64a50e51fb4d2ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <cstdint>
#include <drivers/include/nrfx_saadc.h>
#include <array>
#include <numeric>

namespace Pinetime {
  namespace Controllers {

    class Battery {
      public:

        void Init();
        void Update();
        
        int PercentRemaining();
        float Voltage();

        bool IsCharging() const { return isCharging; }
        bool IsPowerPresent() const { return isPowerPresent; }

      private:
        static constexpr uint32_t chargingPin = 12;
        static constexpr uint32_t powerPresentPin = 19;
        static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;

        bool isCharging = false;
        bool isPowerPresent = false;

        static void SaadcEventHandler(nrfx_saadc_evt_t const * p_event);
        void SaadcInit();

    };
  }
}