Skip to content

Commit f78ca1e

Browse files
author
Louis Pearson
committed
Add battery icon to stopwatch screen
1 parent 781d5d8 commit f78ca1e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
407407
ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
408408
break;
409409
case Apps::StopWatch:
410-
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask, dateTimeController, stopWatchController);
410+
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask, dateTimeController, stopWatchController, batteryController);
411411
break;
412412
case Apps::Twos:
413413
currentScreen = std::make_unique<Screens::Twos>(this);

src/displayapp/screens/StopWatch.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "projdefs.h"
77
#include "FreeRTOSConfig.h"
88
#include "task.h"
9+
#include "BatteryIcon.h"
910

1011
#include <tuple>
1112

@@ -48,11 +49,13 @@ static void stop_lap_event_handler(lv_obj_t* obj, lv_event_t event) {
4849
StopWatch::StopWatch(DisplayApp* app,
4950
System::SystemTask& systemTask,
5051
Controllers::DateTime& dateTimeController,
51-
Controllers::StopWatch& stopWatchController)
52+
Controllers::StopWatch& stopWatchController,
53+
Controllers::Battery& batteryController)
5254
: Screen(app),
5355
systemTask {systemTask},
5456
dateTimeController {dateTimeController},
5557
stopWatchController {stopWatchController},
58+
batteryController {batteryController},
5659
timeElapsed {},
5760
currentTimeSeparated {} {
5861

@@ -112,6 +115,11 @@ StopWatch::StopWatch(DisplayApp* app,
112115
lv_obj_align(dateTime, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
113116
lv_obj_set_style_local_text_color(dateTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
114117

118+
// Battery
119+
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
120+
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
121+
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0);
122+
115123
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
116124

117125
// Figure out what the current state of the stopwatch is and select the correct display
@@ -196,6 +204,7 @@ void StopWatch::updateLaps() {
196204

197205
void StopWatch::Refresh() {
198206
lv_label_set_text_fmt(dateTime, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
207+
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
199208
if (stopWatchController.isRunning()) {
200209
timeElapsed = calculateDelta(stopWatchController.getStart(), xTaskGetTickCount());
201210
currentTimeSeparated = convertTicksToTimeSegments((stopWatchController.getElapsedPreviously() + timeElapsed));

src/displayapp/screens/StopWatch.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Screen.h"
44
#include "components/datetime/DateTimeController.h"
55
#include "components/stopwatch/StopWatchController.h"
6+
#include "components/battery/BatteryController.h"
67
#include "../LittleVgl.h"
78

89
#include "FreeRTOS.h"
@@ -24,7 +25,8 @@ namespace Pinetime::Applications::Screens {
2425
StopWatch(DisplayApp* app,
2526
System::SystemTask& systemTask,
2627
Controllers::DateTime& dateTimeController,
27-
Controllers::StopWatch& stopWatchController);
28+
Controllers::StopWatch& stopWatchController,
29+
Controllers::Battery& batteryController);
2830
~StopWatch() override;
2931
void Refresh() override;
3032

@@ -40,11 +42,12 @@ namespace Pinetime::Applications::Screens {
4042
Pinetime::System::SystemTask& systemTask;
4143
Controllers::DateTime& dateTimeController;
4244
Controllers::StopWatch& stopWatchController;
45+
Controllers::Battery& batteryController;
4346

4447
TickType_t timeElapsed;
4548
TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs
4649

47-
lv_obj_t *dateTime, *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
50+
lv_obj_t *dateTime, *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap, *batteryIcon;
4851
lv_obj_t *lapOneText, *lapTwoText;
4952

5053
lv_task_t* taskRefresh;

0 commit comments

Comments
 (0)