diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-10 10:50:49 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-06-10 10:50:49 (GMT) |
| commit | b0aadd14e6867b80f7357d4e162180aa9d9ba075 (patch) | |
| tree | 8f02285d8384fa30102d31086b5c21d190230da1 | |
| parent | b72a3ed87d9797f7746d6fbdb348972401e4414b (diff) | |
Revert "Integrate hatmajster's timer code"
This reverts commit b72a3ed87d9797f7746d6fbdb348972401e4414b.
| -rw-r--r-- | src/components/timer/TimerController.cpp | 32 | ||||
| -rw-r--r-- | src/components/timer/TimerController.h | 24 | ||||
| -rw-r--r-- | src/displayapp/screens/Alarm.h | 1 | ||||
| -rw-r--r-- | src/displayapp/screens/Timer.cpp | 64 | ||||
| -rw-r--r-- | src/displayapp/screens/Timer.h | 16 | ||||
| -rw-r--r-- | src/systemtask/SystemTask.cpp | 2 |
6 files changed, 48 insertions, 91 deletions
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 55b7d56..eeee61f 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -3,11 +3,9 @@ using namespace Pinetime::Controllers; -namespace { - void TimerCallback(TimerHandle_t xTimer) { - auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer)); - controller->OnTimerEnd(); - } +void TimerCallback(TimerHandle_t xTimer) { + auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer)); + controller->OnTimerEnd(); } void TimerController::Init(Pinetime::System::SystemTask* systemTask) { @@ -18,37 +16,25 @@ void TimerController::Init(Pinetime::System::SystemTask* systemTask) { void TimerController::StartTimer(uint32_t duration) { xTimerChangePeriod(timer, pdMS_TO_TICKS(duration), 0); xTimerStart(timer, 0); - timerRunning = true; - overtime = false; } -int32_t TimerController::GetSecondsRemaining() { +uint32_t TimerController::GetTimeRemaining() { if (IsRunning()) { - int32_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount(); - return remainingTime / configTICK_RATE_HZ; + TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount(); + return (remainingTime * 1000 / configTICK_RATE_HZ); } return 0; } void TimerController::StopTimer() { xTimerStop(timer, 0); - timerRunning = false; - if (overtime) { - StopAlerting(); - overtime = false; - } } -void TimerController::StopAlerting() { - if (systemTask != nullptr) { - systemTask->PushMessage(System::Messages::StopRinging); - } +bool TimerController::IsRunning() { + return (xTimerIsTimerActive(timer) == pdTRUE); } void TimerController::OnTimerEnd() { - overtime = true; - if (systemTask != nullptr) { - systemTask->PushMessage(System::Messages::OnTimerDone); - } + systemTask->PushMessage(System::Messages::OnTimerDone); } diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h index c3bdc2a..93d8afc 100644 --- a/src/components/timer/TimerController.h +++ b/src/components/timer/TimerController.h @@ -2,7 +2,6 @@ #include <FreeRTOS.h> #include <timers.h> -#include <cstdint> namespace Pinetime { namespace System { @@ -14,28 +13,21 @@ namespace Pinetime { public: TimerController() = default; + void Init(System::SystemTask* systemTask); + void StartTimer(uint32_t duration); + void StopTimer(); - void StopAlerting(); - int32_t GetSecondsRemaining(); - inline bool IsOvertime() { - return overtime; - } - inline bool IsRunning() { - return timerRunning; - } - void OnTimerEnd(); + uint32_t GetTimeRemaining(); - protected: - friend class Pinetime::System::SystemTask; - void Init(System::SystemTask* systemTask); + bool IsRunning(); + + void OnTimerEnd(); private: System::SystemTask* systemTask = nullptr; TimerHandle_t timer; - bool timerRunning = false; - bool overtime = false; }; } -}
\ No newline at end of file +} diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index 07adad3..80e446f 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -54,6 +54,7 @@ namespace Pinetime { enum class EnableButtonState { On, Off, Alerting }; void SetRecurButtonState(); void SetSwitchState(lv_anim_enable_t anim); + void SetAlarm(); void ShowInfo(); void HideInfo(); void ToggleRecurrence(); diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index 002c9e3..9ef620a 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -44,42 +44,15 @@ void Timer::CreateButtons() { lv_label_set_text_static(txtSDown, "-"); } -void Timer::Stop() { - int32_t secondsRemaining = timerController.GetSecondsRemaining(); - if (timerController.IsOvertime()) { - minutesToSet = 0; - secondsToSet = 0; - secondsRemaining = 0; - } else { - minutesToSet = secondsRemaining / 60; - secondsToSet = secondsRemaining % 60; - } - timerController.StopTimer(); - timerController.StopAlerting(); - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - lv_label_set_text_fmt(time, "%02lu:%02lu", secondsRemaining / 60, secondsRemaining % 60); - lv_label_set_text(txtPlayPause, Symbols::play); - CreateButtons(); -} - Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) : Screen(app), running {true}, timerController {timerController} { time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); - int32_t seconds = timerController.GetSecondsRemaining(); - bool overtime = timerController.IsOvertime(); - - if (overtime) { - seconds = -seconds + 1; // "+ 1" is to not show -00:00 again after +00:00 - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - } else { - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - } - + uint32_t seconds = timerController.GetTimeRemaining() / 1000; lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60); - lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -25); btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); @@ -89,34 +62,23 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); txtPlayPause = lv_label_create(btnPlayPause, nullptr); if (timerController.IsRunning()) { - lv_label_set_text(txtPlayPause, overtime ? Symbols::stop : Symbols::pause); + lv_label_set_text_static(txtPlayPause, Symbols::pause); } else { lv_label_set_text_static(txtPlayPause, Symbols::play); CreateButtons(); } + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } Timer::~Timer() { lv_task_del(taskRefresh); lv_obj_clean(lv_scr_act()); - if (timerController.IsRunning() && timerController.IsOvertime()) { - timerController.StopTimer(); - } } void Timer::Refresh() { if (timerController.IsRunning()) { - int32_t seconds = timerController.GetSecondsRemaining(); - if (timerController.IsOvertime()) { - seconds = -seconds + 1; // "+ 1" is to not show -00:00 again after +00:00 - - // safety measures, lets not overflow counter as it will display badly - if (seconds >= 100 * 60) { - Stop(); - return; - } - } + uint32_t seconds = timerController.GetTimeRemaining() / 1000; lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60); } } @@ -125,12 +87,17 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { if (event == LV_EVENT_CLICKED) { if (obj == btnPlayPause) { if (timerController.IsRunning()) { - Stop(); + lv_label_set_text_static(txtPlayPause, Symbols::play); + uint32_t seconds = timerController.GetTimeRemaining() / 1000; + minutesToSet = seconds / 60; + secondsToSet = seconds % 60; + timerController.StopTimer(); + CreateButtons(); + } else if (secondsToSet + minutesToSet > 0) { lv_label_set_text_static(txtPlayPause, Symbols::pause); timerController.StartTimer((secondsToSet + minutesToSet * 60) * 1000); - // inlined destroyButtons() lv_obj_del(btnSecondsDown); btnSecondsDown = nullptr; lv_obj_del(btnSecondsUp); @@ -180,6 +147,9 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } void Timer::SetDone() { - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_label_set_text_static(txtPlayPause, Symbols::stop); + lv_label_set_text_static(time, "00:00"); + lv_label_set_text_static(txtPlayPause, Symbols::play); + secondsToSet = 0; + minutesToSet = 0; + CreateButtons(); } diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h index c0e0885..c1f7f9e 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer.h @@ -24,10 +24,18 @@ namespace Pinetime::Applications::Screens { uint8_t secondsToSet = 0; uint8_t minutesToSet = 0; Controllers::TimerController& timerController; - void Stop(); - + lv_obj_t* time; + lv_obj_t* msecTime; + lv_obj_t* btnPlayPause; + lv_obj_t* txtPlayPause; + lv_obj_t* btnMinutesUp; + lv_obj_t* btnMinutesDown; + lv_obj_t* btnSecondsUp; + lv_obj_t* btnSecondsDown; + lv_obj_t* txtMUp; + lv_obj_t* txtMDown; + lv_obj_t* txtSUp; + lv_obj_t* txtSDown; lv_task_t* taskRefresh; - lv_obj_t *time, *btnPlayPause, *txtPlayPause, *btnMinutesUp, *btnMinutesDown, *btnSecondsUp, *btnSecondsDown, *txtMUp, - *txtMDown, *txtSUp, *txtSDown; }; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 775106f..3353a45 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -305,7 +305,7 @@ void SystemTask::Work() { if (state == SystemTaskState::Sleeping) { GoToRunning(); } - motorController.StartRinging(); + motorController.RunForDuration(35); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone); break; case Messages::SetOffAlarm: |
