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 ****************************************************************************/
40 #include "alarm_menu.h"
44 static void speak_time(int hours
, int minutes
, bool speak_hours
)
46 if (global_settings
.talk_menu
){
48 talk_value(hours
, UNIT_HOUR
, false);
49 talk_value(minutes
, UNIT_MIN
, true);
51 talk_value(minutes
, UNIT_MIN
, false);
56 bool alarm_screen(void)
66 bool hour_wrapped
= false;
67 struct viewport vp
[NB_SCREENS
];
69 rtc_get_alarm(&h
, &m
);
71 /* After a battery change the RTC values are out of range */
72 if (m
> 60 || h
> 24) {
76 m
= m
/ 5 * 5; /* 5 min accuracy should be enough */
80 viewport_set_defaults(&vp
[i
], i
);
88 screens
[i
].set_viewport(&vp
[i
]);
89 screens
[i
].clear_viewport();
90 screens
[i
].puts(0, 3, str(LANG_ALARM_MOD_KEYS
));
92 /* Talk when entering the wakeup screen */
93 if (global_settings
.talk_menu
)
95 talk_value(h
, UNIT_HOUR
, true);
96 talk_value(m
, UNIT_MIN
, true);
101 snprintf(buf
, 32, str(LANG_ALARM_MOD_TIME
), h
, m
);
104 screens
[i
].set_viewport(&vp
[i
]);
105 screens
[i
].puts(0, 1, buf
);
106 screens
[i
].update_viewport();
107 screens
[i
].set_viewport(NULL
);
109 button
= get_action(CONTEXT_SETTINGS
,HZ
);
113 /* prevent that an alarm occurs in the shutdown procedure */
114 /* accept alarms only if they are in 2 minutes or more */
116 togo
= (m
+ h
* 60 - tm
->tm_min
- tm
->tm_hour
* 60 + 1440) % 1440;
121 rtc_enable_alarm(true);
122 if (global_settings
.talk_menu
)
124 talk_id(LANG_ALARM_MOD_TIME_TO_GO
, true);
125 talk_value(togo
/ 60, UNIT_HOUR
, true);
126 talk_value(togo
% 60, UNIT_MIN
, true);
127 talk_force_enqueue_next();
129 splashf(HZ
*2, str(LANG_ALARM_MOD_TIME_TO_GO
),
130 togo
/ 60, togo
% 60);
133 splash(HZ
, ID2P(LANG_ALARM_MOD_ERROR
));
139 case ACTION_SETTINGS_INC
:
140 case ACTION_SETTINGS_INCREPEAT
:
150 speak_time(h
, m
, hour_wrapped
);
154 case ACTION_SETTINGS_DEC
:
155 case ACTION_SETTINGS_DECREPEAT
:
165 speak_time(h
, m
, hour_wrapped
);
169 case ACTION_STD_NEXT
:
170 case ACTION_STD_NEXTREPEAT
:
173 if (global_settings
.talk_menu
)
174 talk_value(h
, UNIT_HOUR
, false);
178 case ACTION_STD_PREV
:
179 case ACTION_STD_PREVREPEAT
:
182 if (global_settings
.talk_menu
)
183 talk_value(h
, UNIT_HOUR
, false);
186 case ACTION_STD_CANCEL
:
187 rtc_enable_alarm(false);
188 splash(HZ
*2, ID2P(LANG_ALARM_MOD_DISABLE
));
193 hour_wrapped
= false;
197 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
199 rtc_enable_alarm(false);
208 #endif /* HAVE_RTC_ALARM */