From fcbd341c1cf0084d50e7d32337013095d45091b9 Mon Sep 17 00:00:00 2001 From: JF Date: Fri, 27 Dec 2019 16:05:35 +0100 Subject: Implement battery measurement in BatteryController. Update battery info on wake up (with button) --- src/DisplayApp/DisplayApp.cpp | 23 ++++++++++++++++------- src/DisplayApp/DisplayApp.h | 6 +++++- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src/DisplayApp') diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 496a204f..10153930 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -10,6 +10,10 @@ using namespace Pinetime::Applications; +DisplayApp::DisplayApp(Pinetime::Controllers::Battery &batteryController) : batteryController{batteryController} { + msgQueue = xQueueCreate(queueSize, itemSize); +} + void DisplayApp::Start() { if (pdPASS != xTaskCreate(DisplayApp::Process, "DisplayApp", 256, this, 0, &taskHandle)) APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); @@ -61,6 +65,9 @@ void DisplayApp::InitHw() { x = 181; gfx->DrawChar(&largeFont, '0', &x, 78, 0xffff); + + gfx->DrawString(10, 0, 0xffff, "BLE", &smallFont, false); + gfx->DrawString(20, 160, 0xffff, "FRIDAY 27 DEC 2019", &smallFont, false); } void DisplayApp::Refresh() { @@ -116,9 +123,15 @@ void DisplayApp::SetTime(uint8_t minutes, uint8_t hours) { void DisplayApp::RunningState() { uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); - gfx->DrawString(10, 0, 0xffff, "BLE", &smallFont, false); - gfx->DrawString((240-96), 0, 0xffff, "BAT: 58%", &smallFont, false); - gfx->DrawString(20, 160, 0xffff, "FRIDAY 27 DEC 2019", &smallFont, false); + char batteryChar[11]; + uint16_t newBatteryValue = batteryController.PercentRemaining(); + newBatteryValue = (newBatteryValue>100) ? 100 : newBatteryValue; + newBatteryValue = (newBatteryValue<0) ? 0 : newBatteryValue; + if(newBatteryValue != battery) { + battery = newBatteryValue; + sprintf(batteryChar, "BAT: %d%%", battery); + gfx->DrawString((240-108), 0, 0xffff, batteryChar, &smallFont, false); + } auto raw = systick_counter / 1000; auto currentDeltaSeconds = raw - deltaSeconds; @@ -175,10 +188,6 @@ void DisplayApp::IdleState() { } -DisplayApp::DisplayApp() { - msgQueue = xQueueCreate(queueSize, itemSize); -} - void DisplayApp::PushMessage(DisplayApp::Messages msg) { BaseType_t xHigherPriorityTaskWoken; xHigherPriorityTaskWoken = pdFALSE; diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 19fe7ff1..4605cf1c 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "lcdfont14.h" extern const FONT_INFO lCD_70ptFontInfo; @@ -16,7 +17,7 @@ namespace Pinetime { public: enum class States {Idle, Running}; enum class Messages : uint8_t {GoToSleep, GoToRunning} ; - DisplayApp(); + DisplayApp(Pinetime::Controllers::Battery& batteryController); void Start(); void Minutes(uint8_t m); @@ -51,6 +52,9 @@ namespace Pinetime { static constexpr uint8_t queueSize = 10; static constexpr uint8_t itemSize = 1; + Pinetime::Controllers::Battery &batteryController; + uint16_t battery = 0; + }; } } -- cgit v1.2.3-70-g09d2