aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/displayapp/DisplayApp.cpp10
-rw-r--r--src/displayapp/screens/Timer.cpp41
-rw-r--r--src/displayapp/screens/Timer.h1
3 files changed, 31 insertions, 21 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 85e0ad56..35330fb7 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -372,15 +372,15 @@ void DisplayApp::Refresh() {
if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning);
}
+ lv_disp_trig_activity(nullptr);
// Load timer app if not loaded
if (currentApp != Apps::Timer) {
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
+ } else {
+ // Set the timer to ringing mode if already loaded
+ auto* timerScreen = static_cast<Screens::Timer*>(currentScreen.get());
+ timerScreen->SetTimerRinging();
}
- // Set the timer to ringing mode
- lv_disp_trig_activity(nullptr);
- auto* timerScreen = static_cast<Screens::Timer*>(currentScreen.get());
- timerScreen->SetTimerRinging();
- motorController.StartRinging();
break;
}
case Messages::AlarmTriggered:
diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp
index 02c84160..749d9859 100644
--- a/src/displayapp/screens/Timer.cpp
+++ b/src/displayapp/screens/Timer.cpp
@@ -63,7 +63,9 @@ Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController&
// Create the label as a child of the button so it stays centered by default
txtPlayPause = lv_label_create(btnPlayPause, nullptr);
- if (motorController.IsRinging()) {
+ auto timerStatus = timer.GetTimerState();
+
+ if (timerStatus && timerStatus->expired) {
SetTimerRinging();
} else if (timer.IsRunning()) {
SetTimerRunning();
@@ -76,6 +78,14 @@ Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController&
Timer::~Timer() {
lv_task_del(taskRefresh);
+
+ // If timer has expired, reset it when leaving the screen
+ auto timerStatus = timer.GetTimerState();
+ if (timerStatus && timerStatus->expired) {
+ motorController.StopRinging();
+ timer.ResetExpiredTime();
+ }
+
lv_obj_clean(lv_scr_act());
}
@@ -106,20 +116,20 @@ void Timer::UpdateMask() {
}
void Timer::Refresh() {
- if (isRinging) {
+ auto timerStatus = timer.GetTimerState();
+
+ if (timerStatus && timerStatus->expired) {
+ // Timer exists and has expired, so we're in ringing mode
DisplayTime();
- if (motorController.IsRinging()) {
- if (displaySeconds.Get().count() > 10) {
- // Stop buzzing after 10 seconds, but continue the counter
- motorController.StopRinging();
- wakeLock.Release();
- } else {
- // Keep the screen awake during the first 10 seconds
- wakeLock.Lock();
- }
+
+ if (timerStatus->distanceToExpiry.count() > 10000 && motorController.IsRinging()) {
+ // Stop buzzing after 10 seconds, but continue the counter
+ motorController.StopRinging();
+ wakeLock.Release();
}
+
// Reset timer after 1 minute
- if (displaySeconds.Get().count() > 60) {
+ if (timerStatus->distanceToExpiry.count() > 60000) {
Reset();
}
} else if (timer.IsRunning()) {
@@ -153,7 +163,6 @@ void Timer::SetTimerRunning() {
}
void Timer::SetTimerStopped() {
- isRinging = false;
minuteCounter.ShowControls();
secondCounter.ShowControls();
lv_label_set_text_static(txtPlayPause, "Start");
@@ -161,7 +170,8 @@ void Timer::SetTimerStopped() {
}
void Timer::SetTimerRinging() {
- isRinging = true;
+ motorController.StartRinging();
+ wakeLock.Lock();
minuteCounter.HideControls();
secondCounter.HideControls();
lv_label_set_text_static(txtPlayPause, "Reset");
@@ -169,7 +179,8 @@ void Timer::SetTimerRinging() {
}
void Timer::ToggleRunning() {
- if (isRinging) {
+ auto timerStatus = timer.GetTimerState();
+ if (timerStatus && timerStatus->expired) {
motorController.StopRinging();
Reset();
} else if (timer.IsRunning()) {
diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h
index 63ca2456..651c7f0d 100644
--- a/src/displayapp/screens/Timer.h
+++ b/src/displayapp/screens/Timer.h
@@ -48,7 +48,6 @@ namespace Pinetime::Applications {
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
bool buttonPressing = false;
- bool isRinging = false;
lv_coord_t maskPosition = 0;
TickType_t pressTime = 0;
Utility::DirtyValue<std::chrono::seconds> displaySeconds;