diff options
author | Jean-François Milants <jf@codingfield.com> | 2021-07-13 20:31:44 +0200 |
---|---|---|
committer | Jean-François Milants <jf@codingfield.com> | 2021-07-13 20:31:44 +0200 |
commit | af10747c94080123a5847d5258c2cfeb7ec317cb (patch) | |
tree | 7385ab23e93eb7746cf459c64679ddcdaff4fc41 /src/components/battery/BatteryController.h | |
parent | 4f378e8726fdcff72598aa6ed12eeaa6b3e61355 (diff) | |
parent | 3e705548442f1f208c2092ffc865ae824ee0955a (diff) |
Merge branch 'notify-battery-level' into develop
Diffstat (limited to 'src/components/battery/BatteryController.h')
-rw-r--r-- | src/components/battery/BatteryController.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 26e24938..1333ad0e 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -19,7 +19,7 @@ namespace Pinetime { insert member function overwrites the next data to the current HEAD and moves the HEAD to the newly inserted value. */ - void insert(const int num) { + void Insert(const uint8_t num) { head %= cap; arr[head++] = num; if (sz != cap) { @@ -27,13 +27,13 @@ namespace Pinetime { } } - int GetAverage() const { + uint8_t GetAverage() const { int sum = std::accumulate(arr.begin(), arr.end(), 0); - return (sum / sz); + return static_cast<uint8_t>(sum / sz); } private: - std::array<int, N> arr; /**< internal array used to store the values*/ + std::array<uint8_t, N> arr; /**< internal array used to store the values*/ uint8_t sz; /**< The current size of the array.*/ uint8_t cap; /**< Total capacity of the CircBuffer.*/ uint8_t head; /**< The current head of the CircBuffer*/ @@ -46,8 +46,11 @@ namespace Pinetime { void Init(); void Update(); - int PercentRemaining() const { - return percentRemainingBuffer.GetAverage(); + uint8_t PercentRemaining() const { + auto avg = percentRemainingBuffer.GetAverage(); + avg = std::min(avg, static_cast<uint8_t>(100)); + avg = std::max(avg, static_cast<uint8_t>(0)); + return avg; } uint16_t Voltage() const { @@ -57,6 +60,7 @@ namespace Pinetime { bool IsCharging() const { return isCharging; } + bool IsPowerPresent() const { return isPowerPresent; } @@ -80,7 +84,7 @@ namespace Pinetime { void SaadcInit(); void SaadcEventHandler(nrfx_saadc_evt_t const* p_event); - static void adcCallbackStatic(nrfx_saadc_evt_t const* event); + static void AdcCallbackStatic(nrfx_saadc_evt_t const* event); bool isReading = false; uint8_t samples = 0; |