This commit is contained in:
Victor Kareh 2024-08-13 15:12:45 +00:00 committed by GitHub
commit da66fa4507
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 60 additions and 13 deletions

View file

@ -34,6 +34,10 @@ void MotorController::StopRinging() {
nrf_gpio_pin_set(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor);
} }
bool MotorController::IsRinging() {
return (xTimerIsTimerActive(longVib) == pdTRUE);
}
void MotorController::StopMotor(TimerHandle_t /*xTimer*/) { void MotorController::StopMotor(TimerHandle_t /*xTimer*/) {
nrf_gpio_pin_set(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor);
} }

View file

@ -15,6 +15,7 @@ namespace Pinetime {
void RunForDuration(uint8_t motorDuration); void RunForDuration(uint8_t motorDuration);
void StartRinging(); void StartRinging();
void StopRinging(); void StopRinging();
bool IsRinging();
private: private:
static void Ring(TimerHandle_t xTimer); static void Ring(TimerHandle_t xTimer);

View file

@ -12,11 +12,13 @@ void Timer::StartTimer(std::chrono::milliseconds duration) {
} }
std::chrono::milliseconds Timer::GetTimeRemaining() { std::chrono::milliseconds Timer::GetTimeRemaining() {
TickType_t remainingTime = 0;
if (IsRunning()) { if (IsRunning()) {
TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount(); remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ); } else {
remainingTime = xTaskGetTickCount() - xTimerGetExpiryTime(timer);
} }
return std::chrono::milliseconds(0); return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
} }
void Timer::StopTimer() { void Timer::StopTimer() {

View file

@ -331,14 +331,17 @@ void DisplayApp::Refresh() {
if (state != States::Running) { if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning); 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) { if (currentApp == Apps::Timer) {
lv_disp_trig_activity(nullptr); lv_disp_trig_activity(nullptr);
auto* timer = static_cast<Screens::Timer*>(currentScreen.get()); auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
timer->Reset(); timer->SetTimerRinging();
} else {
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
} }
motorController.RunForDuration(35); motorController.StartRinging();
break; break;
case Messages::AlarmTriggered: case Messages::AlarmTriggered:
if (currentApp == Apps::Alarm) { if (currentApp == Apps::Alarm) {

View file

@ -17,7 +17,8 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
} }
} }
Timer::Timer(Controllers::Timer& timerController) : timer {timerController} { Timer::Timer(Controllers::Timer& timerController, Controllers::MotorController& motorController)
: timer {timerController}, motorController {motorController} {
lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); 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} {
txtPlayPause = lv_label_create(lv_scr_act(), nullptr); txtPlayPause = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0); lv_obj_align(txtPlayPause, btnPlayPause, LV_ALIGN_CENTER, 0, 0);
if (timer.IsRunning()) { if (motorController.IsRinging()) {
SetTimerRinging();
} else if (timer.IsRunning()) {
SetTimerRunning(); SetTimerRunning();
} else { } else {
SetTimerStopped(); SetTimerStopped();
@ -103,7 +106,19 @@ void Timer::UpdateMask() {
} }
void Timer::Refresh() { void Timer::Refresh() {
if (timer.IsRunning()) { 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()); auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
minuteCounter.SetValue(secondsRemaining.count() / 60); minuteCounter.SetValue(secondsRemaining.count() / 60);
secondCounter.SetValue(secondsRemaining.count() % 60); secondCounter.SetValue(secondsRemaining.count() % 60);
@ -123,16 +138,33 @@ void Timer::SetTimerRunning() {
minuteCounter.HideControls(); minuteCounter.HideControls();
secondCounter.HideControls(); secondCounter.HideControls();
lv_label_set_text_static(txtPlayPause, "Pause"); lv_label_set_text_static(txtPlayPause, "Pause");
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
} }
void Timer::SetTimerStopped() { void Timer::SetTimerStopped() {
isRinging = false;
minuteCounter.ShowControls(); minuteCounter.ShowControls();
secondCounter.ShowControls(); secondCounter.ShowControls();
lv_label_set_text_static(txtPlayPause, "Start"); 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");
lv_obj_set_style_local_bg_color(btnPlayPause, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
if (ringTime == 0) {
ringTime = xTaskGetTickCount();
}
} }
void Timer::ToggleRunning() { void Timer::ToggleRunning() {
if (timer.IsRunning()) { if (isRinging) {
motorController.StopRinging();
Reset();
} else if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining()); auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(timer.GetTimeRemaining());
minuteCounter.SetValue(secondsRemaining.count() / 60); minuteCounter.SetValue(secondsRemaining.count() / 60);
secondCounter.SetValue(secondsRemaining.count() % 60); secondCounter.SetValue(secondsRemaining.count() % 60);

View file

@ -2,6 +2,7 @@
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h" #include "components/datetime/DateTimeController.h"
#include "components/motor/MotorController.h"
#include "systemtask/SystemTask.h" #include "systemtask/SystemTask.h"
#include "displayapp/LittleVgl.h" #include "displayapp/LittleVgl.h"
#include "displayapp/widgets/Counter.h" #include "displayapp/widgets/Counter.h"
@ -14,19 +15,21 @@ namespace Pinetime::Applications {
namespace Screens { namespace Screens {
class Timer : public Screen { class Timer : public Screen {
public: public:
Timer(Controllers::Timer& timerController); Timer(Controllers::Timer& timerController, Controllers::MotorController& motorController);
~Timer() override; ~Timer() override;
void Refresh() override; void Refresh() override;
void Reset(); void Reset();
void ToggleRunning(); void ToggleRunning();
void ButtonPressed(); void ButtonPressed();
void MaskReset(); void MaskReset();
void SetTimerRinging();
private: private:
void SetTimerRunning(); void SetTimerRunning();
void SetTimerStopped(); void SetTimerStopped();
void UpdateMask(); void UpdateMask();
Pinetime::Controllers::Timer& timer; Pinetime::Controllers::Timer& timer;
Pinetime::Controllers::MotorController& motorController;
lv_obj_t* btnPlayPause; lv_obj_t* btnPlayPause;
lv_obj_t* txtPlayPause; lv_obj_t* txtPlayPause;
@ -41,8 +44,10 @@ namespace Pinetime::Applications {
Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76); Widgets::Counter secondCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
bool buttonPressing = false; bool buttonPressing = false;
bool isRinging = false;
lv_coord_t maskPosition = 0; lv_coord_t maskPosition = 0;
TickType_t pressTime = 0; TickType_t pressTime = 0;
TickType_t ringTime = 0;
}; };
} }
@ -52,7 +57,7 @@ namespace Pinetime::Applications {
static constexpr const char* icon = Screens::Symbols::hourGlass; static constexpr const char* icon = Screens::Symbols::hourGlass;
static Screens::Screen* Create(AppControllers& controllers) { static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::Timer(controllers.timer); return new Screens::Timer(controllers.timer, controllers.motorController);
}; };
}; };
} }