Skip to content

Commit 7e1386e

Browse files
committed
timer: Add ringing
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.
1 parent 6ab512a commit 7e1386e

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

src/components/motor/MotorController.cpp

+4
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

+1
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

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ void Timer::StartTimer(std::chrono::milliseconds duration) {
1212
}
1313

1414
std::chrono::milliseconds Timer::GetTimeRemaining() {
15+
TickType_t remainingTime = 0;
1516
if (IsRunning()) {
16-
TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
17-
return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
17+
remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
18+
} else {
19+
remainingTime = xTaskGetTickCount() - xTimerGetExpiryTime(timer);
1820
}
19-
return std::chrono::milliseconds(0);
21+
return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
2022
}
2123

2224
void Timer::StopTimer() {

src/displayapp/DisplayApp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void DisplayApp::Refresh() {
273273
} else {
274274
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
275275
}
276-
motorController.RunForDuration(35);
276+
motorController.StartRinging();
277277
break;
278278
case Messages::AlarmTriggered:
279279
if (currentApp == Apps::Alarm) {

src/displayapp/screens/Timer.cpp

+27-4
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
txtPlayPause = lv_label_create(lv_scr_act(), nullptr);
6364
lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0);
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,12 @@ void Timer::UpdateMask() {
103106
}
104107

105108
void Timer::Refresh() {
106-
if (timer.IsRunning()) {
109+
if (motorController.IsRinging()) {
110+
SetTimerRinging();
111+
auto secondsElapsed = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
112+
minuteCounter.SetValue(secondsElapsed.count() / 60);
113+
secondCounter.SetValue(secondsElapsed.count() % 60);
114+
} else if (timer.IsRunning()) {
107115
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
108116
minuteCounter.SetValue(secondsRemaining.count() / 60);
109117
secondCounter.SetValue(secondsRemaining.count() % 60);
@@ -123,16 +131,31 @@ void Timer::SetTimerRunning() {
123131
minuteCounter.HideControls();
124132
secondCounter.HideControls();
125133
lv_label_set_text_static(txtPlayPause, "Pause");
134+
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
126135
}
127136

128137
void Timer::SetTimerStopped() {
129138
minuteCounter.ShowControls();
130139
secondCounter.ShowControls();
131140
lv_label_set_text_static(txtPlayPause, "Start");
141+
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
142+
}
143+
144+
void Timer::SetTimerRinging() {
145+
minuteCounter.HideControls();
146+
secondCounter.HideControls();
147+
lv_label_set_text_static(txtPlayPause, "Reset");
148+
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
149+
if (ringTime == 0) {
150+
ringTime = xTaskGetTickCount();
151+
}
132152
}
133153

134154
void Timer::ToggleRunning() {
135-
if (timer.IsRunning()) {
155+
if (motorController.IsRinging()) {
156+
motorController.StopRinging();
157+
Reset();
158+
} else if (timer.IsRunning()) {
136159
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
137160
minuteCounter.SetValue(secondsRemaining.count() / 60);
138161
secondCounter.SetValue(secondsRemaining.count() % 60);

src/displayapp/screens/Timer.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "displayapp/screens/Screen.h"
44
#include "components/datetime/DateTimeController.h"
5+
#include "components/motor/MotorController.h"
56
#include "systemtask/SystemTask.h"
67
#include "displayapp/LittleVgl.h"
78
#include "displayapp/widgets/Counter.h"
@@ -14,7 +15,7 @@ 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();
@@ -25,8 +26,10 @@ namespace Pinetime::Applications {
2526
private:
2627
void SetTimerRunning();
2728
void SetTimerStopped();
29+
void SetTimerRinging();
2830
void UpdateMask();
2931
Pinetime::Controllers::Timer& timer;
32+
Pinetime::Controllers::MotorController& motorController;
3033

3134
lv_obj_t* btnPlayPause;
3235
lv_obj_t* txtPlayPause;
@@ -43,6 +46,7 @@ namespace Pinetime::Applications {
4346
bool buttonPressing = false;
4447
lv_coord_t maskPosition = 0;
4548
TickType_t pressTime = 0;
49+
TickType_t ringTime = 0;
4650
};
4751
}
4852

@@ -52,7 +56,7 @@ namespace Pinetime::Applications {
5256
static constexpr const char* icon = Screens::Symbols::hourGlass;
5357

5458
static Screens::Screen* Create(AppControllers& controllers) {
55-
return new Screens::Timer(controllers.timer);
59+
return new Screens::Timer(controllers.timer, controllers.motorController);
5660
};
5761
};
5862
}

0 commit comments

Comments
 (0)