Implement battery measurement in BatteryController.

Update battery info on wake up (with button)
This commit is contained in:
JF
2019-12-27 16:05:35 +01:00
parent 11d5403558
commit fcbd341c1c
6 changed files with 103 additions and 75 deletions

View File

@@ -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;

View File

@@ -6,6 +6,7 @@
#include <Components/Gfx/Gfx.h>
#include <bits/unique_ptr.h>
#include <queue.h>
#include <Components/Battery/BatteryController.h>
#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;
};
}
}