1111
1212#define TAG "ClockSettingsAlarm"
1313
14+ #define SNOOZE_MINUTES 9
15+ #define TIMEOUT_MINUTES 10
16+
1417typedef struct {
1518 DateTime now ;
19+ DateTime snooze_until ;
20+ DateTime alarm_start ;
1621 IconAnimation * icon ;
22+
23+ bool is_snooze ;
1724} ClockSettingsAlramModel ;
1825
1926const NotificationSequence sequence_alarm = {
@@ -47,12 +54,15 @@ static void clock_settings_alarm_draw_callback(Canvas* canvas, void* ctx) {
4754 ClockSettingsAlramModel * model = ctx ;
4855 char buffer [64 ] = {};
4956
57+ // Clock icon
5058 canvas_draw_icon_animation (canvas , 5 , 6 , model -> icon );
5159
60+ // Time
5261 canvas_set_font (canvas , FontBigNumbers );
5362 snprintf (buffer , sizeof (buffer ), "%02u:%02u" , model -> now .hour , model -> now .minute );
5463 canvas_draw_str (canvas , 58 , 32 , buffer );
5564
65+ // Date
5666 canvas_set_font (canvas , FontPrimary );
5767 snprintf (
5868 buffer ,
@@ -62,6 +72,11 @@ static void clock_settings_alarm_draw_callback(Canvas* canvas, void* ctx) {
6272 model -> now .month ,
6373 model -> now .year );
6474 canvas_draw_str (canvas , 60 , 44 , buffer );
75+
76+ // Press Back to snooze
77+ canvas_set_font (canvas , FontPrimary );
78+ canvas_draw_icon_ex (canvas , 5 , 50 , & I_back_btn_10x8 , 0 );
79+ canvas_draw_str_aligned (canvas , 20 , 50 , AlignLeft , AlignTop , "Snooze" );
6580}
6681
6782static void clock_settings_alarm_input_callback (InputEvent * input_event , void * ctx ) {
@@ -81,8 +96,10 @@ int32_t clock_settings_alarm(void* p) {
8196
8297 // View Model
8398 ClockSettingsAlramModel model ;
99+ model .is_snooze = false;
84100
85101 furi_hal_rtc_get_datetime (& model .now );
102+ furi_hal_rtc_get_alarm (& model .alarm_start );
86103 model .icon = icon_animation_alloc (& A_Alarm_47x39 );
87104
88105 // Alloc message queue
@@ -95,6 +112,7 @@ int32_t clock_settings_alarm(void* p) {
95112
96113 // Register view port in GUI
97114 Gui * gui = furi_record_open (RECORD_GUI );
115+ gui_set_lockdown_inhibit (gui , true);
98116 gui_add_view_port (gui , view_port , GuiLayerFullscreen );
99117
100118 NotificationApp * notification = furi_record_open (RECORD_NOTIFICATION );
@@ -110,12 +128,43 @@ int32_t clock_settings_alarm(void* p) {
110128 while (running ) {
111129 if (furi_message_queue_get (event_queue , & event , 2000 ) == FuriStatusOk ) {
112130 if (event .type == InputTypePress ) {
113- running = false;
131+ // Snooze
132+ if (event .key == InputKeyBack ) {
133+ furi_hal_rtc_get_datetime (& model .snooze_until );
134+ model .snooze_until .minute += SNOOZE_MINUTES ;
135+ model .snooze_until .hour += model .snooze_until .minute / 60 ;
136+ model .snooze_until .minute %= 60 ;
137+ model .snooze_until .hour %= 24 ;
138+
139+ model .is_snooze = true;
140+ model .alarm_start = model .snooze_until ; // For correct timeout behavior
141+ view_port_enabled_set (view_port , false);
142+ gui_set_lockdown_inhibit (gui , false);
143+ } else {
144+ running = false;
145+ }
146+ }
147+ } else if (model .is_snooze ) {
148+ furi_hal_rtc_get_datetime (& model .now );
149+ if (datetime_datetime_to_timestamp (& model .now ) >=
150+ datetime_datetime_to_timestamp (& model .snooze_until )) {
151+ view_port_enabled_set (view_port , true);
152+ gui_set_lockdown_inhibit (gui , true);
153+
154+ model .is_snooze = false;
114155 }
115156 } else {
116157 notification_message (notification , & sequence_alarm );
117158 furi_hal_rtc_get_datetime (& model .now );
118159 view_port_update (view_port );
160+
161+ // Stop the alarm if it has been ringing for more than TIMEOUT_MINUTES
162+ if ((model .now .hour == model .alarm_start .hour &&
163+ model .now .minute >= model .alarm_start .minute + TIMEOUT_MINUTES ) ||
164+ (model .now .hour == (model .alarm_start .hour + 1 ) % 24 &&
165+ model .now .minute < (model .alarm_start .minute + TIMEOUT_MINUTES ) % 60 )) {
166+ running = false;
167+ }
119168 }
120169 }
121170
@@ -125,6 +174,7 @@ int32_t clock_settings_alarm(void* p) {
125174 furi_record_close (RECORD_NOTIFICATION );
126175
127176 view_port_enabled_set (view_port , false);
177+ gui_set_lockdown_inhibit (gui , false);
128178 gui_remove_view_port (gui , view_port );
129179 view_port_free (view_port );
130180 furi_message_queue_free (event_queue );
0 commit comments