1
0
Fork 0

Fixes per Riksu9000's feedback

This commit is contained in:
Mark Russell 2021-09-16 15:38:31 -04:00
parent 2bf339a3f8
commit f857a757a7
7 changed files with 27 additions and 30 deletions

View file

@ -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<std::chrono::milliseconds>(alarmTime - now).count();
app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this);
state = AlarmState::Set;
}
uint32_t AlarmController::SecondsToAlarm() {

View file

@ -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<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
AlarmState state = AlarmState::Not_Set;
RecurType recurrence = RecurType::None;
void ScheduleAlarm();
};
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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();
}

View file

@ -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,6 +47,7 @@ namespace Pinetime {
void SetAlarm();
void ShowInfo();
void ToggleRecurrence();
void UpdateAlarmTime();
};
};
};

View file

@ -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: