summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-09-03 14:35:38 +0300
committerRiku Isokoski <riksu9000@gmail.com>2021-09-03 14:35:38 +0300
commitfd52ca8fe6f42226ec32a001f4c61dc100ead94a (patch)
tree250d929d0c9bfb682e7884c907f284a785b2484f /src/components
parent6f9f0e8b0e42a5526d47ca664534fb6b0ccb6ace (diff)
Detect full charge and improve watchface display
Diffstat (limited to 'src/components')
-rw-r--r--src/components/battery/BatteryController.cpp10
-rw-r--r--src/components/battery/BatteryController.h9
2 files changed, 16 insertions, 3 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index f8a64ecd..619e227c 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -19,6 +19,12 @@ void Battery::Update() {
isCharging = !nrf_gpio_pin_read(chargingPin);
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
+ if (isPowerPresent && !isCharging) {
+ isFull = true;
+ } else if (!isPowerPresent) {
+ isFull = false;
+ }
+
if (isReading) {
return;
}
@@ -65,12 +71,12 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
- if (voltage > battery_max) {
+ if (isFull) {
percentRemaining = 100;
} else if (voltage < battery_min) {
percentRemaining = 0;
} else {
- percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min);
+ percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), 99);
}
nrfx_saadc_uninit();
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index 6f09b737..164057c4 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -23,13 +23,19 @@ namespace Pinetime {
}
bool IsCharging() const {
- return isCharging;
+ // isCharging will go up and down when fully charged
+ // isFull makes sure this returns false while fully charged.
+ return isCharging && !isFull;
}
bool IsPowerPresent() const {
return isPowerPresent;
}
+ bool IsFull() const {
+ return isFull;
+ }
+
private:
static Battery* instance;
nrf_saadc_value_t saadc_value;
@@ -40,6 +46,7 @@ namespace Pinetime {
uint16_t voltage = 0;
uint8_t percentRemaining = 0;
+ bool isFull = false;
bool isCharging = false;
bool isPowerPresent = false;