Skip to content

Commit 6bd64b5

Browse files
committed
timer: Stop buzzing after 10 seconds
Also reset timer after 1 minute.
1 parent f00c53c commit 6bd64b5

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/displayapp/DisplayApp.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,15 @@ void DisplayApp::Refresh() {
265265
if (state != States::Running) {
266266
PushMessageToSystemTask(System::Messages::GoToRunning);
267267
}
268+
// Load timer app if not loaded
269+
if (currentApp != Apps::Timer) {
270+
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
271+
}
272+
// Once loaded, set the timer to ringing mode
268273
if (currentApp == Apps::Timer) {
269274
lv_disp_trig_activity(nullptr);
270275
auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
271-
timer->Reset();
272-
} else {
273-
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
276+
timer->SetTimerRinging();
274277
}
275278
motorController.StartRinging();
276279
break;

src/displayapp/screens/Timer.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,18 @@ void Timer::UpdateMask() {
106106
}
107107

108108
void Timer::Refresh() {
109-
if (motorController.IsRinging()) {
110-
SetTimerRinging();
109+
if (isRinging) {
111110
auto secondsElapsed = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
112111
minuteCounter.SetValue(secondsElapsed.count() / 60);
113112
secondCounter.SetValue(secondsElapsed.count() % 60);
113+
// Stop buzzing after 10 seconds, but continue the counter
114+
if (motorController.IsRinging() && secondsElapsed.count() > 10) {
115+
motorController.StopRinging();
116+
}
117+
// Reset timer after 1 minute
118+
if (secondsElapsed.count() > 60) {
119+
Reset();
120+
}
114121
} else if (timer.IsRunning()) {
115122
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
116123
minuteCounter.SetValue(secondsRemaining.count() / 60);
@@ -135,13 +142,15 @@ void Timer::SetTimerRunning() {
135142
}
136143

137144
void Timer::SetTimerStopped() {
145+
isRinging = false;
138146
minuteCounter.ShowControls();
139147
secondCounter.ShowControls();
140148
lv_label_set_text_static(txtPlayPause, "Start");
141149
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
142150
}
143151

144152
void Timer::SetTimerRinging() {
153+
isRinging = true;
145154
minuteCounter.HideControls();
146155
secondCounter.HideControls();
147156
lv_label_set_text_static(txtPlayPause, "Reset");
@@ -152,7 +161,7 @@ void Timer::SetTimerRinging() {
152161
}
153162

154163
void Timer::ToggleRunning() {
155-
if (motorController.IsRinging()) {
164+
if (isRinging) {
156165
motorController.StopRinging();
157166
Reset();
158167
} else if (timer.IsRunning()) {

src/displayapp/screens/Timer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ namespace Pinetime::Applications {
2222
void ToggleRunning();
2323
void ButtonPressed();
2424
void MaskReset();
25+
void SetTimerRinging();
2526

2627
private:
2728
void SetTimerRunning();
2829
void SetTimerStopped();
29-
void SetTimerRinging();
3030
void UpdateMask();
3131
Pinetime::Controllers::Timer& timer;
3232
Pinetime::Controllers::MotorController& motorController;
@@ -44,6 +44,7 @@ namespace Pinetime::Applications {
4444
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
4545

4646
bool buttonPressing = false;
47+
bool isRinging = false;
4748
lv_coord_t maskPosition = 0;
4849
TickType_t pressTime = 0;
4950
TickType_t ringTime = 0;

0 commit comments

Comments
 (0)