diff options
Diffstat (limited to 'src/displayapp/screens/Alarm.cpp')
-rw-r--r-- | src/displayapp/screens/Alarm.cpp | 115 |
1 files changed, 84 insertions, 31 deletions
diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index 6b45a36e..a2f534df 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -15,9 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "Alarm.h" -#include "Screen.h" -#include "Symbols.h" +#include "displayapp/screens/Alarm.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" using namespace Pinetime::Applications::Screens; using Pinetime::Controllers::AlarmController; @@ -27,8 +27,8 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) { screen->OnButtonEvent(obj, event); } -Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) - : Screen(app), running {true}, alarmController {alarmController} { +Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pinetime::Controllers::Settings& settingsController) + : Screen(app), alarmController {alarmController}, settingsController {settingsController} { 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); @@ -36,10 +36,17 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) alarmHours = alarmController.Hours(); alarmMinutes = alarmController.Minutes(); - lv_label_set_text_fmt(time, "%02lu:%02lu", alarmHours, alarmMinutes); + lv_label_set_text_fmt(time, "%02hhu:%02hhu", alarmHours, alarmMinutes); lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -25); + lblampm = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); + lv_obj_set_style_local_text_color(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_label_set_text_static(lblampm, " "); + lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); + btnHoursUp = lv_btn_create(lv_scr_act(), nullptr); btnHoursUp->user_data = this; lv_obj_set_event_cb(btnHoursUp, btnEventHandler); @@ -72,13 +79,15 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) txtMinDown = lv_label_create(btnMinutesDown, nullptr); lv_label_set_text_static(txtMinDown, "-"); - btnEnable = lv_btn_create(lv_scr_act(), nullptr); - btnEnable->user_data = this; - lv_obj_set_event_cb(btnEnable, btnEventHandler); - lv_obj_set_size(btnEnable, 115, 50); - lv_obj_align(btnEnable, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); - txtEnable = lv_label_create(btnEnable, nullptr); - SetEnableButtonState(); + btnStop = lv_btn_create(lv_scr_act(), nullptr); + btnStop->user_data = this; + lv_obj_set_event_cb(btnStop, btnEventHandler); + lv_obj_set_size(btnStop, 115, 50); + lv_obj_align(btnStop, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_set_style_local_bg_color(btnStop, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + txtStop = lv_label_create(btnStop, nullptr); + lv_label_set_text_static(txtStop, Symbols::stop); + lv_obj_set_hidden(btnStop, true); btnRecur = lv_btn_create(lv_scr_act(), nullptr); btnRecur->user_data = this; @@ -95,6 +104,21 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 0, -85); txtInfo = lv_label_create(btnInfo, nullptr); lv_label_set_text_static(txtInfo, "i"); + + enableSwitch = lv_switch_create(lv_scr_act(), nullptr); + enableSwitch->user_data = this; + lv_obj_set_event_cb(enableSwitch, btnEventHandler); + lv_obj_set_size(enableSwitch, 100, 50); + // Align to the center of 115px from edge + lv_obj_align(enableSwitch, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 7, 0); + + UpdateAlarmTime(); + + if (alarmController.State() == Controllers::AlarmController::AlarmState::Alerting) { + SetAlerting(); + } else { + SetSwitchState(LV_ANIM_OFF); + } } Alarm::~Alarm() { @@ -104,15 +128,12 @@ Alarm::~Alarm() { void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { using Pinetime::Controllers::AlarmController; if (event == LV_EVENT_CLICKED) { - if (obj == btnEnable) { + if (obj == btnStop) { if (alarmController.State() == AlarmController::AlarmState::Alerting) { alarmController.StopAlerting(); - } else if (alarmController.State() == AlarmController::AlarmState::Set) { - alarmController.DisableAlarm(); - } else { - alarmController.ScheduleAlarm(); } - SetEnableButtonState(); + SetSwitchState(LV_ANIM_OFF); + StopAlerting(); return; } if (obj == btnInfo) { @@ -123,11 +144,19 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { HideInfo(); return; } + if (obj == enableSwitch) { + if (lv_switch_get_state(enableSwitch)) { + alarmController.ScheduleAlarm(); + } else { + alarmController.DisableAlarm(); + } + return; + } // If any other button was pressed, disable the alarm // this is to make it clear that the alarm won't be set until it is turned back on if (alarmController.State() == AlarmController::AlarmState::Set) { alarmController.DisableAlarm(); - SetEnableButtonState(); + lv_switch_off(enableSwitch, LV_ANIM_ON); } if (obj == btnMinutesUp) { if (alarmMinutes >= 59) { @@ -180,27 +209,51 @@ bool Alarm::OnButtonPushed() { } void Alarm::UpdateAlarmTime() { - lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { + switch (alarmHours) { + case 0: + lv_label_set_text_static(lblampm, "AM"); + lv_label_set_text_fmt(time, "%02d:%02d", 12, alarmMinutes); + break; + case 1 ... 11: + lv_label_set_text_static(lblampm, "AM"); + lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + break; + case 12: + lv_label_set_text_static(lblampm, "PM"); + lv_label_set_text_fmt(time, "%02d:%02d", 12, alarmMinutes); + break; + case 13 ... 23: + lv_label_set_text_static(lblampm, "PM"); + lv_label_set_text_fmt(time, "%02d:%02d", alarmHours - 12, alarmMinutes); + break; + } + } else { + lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + } alarmController.SetAlarmTime(alarmHours, alarmMinutes); } void Alarm::SetAlerting() { - SetEnableButtonState(); + lv_obj_set_hidden(enableSwitch, true); + lv_obj_set_hidden(btnStop, false); } -void Alarm::SetEnableButtonState() { +void Alarm::StopAlerting() { + lv_obj_set_hidden(enableSwitch, false); + lv_obj_set_hidden(btnStop, true); +} + +void Alarm::SetSwitchState(lv_anim_enable_t anim) { switch (alarmController.State()) { case AlarmController::AlarmState::Set: - lv_label_set_text(txtEnable, "ON"); - lv_obj_set_style_local_bg_color(btnEnable, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + lv_switch_on(enableSwitch, anim); break; case AlarmController::AlarmState::Not_Set: - lv_label_set_text(txtEnable, "OFF"); - lv_obj_set_style_local_bg_color(btnEnable, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_switch_off(enableSwitch, anim); + break; + default: break; - case AlarmController::AlarmState::Alerting: - lv_label_set_text(txtEnable, Symbols::stop); - lv_obj_set_style_local_bg_color(btnEnable, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); } } @@ -223,7 +276,7 @@ void Alarm::ShowInfo() { auto secToAlarm = timeToAlarm % 60; lv_label_set_text_fmt( - txtMessage, "Time to\nalarm:\n%2d Days\n%2d Hours\n%2d Minutes\n%2d Seconds", daysToAlarm, hrsToAlarm, minToAlarm, secToAlarm); + txtMessage, "Time to\nalarm:\n%2lu Days\n%2lu Hours\n%2lu Minutes\n%2lu Seconds", daysToAlarm, hrsToAlarm, minToAlarm, secToAlarm); } else { lv_label_set_text(txtMessage, "Alarm\nis not\nset."); } |