diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/battery/BatteryController.cpp | 10 | ||||
-rw-r--r-- | src/components/battery/BatteryController.h | 5 | ||||
-rw-r--r-- | src/components/ble/BatteryInformationService.cpp | 2 | ||||
-rw-r--r-- | src/components/fs/FS.h | 2 |
4 files changed, 14 insertions, 5 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index 4ef20a24..b43b229f 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -17,6 +17,12 @@ void Battery::Update() { isCharging = !nrf_gpio_pin_read(PinMap::Charging); isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent); + if (isPowerPresent && !isCharging) { + isFull = true; + } else if (!isPowerPresent) { + isFull = false; + } + if (isReading) { return; } @@ -63,12 +69,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), isCharging ? 99 : 100); } nrfx_saadc_uninit(); diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 8af27ea8..c78ffb3f 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -22,7 +22,9 @@ 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 { @@ -37,6 +39,7 @@ namespace Pinetime { uint16_t voltage = 0; uint8_t percentRemaining = 0; + bool isFull = false; bool isCharging = false; bool isPowerPresent = false; diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp index 7f176904..4ef02358 100644 --- a/src/components/ble/BatteryInformationService.cpp +++ b/src/components/ble/BatteryInformationService.cpp @@ -43,7 +43,7 @@ int BatteryInformationService::OnBatteryServiceRequested(uint16_t connectionHand ble_gatt_access_ctxt* context) { if (attributeHandle == batteryLevelHandle) { NRF_LOG_INFO("BATTERY : handle = %d", batteryLevelHandle); - static uint8_t batteryValue = batteryController.PercentRemaining(); + uint8_t batteryValue = batteryController.PercentRemaining(); int res = os_mbuf_append(context->om, &batteryValue, 1); return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; } diff --git a/src/components/fs/FS.h b/src/components/fs/FS.h index 1f2eb7e0..75ba16c8 100644 --- a/src/components/fs/FS.h +++ b/src/components/fs/FS.h @@ -53,7 +53,7 @@ namespace Pinetime { * */ static constexpr size_t startAddress = 0x0B4000; - static constexpr size_t size = 0x3C0000; + static constexpr size_t size = 0x34C000; static constexpr size_t blockSize = 4096; bool resourcesValid = false; |