Improved alarm alert handling
This commit is contained in:
parent
e332be0d7c
commit
4f649a8544
3 changed files with 41 additions and 10 deletions
|
@ -379,7 +379,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
|||
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
|
||||
break;
|
||||
case Apps::Alarm:
|
||||
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController);
|
||||
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController, *systemTask);
|
||||
break;
|
||||
|
||||
// Settings
|
||||
|
|
|
@ -23,12 +23,20 @@ using namespace Pinetime::Applications::Screens;
|
|||
using Pinetime::Controllers::AlarmController;
|
||||
|
||||
static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||
Alarm* screen = static_cast<Alarm*>(obj->user_data);
|
||||
auto* screen = static_cast<Alarm*>(obj->user_data);
|
||||
screen->OnButtonEvent(obj, event);
|
||||
}
|
||||
|
||||
Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app), alarmController {alarmController}, settingsController {settingsController} {
|
||||
static void StopAlarmTaskCallback(lv_task_t* task) {
|
||||
auto* screen = static_cast<Alarm*>(task->user_data);
|
||||
screen->StopAlerting();
|
||||
}
|
||||
|
||||
Alarm::Alarm(DisplayApp* app,
|
||||
Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
System::SystemTask& systemTask)
|
||||
: Screen(app), alarmController {alarmController}, settingsController {settingsController}, systemTask {systemTask} {
|
||||
|
||||
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);
|
||||
|
@ -122,6 +130,9 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pin
|
|||
}
|
||||
|
||||
Alarm::~Alarm() {
|
||||
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
||||
StopAlerting();
|
||||
}
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
|
@ -129,10 +140,6 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
|
|||
using Pinetime::Controllers::AlarmController;
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
if (obj == btnStop) {
|
||||
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
||||
alarmController.StopAlerting();
|
||||
}
|
||||
SetSwitchState(LV_ANIM_OFF);
|
||||
StopAlerting();
|
||||
return;
|
||||
}
|
||||
|
@ -205,9 +212,18 @@ bool Alarm::OnButtonPushed() {
|
|||
HideInfo();
|
||||
return true;
|
||||
}
|
||||
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
||||
StopAlerting();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Alarm::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||
// Don't allow closing the screen by swiping while the alarm is alerting
|
||||
return alarmController.State() == AlarmController::AlarmState::Alerting && event == TouchEvents::SwipeDown;
|
||||
}
|
||||
|
||||
void Alarm::UpdateAlarmTime() {
|
||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||
switch (alarmHours) {
|
||||
|
@ -237,9 +253,18 @@ void Alarm::UpdateAlarmTime() {
|
|||
void Alarm::SetAlerting() {
|
||||
lv_obj_set_hidden(enableSwitch, true);
|
||||
lv_obj_set_hidden(btnStop, false);
|
||||
taskStopAlarm = lv_task_create(StopAlarmTaskCallback, pdMS_TO_TICKS(60 * 1000), LV_TASK_PRIO_MID, this);
|
||||
systemTask.PushMessage(System::Messages::DisableSleeping);
|
||||
}
|
||||
|
||||
void Alarm::StopAlerting() {
|
||||
alarmController.StopAlerting();
|
||||
SetSwitchState(LV_ANIM_OFF);
|
||||
if (taskStopAlarm != nullptr) {
|
||||
lv_task_del(taskStopAlarm);
|
||||
taskStopAlarm = nullptr;
|
||||
}
|
||||
systemTask.PushMessage(System::Messages::EnableSleeping);
|
||||
lv_obj_set_hidden(enableSwitch, false);
|
||||
lv_obj_set_hidden(btnStop, true);
|
||||
}
|
||||
|
|
|
@ -27,28 +27,34 @@ namespace Pinetime {
|
|||
namespace Screens {
|
||||
class Alarm : public Screen {
|
||||
public:
|
||||
Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pinetime::Controllers::Settings& settingsController);
|
||||
Alarm(DisplayApp* app,
|
||||
Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
System::SystemTask& systemTask);
|
||||
~Alarm() override;
|
||||
void SetAlerting();
|
||||
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
|
||||
bool OnButtonPushed() override;
|
||||
bool OnTouchEvent(TouchEvents event) override;
|
||||
void StopAlerting();
|
||||
|
||||
private:
|
||||
uint8_t alarmHours;
|
||||
uint8_t alarmMinutes;
|
||||
Controllers::AlarmController& alarmController;
|
||||
Controllers::Settings& settingsController;
|
||||
System::SystemTask& systemTask;
|
||||
|
||||
lv_obj_t *time, *lblampm, *btnStop, *txtStop, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp,
|
||||
*txtMinDown, *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo, *enableSwitch;
|
||||
lv_obj_t* txtMessage = nullptr;
|
||||
lv_obj_t* btnMessage = nullptr;
|
||||
lv_task_t* taskStopAlarm = nullptr;
|
||||
|
||||
enum class EnableButtonState { On, Off, Alerting };
|
||||
void SetRecurButtonState();
|
||||
void SetSwitchState(lv_anim_enable_t anim);
|
||||
void SetAlarm();
|
||||
void StopAlerting();
|
||||
void ShowInfo();
|
||||
void HideInfo();
|
||||
void ToggleRecurrence();
|
||||
|
|
Loading…
Reference in a new issue