Skip to content

Commit

Permalink
Fix snooze and next day alarm behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrrra committed Dec 24, 2024
1 parent f68f125 commit 93d2120
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions applications/settings/clock_settings/clock_settings_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

typedef struct {
DateTime now;
DateTime snooze_until;
DateTime alarm_start;
IconAnimation* icon;

bool is_snooze;
} ClockSettingsAlramModel;

const NotificationSequence sequence_alarm = {
Expand Down Expand Up @@ -93,8 +96,10 @@ int32_t clock_settings_alarm(void* p) {

// View Model
ClockSettingsAlramModel model;
model.is_snooze = false;

furi_hal_rtc_get_datetime(&model.now);
furi_hal_rtc_get_alarm(&model.alarm_start);
model.icon = icon_animation_alloc(&A_Alarm_47x39);

// Alloc message queue
Expand Down Expand Up @@ -125,24 +130,35 @@ int32_t clock_settings_alarm(void* p) {
if(event.type == InputTypePress) {
// Snooze
if(event.key == InputKeyBack) {
furi_hal_rtc_get_datetime(&model.now);
model.now.minute += SNOOZE_MINUTES;
model.now.hour += model.now.minute / 60;
model.now.minute %= 60;
model.now.hour %= 24;

furi_hal_rtc_set_alarm(NULL, false);
furi_hal_rtc_set_alarm(&model.now, true);
furi_hal_rtc_get_datetime(&model.snooze_until);
model.snooze_until.minute += SNOOZE_MINUTES;
model.snooze_until.hour += model.snooze_until.minute / 60;
model.snooze_until.minute %= 60;
model.snooze_until.hour %= 24;

model.is_snooze = true;
model.alarm_start = model.snooze_until; // For correct timeout behavior
view_port_enabled_set(view_port, false);
gui_set_lockdown(gui);
} else {
running = false;
}
running = false;
}
} else if(model.is_snooze) {
furi_hal_rtc_get_datetime(&model.now);
if(datetime_datetime_to_timestamp(&model.now) >=
datetime_datetime_to_timestamp(&model.snooze_until)) {
view_port_enabled_set(view_port, true);
gui_remove_lockdown(gui);

model.is_snooze = false;
}
} else {
notification_message(notification, &sequence_alarm);
furi_hal_rtc_get_datetime(&model.now);
view_port_update(view_port);

// Stop the alarm if it has been ringing for more than TIMEOUT_MINUTES
furi_hal_rtc_get_alarm(&model.alarm_start);
if((model.now.hour == model.alarm_start.hour &&
model.now.minute >= model.alarm_start.minute + TIMEOUT_MINUTES) ||
(model.now.hour == (model.alarm_start.hour + 1) % 24 &&
Expand Down

0 comments on commit 93d2120

Please sign in to comment.