Skip to content

Commit 54f20ff

Browse files
vkarehJF002
authored andcommitted
timer: Add ringing and counter
The timer app issues a short buzz once and then disappears. There is no trace left that the timer finished or how long ago. This change makes the motor start ringing and presents a timer counter. The timer stops buzzing after 10 seconds, and finally resets after 1 minute.
1 parent 7128fc0 commit 54f20ff

File tree

7 files changed

+58
-13
lines changed

7 files changed

+58
-13
lines changed

src/components/motor/MotorController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ void MotorController::StopRinging() {
3434
nrf_gpio_pin_set(PinMap::Motor);
3535
}
3636

37+
bool MotorController::IsRinging() {
38+
return (xTimerIsTimerActive(longVib) == pdTRUE);
39+
}
40+
3741
void MotorController::StopMotor(TimerHandle_t /*xTimer*/) {
3842
nrf_gpio_pin_set(PinMap::Motor);
3943
}

src/components/motor/MotorController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Pinetime {
1515
void RunForDuration(uint8_t motorDuration);
1616
void StartRinging();
1717
void StopRinging();
18+
bool IsRinging();
1819

1920
private:
2021
static void Ring(TimerHandle_t xTimer);

src/components/timer/Timer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ void Timer::StopTimer() {
4141
bool Timer::IsRunning() {
4242
return (xTimerIsTimerActive(timer) == pdTRUE);
4343
}
44+
45+
void Timer::ResetExpiredTime() {
46+
triggered = false;
47+
}

src/components/timer/Timer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace Pinetime {
2525

2626
bool IsRunning();
2727

28+
void ResetExpiredTime();
29+
2830
private:
2931
TimerHandle_t timer;
3032
TickType_t expiry;

src/displayapp/DisplayApp.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,21 @@ void DisplayApp::Refresh() {
368368
case Messages::NewNotification:
369369
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
370370
break;
371-
case Messages::TimerDone:
371+
case Messages::TimerDone: {
372372
if (state != States::Running) {
373373
PushMessageToSystemTask(System::Messages::GoToRunning);
374374
}
375-
if (currentApp == Apps::Timer) {
376-
lv_disp_trig_activity(nullptr);
377-
auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
378-
timer->Reset();
379-
} else {
375+
// Load timer app if not loaded
376+
if (currentApp != Apps::Timer) {
380377
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
381378
}
382-
motorController.RunForDuration(35);
379+
// Set the timer to ringing mode
380+
lv_disp_trig_activity(nullptr);
381+
auto* timerScreen = static_cast<Screens::Timer*>(currentScreen.get());
382+
timerScreen->SetTimerRinging();
383+
motorController.StartRinging();
383384
break;
385+
}
384386
case Messages::AlarmTriggered:
385387
if (currentApp == Apps::Alarm) {
386388
auto* alarm = static_cast<Screens::Alarm*>(currentScreen.get());

src/displayapp/screens/Timer.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
1717
}
1818
}
1919

20-
Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
20+
Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController& motorController)
21+
: timer {timerController}, motorController {motorController} {
2122

2223
lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr);
2324
lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
@@ -62,7 +63,9 @@ Timer::Timer(Controllers::Timer& timerController) : timer {timerController} {
6263
// Create the label as a child of the button so it stays centered by default
6364
txtPlayPause = lv_label_create(btnPlayPause, nullptr);
6465

65-
if (timer.IsRunning()) {
66+
if (motorController.IsRinging()) {
67+
SetTimerRinging();
68+
} else if (timer.IsRunning()) {
6669
SetTimerRunning();
6770
} else {
6871
SetTimerStopped();
@@ -103,7 +106,17 @@ void Timer::UpdateMask() {
103106
}
104107

105108
void Timer::Refresh() {
106-
if (timer.IsRunning()) {
109+
if (isRinging) {
110+
DisplayTime();
111+
// Stop buzzing after 10 seconds, but continue the counter
112+
if (motorController.IsRinging() && displaySeconds.Get().count() > 10) {
113+
motorController.StopRinging();
114+
}
115+
// Reset timer after 1 minute
116+
if (displaySeconds.Get().count() > 60) {
117+
Reset();
118+
}
119+
} else if (timer.IsRunning()) {
107120
DisplayTime();
108121
} else if (buttonPressing && xTaskGetTickCount() - pressTime > pdMS_TO_TICKS(150)) {
109122
lv_label_set_text_static(txtPlayPause, "Reset");
@@ -130,16 +143,30 @@ void Timer::SetTimerRunning() {
130143
minuteCounter.HideControls();
131144
secondCounter.HideControls();
132145
lv_label_set_text_static(txtPlayPause, "Pause");
146+
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
133147
}
134148

135149
void Timer::SetTimerStopped() {
150+
isRinging = false;
136151
minuteCounter.ShowControls();
137152
secondCounter.ShowControls();
138153
lv_label_set_text_static(txtPlayPause, "Start");
154+
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
155+
}
156+
157+
void Timer::SetTimerRinging() {
158+
isRinging = true;
159+
minuteCounter.HideControls();
160+
secondCounter.HideControls();
161+
lv_label_set_text_static(txtPlayPause, "Reset");
162+
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
139163
}
140164

141165
void Timer::ToggleRunning() {
142-
if (timer.IsRunning()) {
166+
if (isRinging) {
167+
motorController.StopRinging();
168+
Reset();
169+
} else if (timer.IsRunning()) {
143170
DisplayTime();
144171
timer.StopTimer();
145172
SetTimerStopped();
@@ -152,6 +179,7 @@ void Timer::ToggleRunning() {
152179
}
153180

154181
void Timer::Reset() {
182+
timer.ResetExpiredTime();
155183
DisplayTime();
156184
SetTimerStopped();
157185
}

src/displayapp/screens/Timer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "displayapp/screens/Screen.h"
4+
#include "components/motor/MotorController.h"
45
#include "systemtask/SystemTask.h"
56
#include "displayapp/LittleVgl.h"
67
#include "displayapp/widgets/Counter.h"
@@ -14,20 +15,22 @@ namespace Pinetime::Applications {
1415
namespace Screens {
1516
class Timer : public Screen {
1617
public:
17-
Timer(Controllers::Timer& timerController);
18+
Timer(Controllers::Timer& timerController, Controllers::MotorController& motorController);
1819
~Timer() override;
1920
void Refresh() override;
2021
void Reset();
2122
void ToggleRunning();
2223
void ButtonPressed();
2324
void MaskReset();
25+
void SetTimerRinging();
2426

2527
private:
2628
void SetTimerRunning();
2729
void SetTimerStopped();
2830
void UpdateMask();
2931
void DisplayTime();
3032
Pinetime::Controllers::Timer& timer;
33+
Pinetime::Controllers::MotorController& motorController;
3134

3235
lv_obj_t* btnPlayPause;
3336
lv_obj_t* txtPlayPause;
@@ -42,6 +45,7 @@ namespace Pinetime::Applications {
4245
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
4346

4447
bool buttonPressing = false;
48+
bool isRinging = false;
4549
lv_coord_t maskPosition = 0;
4650
TickType_t pressTime = 0;
4751
Utility::DirtyValue<std::chrono::seconds> displaySeconds;
@@ -54,7 +58,7 @@ namespace Pinetime::Applications {
5458
static constexpr const char* icon = Screens::Symbols::hourGlass;
5559

5660
static Screens::Screen* Create(AppControllers& controllers) {
57-
return new Screens::Timer(controllers.timer);
61+
return new Screens::Timer(controllers.timer, controllers.motorController);
5862
};
5963

6064
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {

0 commit comments

Comments
 (0)