Skip to content

Commit

Permalink
Use DirtyValue for timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mark9064 authored and JF002 committed Sep 14, 2024
1 parent 975bfc5 commit fd019c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/displayapp/screens/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ void Timer::UpdateMask() {

void Timer::Refresh() {
if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
minuteCounter.SetValue(secondsRemaining.count() / 60);
secondCounter.SetValue(secondsRemaining.count() % 60);
DisplayTime();
} else if (buttonPressing && xTaskGetTickCount() > pressTime + pdMS_TO_TICKS(150)) {
lv_label_set_text_static(txtPlayPause, "Reset");
maskPosition += 15;
Expand All @@ -119,6 +117,14 @@ void Timer::Refresh() {
}
}

void Timer::DisplayTime() {
displaySeconds = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
if (displaySeconds.IsUpdated()) {
minuteCounter.SetValue(displaySeconds.Get().count() / 60);
secondCounter.SetValue(displaySeconds.Get().count() % 60);
}
}

void Timer::SetTimerRunning() {
minuteCounter.HideControls();
secondCounter.HideControls();
Expand All @@ -133,9 +139,7 @@ void Timer::SetTimerStopped() {

void Timer::ToggleRunning() {
if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
minuteCounter.SetValue(secondsRemaining.count() / 60);
secondCounter.SetValue(secondsRemaining.count() % 60);
DisplayTime();
timer.StopTimer();
SetTimerStopped();
} else if (secondCounter.GetValue() + minuteCounter.GetValue() > 0) {
Expand All @@ -147,7 +151,6 @@ void Timer::ToggleRunning() {
}

void Timer::Reset() {
minuteCounter.SetValue(0);
secondCounter.SetValue(0);
DisplayTime();
SetTimerStopped();
}
3 changes: 3 additions & 0 deletions src/displayapp/screens/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "systemtask/SystemTask.h"
#include "displayapp/LittleVgl.h"
#include "displayapp/widgets/Counter.h"
#include "utility/DirtyValue.h"
#include <lvgl/lvgl.h>

#include "components/timer/Timer.h"
Expand All @@ -26,6 +27,7 @@ namespace Pinetime::Applications {
void SetTimerRunning();
void SetTimerStopped();
void UpdateMask();
void DisplayTime();
Pinetime::Controllers::Timer& timer;

lv_obj_t* btnPlayPause;
Expand All @@ -43,6 +45,7 @@ namespace Pinetime::Applications {
bool buttonPressing = false;
lv_coord_t maskPosition = 0;
TickType_t pressTime = 0;
Utility::DirtyValue<std::chrono::seconds> displaySeconds;
};
}

Expand Down

0 comments on commit fd019c7

Please sign in to comment.