Improved alarm alert handling
This commit is contained in:
parent
e332be0d7c
commit
4f649a8544
|
@ -379,7 +379,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||||
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
|
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
|
||||||
break;
|
break;
|
||||||
case Apps::Alarm:
|
case Apps::Alarm:
|
||||||
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController);
|
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController, *systemTask);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
|
|
@ -23,12 +23,20 @@ using namespace Pinetime::Applications::Screens;
|
||||||
using Pinetime::Controllers::AlarmController;
|
using Pinetime::Controllers::AlarmController;
|
||||||
|
|
||||||
static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
|
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);
|
screen->OnButtonEvent(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pinetime::Controllers::Settings& settingsController)
|
static void StopAlarmTaskCallback(lv_task_t* task) {
|
||||||
: Screen(app), alarmController {alarmController}, settingsController {settingsController} {
|
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);
|
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_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() {
|
Alarm::~Alarm() {
|
||||||
|
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
||||||
|
StopAlerting();
|
||||||
|
}
|
||||||
lv_obj_clean(lv_scr_act());
|
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;
|
using Pinetime::Controllers::AlarmController;
|
||||||
if (event == LV_EVENT_CLICKED) {
|
if (event == LV_EVENT_CLICKED) {
|
||||||
if (obj == btnStop) {
|
if (obj == btnStop) {
|
||||||
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
|
||||||
alarmController.StopAlerting();
|
|
||||||
}
|
|
||||||
SetSwitchState(LV_ANIM_OFF);
|
|
||||||
StopAlerting();
|
StopAlerting();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -205,9 +212,18 @@ bool Alarm::OnButtonPushed() {
|
||||||
HideInfo();
|
HideInfo();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
||||||
|
StopAlerting();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
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() {
|
void Alarm::UpdateAlarmTime() {
|
||||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||||
switch (alarmHours) {
|
switch (alarmHours) {
|
||||||
|
@ -237,9 +253,18 @@ void Alarm::UpdateAlarmTime() {
|
||||||
void Alarm::SetAlerting() {
|
void Alarm::SetAlerting() {
|
||||||
lv_obj_set_hidden(enableSwitch, true);
|
lv_obj_set_hidden(enableSwitch, true);
|
||||||
lv_obj_set_hidden(btnStop, false);
|
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() {
|
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(enableSwitch, false);
|
||||||
lv_obj_set_hidden(btnStop, true);
|
lv_obj_set_hidden(btnStop, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,28 +27,34 @@ namespace Pinetime {
|
||||||
namespace Screens {
|
namespace Screens {
|
||||||
class Alarm : public Screen {
|
class Alarm : public Screen {
|
||||||
public:
|
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;
|
~Alarm() override;
|
||||||
void SetAlerting();
|
void SetAlerting();
|
||||||
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
|
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
|
||||||
bool OnButtonPushed() override;
|
bool OnButtonPushed() override;
|
||||||
|
bool OnTouchEvent(TouchEvents event) override;
|
||||||
|
void StopAlerting();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t alarmHours;
|
uint8_t alarmHours;
|
||||||
uint8_t alarmMinutes;
|
uint8_t alarmMinutes;
|
||||||
Controllers::AlarmController& alarmController;
|
Controllers::AlarmController& alarmController;
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
|
System::SystemTask& systemTask;
|
||||||
|
|
||||||
lv_obj_t *time, *lblampm, *btnStop, *txtStop, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp,
|
lv_obj_t *time, *lblampm, *btnStop, *txtStop, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp,
|
||||||
*txtMinDown, *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo, *enableSwitch;
|
*txtMinDown, *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo, *enableSwitch;
|
||||||
lv_obj_t* txtMessage = nullptr;
|
lv_obj_t* txtMessage = nullptr;
|
||||||
lv_obj_t* btnMessage = nullptr;
|
lv_obj_t* btnMessage = nullptr;
|
||||||
|
lv_task_t* taskStopAlarm = nullptr;
|
||||||
|
|
||||||
enum class EnableButtonState { On, Off, Alerting };
|
enum class EnableButtonState { On, Off, Alerting };
|
||||||
void SetRecurButtonState();
|
void SetRecurButtonState();
|
||||||
void SetSwitchState(lv_anim_enable_t anim);
|
void SetSwitchState(lv_anim_enable_t anim);
|
||||||
void SetAlarm();
|
void SetAlarm();
|
||||||
void StopAlerting();
|
|
||||||
void ShowInfo();
|
void ShowInfo();
|
||||||
void HideInfo();
|
void HideInfo();
|
||||||
void ToggleRecurrence();
|
void ToggleRecurrence();
|
||||||
|
|
Loading…
Reference in a new issue