77namespace Pinetime {
88 namespace Controllers {
99
10- /* * A simple circular buffer that can be used to average
11- out the sensor values. The total capacity of the CircBuffer
12- is given as the template parameter N.
13- */
14- template <int N> class CircBuffer {
15- public:
16- CircBuffer () : arr {}, sz {}, cap {N}, head {} {
17- }
18- /* *
19- insert member function overwrites the next data to the current
20- HEAD and moves the HEAD to the newly inserted value.
21- */
22- void insert (const int num) {
23- head %= cap;
24- arr[head++] = num;
25- if (sz != cap) {
26- sz++;
27- }
28- }
29-
30- int GetAverage () const {
31- int sum = std::accumulate (arr.begin (), arr.end (), 0 );
32- return (sum / sz);
33- }
34-
35- private:
36- std::array<int , N> arr; /* *< internal array used to store the values*/
37- uint8_t sz; /* *< The current size of the array.*/
38- uint8_t cap; /* *< Total capacity of the CircBuffer.*/
39- uint8_t head; /* *< The current head of the CircBuffer*/
40- };
41-
4210 class Battery {
4311 public:
4412 Battery ();
@@ -47,7 +15,7 @@ namespace Pinetime {
4715 void Update ();
4816
4917 int PercentRemaining () const {
50- return percentRemainingBuffer. GetAverage () ;
18+ return percentRemaining ;
5119 }
5220
5321 uint16_t Voltage () const {
@@ -65,9 +33,6 @@ namespace Pinetime {
6533 static Battery* instance;
6634 nrf_saadc_value_t saadc_value;
6735
68- static constexpr uint8_t percentRemainingSamples = 5 ;
69- CircBuffer<percentRemainingSamples> percentRemainingBuffer {};
70-
7136 static constexpr uint32_t chargingPin = 12 ;
7237 static constexpr uint32_t powerPresentPin = 19 ;
7338 static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
@@ -83,7 +48,6 @@ namespace Pinetime {
8348 static void adcCallbackStatic (nrfx_saadc_evt_t const * event);
8449
8550 bool isReading = false ;
86- uint8_t samples = 0 ;
8751 };
8852 }
8953}
0 commit comments