From 6bd64b54ad2216a8baa8a47e55eb6ccc5664416f Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Mon, 15 Jan 2024 11:50:54 -0500 Subject: [PATCH] timer: Stop buzzing after 10 seconds Also reset timer after 1 minute. --- src/displayapp/DisplayApp.cpp | 9 ++++++--- src/displayapp/screens/Timer.cpp | 15 ++++++++++++--- src/displayapp/screens/Timer.h | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 198fc9f2d1..93e98daf26 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -265,12 +265,15 @@ void DisplayApp::Refresh() { if (state != States::Running) { PushMessageToSystemTask(System::Messages::GoToRunning); } + // Load timer app if not loaded + if (currentApp != Apps::Timer) { + LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up); + } + // Once loaded, set the timer to ringing mode if (currentApp == Apps::Timer) { lv_disp_trig_activity(nullptr); auto* timer = static_cast(currentScreen.get()); - timer->Reset(); - } else { - LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up); + timer->SetTimerRinging(); } motorController.StartRinging(); break; diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index f0b48f8d06..dbfaeff582 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -106,11 +106,18 @@ void Timer::UpdateMask() { } void Timer::Refresh() { - if (motorController.IsRinging()) { - SetTimerRinging(); + if (isRinging) { auto secondsElapsed = std::chrono::duration_cast(timer.GetTimeRemaining()); minuteCounter.SetValue(secondsElapsed.count() / 60); secondCounter.SetValue(secondsElapsed.count() % 60); + // Stop buzzing after 10 seconds, but continue the counter + if (motorController.IsRinging() && secondsElapsed.count() > 10) { + motorController.StopRinging(); + } + // Reset timer after 1 minute + if (secondsElapsed.count() > 60) { + Reset(); + } } else if (timer.IsRunning()) { auto secondsRemaining = std::chrono::duration_cast(timer.GetTimeRemaining()); minuteCounter.SetValue(secondsRemaining.count() / 60); @@ -135,6 +142,7 @@ void Timer::SetTimerRunning() { } void Timer::SetTimerStopped() { + isRinging = false; minuteCounter.ShowControls(); secondCounter.ShowControls(); lv_label_set_text_static(txtPlayPause, "Start"); @@ -142,6 +150,7 @@ void Timer::SetTimerStopped() { } void Timer::SetTimerRinging() { + isRinging = true; minuteCounter.HideControls(); secondCounter.HideControls(); lv_label_set_text_static(txtPlayPause, "Reset"); @@ -152,7 +161,7 @@ void Timer::SetTimerRinging() { } void Timer::ToggleRunning() { - if (motorController.IsRinging()) { + if (isRinging) { motorController.StopRinging(); Reset(); } else if (timer.IsRunning()) { diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h index 99f3a016bb..62ae96a784 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer.h @@ -22,11 +22,11 @@ namespace Pinetime::Applications { void ToggleRunning(); void ButtonPressed(); void MaskReset(); + void SetTimerRinging(); private: void SetTimerRunning(); void SetTimerStopped(); - void SetTimerRinging(); void UpdateMask(); Pinetime::Controllers::Timer& timer; Pinetime::Controllers::MotorController& motorController; @@ -44,6 +44,7 @@ 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; TickType_t ringTime = 0;