Skip to content

Commit

Permalink
timer: Stop buzzing after 10 seconds
Browse files Browse the repository at this point in the history
Also reset timer after 1 minute.
  • Loading branch information
vkareh committed May 13, 2024
1 parent d229903 commit de20a15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,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<Screens::Timer*>(currentScreen.get());
timer->Reset();
} else {
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
timer->SetTimerRinging();
}
motorController.StartRinging();
break;
Expand Down
15 changes: 12 additions & 3 deletions src/displayapp/screens/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ void Timer::UpdateMask() {
}

void Timer::Refresh() {
if (motorController.IsRinging()) {
SetTimerRinging();
if (isRinging) {
auto secondsElapsed = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::seconds>(timer.GetTimeRemaining());
minuteCounter.SetValue(secondsRemaining.count() / 60);
Expand All @@ -135,13 +142,15 @@ void Timer::SetTimerRunning() {
}

void Timer::SetTimerStopped() {
isRinging = false;
minuteCounter.ShowControls();
secondCounter.ShowControls();
lv_label_set_text_static(txtPlayPause, "Start");
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
}

void Timer::SetTimerRinging() {
isRinging = true;
minuteCounter.HideControls();
secondCounter.HideControls();
lv_label_set_text_static(txtPlayPause, "Reset");
Expand All @@ -152,7 +161,7 @@ void Timer::SetTimerRinging() {
}

void Timer::ToggleRunning() {
if (motorController.IsRinging()) {
if (isRinging) {
motorController.StopRinging();
Reset();
} else if (timer.IsRunning()) {
Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/screens/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit de20a15

Please sign in to comment.