Skip to content

Commit

Permalink
Add battery icon to stopwatch screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Pearson committed Nov 30, 2021
1 parent 8fbc164 commit ec72f56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::StopWatch:
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask, dateTimeController, stopWatchController);
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask, dateTimeController, stopWatchController, batteryController);
break;
case Apps::Twos:
currentScreen = std::make_unique<Screens::Twos>(this);
Expand Down
11 changes: 10 additions & 1 deletion src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "projdefs.h"
#include "FreeRTOSConfig.h"
#include "task.h"
#include "BatteryIcon.h"

#include <tuple>

Expand Down Expand Up @@ -48,11 +49,13 @@ static void stop_lap_event_handler(lv_obj_t* obj, lv_event_t event) {
StopWatch::StopWatch(DisplayApp* app,
System::SystemTask& systemTask,
Controllers::DateTime& dateTimeController,
Controllers::StopWatch& stopWatchController)
Controllers::StopWatch& stopWatchController,
Controllers::Battery& batteryController)
: Screen(app),
systemTask {systemTask},
dateTimeController {dateTimeController},
stopWatchController {stopWatchController},
batteryController {batteryController},
timeElapsed {},
currentTimeSeparated {} {

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

// Battery
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0);

taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);

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

void StopWatch::Refresh() {
lv_label_set_text_fmt(dateTime, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
if (stopWatchController.isRunning()) {
timeElapsed = calculateDelta(stopWatchController.getStart(), xTaskGetTickCount());
currentTimeSeparated = convertTicksToTimeSegments((stopWatchController.getElapsedPreviously() + timeElapsed));
Expand Down
8 changes: 6 additions & 2 deletions src/displayapp/screens/StopWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "components/datetime/DateTimeController.h"
#include "displayapp/LittleVgl.h"
#include "components/stopwatch/StopWatchController.h"
#include "components/battery/BatteryController.h"
#include "displayapp/LittleVgl.h"

#include "FreeRTOS.h"
#include "portmacro_cmsis.h"
Expand All @@ -24,7 +26,8 @@ namespace Pinetime::Applications::Screens {
StopWatch(DisplayApp* app,
System::SystemTask& systemTask,
Controllers::DateTime& dateTimeController,
Controllers::StopWatch& stopWatchController);
Controllers::StopWatch& stopWatchController,
Controllers::Battery& batteryController);
~StopWatch() override;
void Refresh() override;

Expand All @@ -40,11 +43,12 @@ namespace Pinetime::Applications::Screens {
Pinetime::System::SystemTask& systemTask;
Controllers::DateTime& dateTimeController;
Controllers::StopWatch& stopWatchController;
Controllers::Battery& batteryController;

TickType_t timeElapsed;
TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs

lv_obj_t *dateTime, *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
lv_obj_t *dateTime, *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap, *batteryIcon;
lv_obj_t *lapOneText, *lapTwoText;

lv_task_t* taskRefresh;
Expand Down

0 comments on commit ec72f56

Please sign in to comment.