1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2003 Uwe Freese
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
41 #include "alarm_menu.h"
42 #include "backlight.h"
44 #include "statusbar.h"
47 static void speak_time(int hours
, int minutes
, bool speak_hours
)
49 if (global_settings
.talk_menu
){
51 talk_value(hours
, UNIT_HOUR
, false);
52 talk_value(minutes
, UNIT_MIN
, true);
54 talk_value(minutes
, UNIT_MIN
, false);
59 bool alarm_screen(void)
69 bool hour_wrapped
= false;
70 struct viewport vp
[NB_SCREENS
];
72 rtc_get_alarm(&h
, &m
);
74 /* After a battery change the RTC values are out of range */
75 if (m
> 60 || h
> 24) {
79 m
= m
/ 5 * 5; /* 5 min accuracy should be enough */
83 viewport_set_defaults(&vp
[i
], i
);
91 screens
[i
].set_viewport(&vp
[i
]);
92 screens
[i
].clear_viewport();
93 screens
[i
].puts(0, 3, str(LANG_ALARM_MOD_KEYS
));
95 /* Talk when entering the wakeup screen */
96 if (global_settings
.talk_menu
)
98 talk_value(h
, UNIT_HOUR
, true);
99 talk_value(m
, UNIT_MIN
, true);
104 snprintf(buf
, 32, str(LANG_ALARM_MOD_TIME
), h
, m
);
107 screens
[i
].set_viewport(&vp
[i
]);
108 screens
[i
].puts(0, 1, buf
);
109 screens
[i
].update_viewport();
110 screens
[i
].set_viewport(NULL
);
112 button
= get_action(CONTEXT_SETTINGS
,HZ
);
116 /* prevent that an alarm occurs in the shutdown procedure */
117 /* accept alarms only if they are in 2 minutes or more */
119 togo
= (m
+ h
* 60 - tm
->tm_min
- tm
->tm_hour
* 60 + 1440) % 1440;
124 rtc_enable_alarm(true);
125 if (global_settings
.talk_menu
)
127 talk_id(LANG_ALARM_MOD_TIME_TO_GO
, true);
128 talk_value(togo
/ 60, UNIT_HOUR
, true);
129 talk_value(togo
% 60, UNIT_MIN
, true);
130 talk_force_enqueue_next();
132 splashf(HZ
*2, str(LANG_ALARM_MOD_TIME_TO_GO
),
133 togo
/ 60, togo
% 60);
136 splash(HZ
, ID2P(LANG_ALARM_MOD_ERROR
));
142 case ACTION_SETTINGS_INC
:
143 case ACTION_SETTINGS_INCREPEAT
:
153 speak_time(h
, m
, hour_wrapped
);
157 case ACTION_SETTINGS_DEC
:
158 case ACTION_SETTINGS_DECREPEAT
:
168 speak_time(h
, m
, hour_wrapped
);
172 case ACTION_STD_NEXT
:
173 case ACTION_STD_NEXTREPEAT
:
176 if (global_settings
.talk_menu
)
177 talk_value(h
, UNIT_HOUR
, false);
181 case ACTION_STD_PREV
:
182 case ACTION_STD_PREVREPEAT
:
185 if (global_settings
.talk_menu
)
186 talk_value(h
, UNIT_HOUR
, false);
189 case ACTION_STD_CANCEL
:
190 rtc_enable_alarm(false);
191 splash(HZ
*2, ID2P(LANG_ALARM_MOD_DISABLE
));
196 gui_syncstatusbar_draw(&statusbars
, false);
197 hour_wrapped
= false;
201 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
203 rtc_enable_alarm(false);
212 #endif /* HAVE_RTC_ALARM */