diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 2532a4a1..67ca05a9 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -43,11 +43,9 @@ void AlarmController::Init(System::SystemTask* systemTask) { this->systemTask = systemTask; } -void AlarmController::SetAlarm(uint8_t alarmHr, uint8_t alarmMin) { +void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) { hours = alarmHr; minutes = alarmMin; - state = AlarmState::Set; - ScheduleAlarm(); } void AlarmController::ScheduleAlarm() { @@ -84,6 +82,8 @@ void AlarmController::ScheduleAlarm() { alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); auto mSecToAlarm = std::chrono::duration_cast(alarmTime - now).count(); app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this); + + state = AlarmState::Set; } uint32_t AlarmController::SecondsToAlarm() { diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h index 7c43b89e..bf85d431 100644 --- a/src/components/alarm/AlarmController.h +++ b/src/components/alarm/AlarmController.h @@ -31,7 +31,8 @@ namespace Pinetime { AlarmController(Controllers::DateTime& dateTimeController); void Init(System::SystemTask* systemTask); - void SetAlarm(uint8_t alarmHr, uint8_t alarmMin); + void SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin); + void ScheduleAlarm(); void DisableAlarm(); void SetOffAlarmNow(); uint32_t SecondsToAlarm(); @@ -57,12 +58,11 @@ namespace Pinetime { private: Controllers::DateTime& dateTimeController; System::SystemTask* systemTask = nullptr; - uint8_t hours; - uint8_t minutes; + uint8_t hours = 7; + uint8_t minutes = 0; std::chrono::time_point alarmTime; AlarmState state = AlarmState::Not_Set; RecurType recurrence = RecurType::None; - void ScheduleAlarm(); }; } } diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 5ade19e4..b25e6bc8 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -42,12 +42,6 @@ void MotorController::StartRinging() { app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); } -// This function is the same as StartRinging(), but will ring even if notifications are turned off in Settings -void MotorController::StartRingingDisregardSettings() { - Ring(this); - app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); -} - void MotorController::StopRinging() { app_timer_stop(longVibTimer); nrf_gpio_pin_set(pinMotor); diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index d3b96b07..d2c9fe5f 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -15,7 +15,6 @@ namespace Pinetime { void RunForDuration(uint8_t motorDuration); void StartRinging(); static void StopRinging(); - void StartRingingDisregardSettings(); private: static void Ring(void* p_context); diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index 70d95fe8..959cb0b2 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -46,7 +46,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) lv_obj_set_size(btnHoursUp, 60, 40); lv_obj_align(btnHoursUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -85); txtHrUp = lv_label_create(btnHoursUp, nullptr); - lv_label_set_text(txtHrUp, "+"); + lv_label_set_text_static(txtHrUp, "+"); btnHoursDown = lv_btn_create(lv_scr_act(), nullptr); btnHoursDown->user_data = this; @@ -54,7 +54,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) lv_obj_set_size(btnHoursDown, 60, 40); lv_obj_align(btnHoursDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, 35); txtHrDown = lv_label_create(btnHoursDown, nullptr); - lv_label_set_text(txtHrDown, "-"); + lv_label_set_text_static(txtHrDown, "-"); btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr); btnMinutesUp->user_data = this; @@ -62,7 +62,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) lv_obj_set_size(btnMinutesUp, 60, 40); lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, -85); txtMinUp = lv_label_create(btnMinutesUp, nullptr); - lv_label_set_text(txtMinUp, "+"); + lv_label_set_text_static(txtMinUp, "+"); btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr); btnMinutesDown->user_data = this; @@ -70,7 +70,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) lv_obj_set_size(btnMinutesDown, 60, 40); lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, 35); txtMinDown = lv_label_create(btnMinutesDown, nullptr); - lv_label_set_text(txtMinDown, "-"); + lv_label_set_text_static(txtMinDown, "-"); btnEnable = lv_btn_create(lv_scr_act(), nullptr); btnEnable->user_data = this; @@ -94,7 +94,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) lv_obj_set_size(btnInfo, 50, 40); lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 0, -85); txtInfo = lv_label_create(btnInfo, nullptr); - lv_label_set_text(txtInfo, "i"); + lv_label_set_text_static(txtInfo, "i"); } Alarm::~Alarm() { @@ -110,7 +110,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } else if (alarmController.State() == AlarmController::AlarmState::Set) { alarmController.DisableAlarm(); } else { - alarmController.SetAlarm(alarmHours, alarmMinutes); + alarmController.ScheduleAlarm(); } SetEnableButtonState(); return; @@ -128,8 +128,6 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } // 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 - // this avoids calling the AlarmController to change the alarm time every time the user hits minute-up or minute-down; - // can just do it once when the alarm is re-enabled if (alarmController.State() == AlarmController::AlarmState::Set) { alarmController.DisableAlarm(); SetEnableButtonState(); @@ -140,7 +138,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } else { alarmMinutes++; } - lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + UpdateAlarmTime(); return; } if (obj == btnMinutesDown) { @@ -149,7 +147,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } else { alarmMinutes--; } - lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + UpdateAlarmTime(); return; } if (obj == btnHoursUp) { @@ -158,7 +156,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } else { alarmHours++; } - lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + UpdateAlarmTime(); return; } if (obj == btnHoursDown) { @@ -167,7 +165,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } else { alarmHours--; } - lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + UpdateAlarmTime(); return; } if (obj == btnRecur) { @@ -176,6 +174,11 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } } +void Alarm::UpdateAlarmTime() { + lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); + alarmController.SetAlarmTime(alarmHours, alarmMinutes); +} + void Alarm::SetAlerting() { SetEnableButtonState(); } diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index b36f7f98..abf97eba 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -34,8 +34,8 @@ namespace Pinetime { private: bool running; - uint8_t alarmHours = 0; - uint8_t alarmMinutes = 0; + uint8_t alarmHours; + uint8_t alarmMinutes; Controllers::AlarmController& alarmController; lv_obj_t *time, *btnEnable, *txtEnable, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown, @@ -47,7 +47,8 @@ namespace Pinetime { void SetAlarm(); void ShowInfo(); void ToggleRecurrence(); + void UpdateAlarmTime(); }; }; }; -} \ No newline at end of file +} diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 9ec20590..534f5510 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -282,7 +282,7 @@ void SystemTask::Work() { if (isSleeping && !isWakingUp) { GoToRunning(); } - motorController.StartRingingDisregardSettings(); + motorController.StartRinging(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered); break; case Messages::StopRinging: