Add the glyph range to the comment. Cyrillic glyphs were taken from FS#9834 (thanks...
[kugel-rb/myfork.git] / apps / alarm_menu.c
blob3c3ed3de39ccc8dc95876bc18f25d0d7755a9466
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
23 #ifdef HAVE_RTC_ALARM
25 #include <stdbool.h>
27 #include "lcd.h"
28 #include "action.h"
29 #include "kernel.h"
30 #include "sprintf.h"
31 #include <string.h>
32 #include "settings.h"
33 #include "power.h"
34 #include "icons.h"
35 #include "rtc.h"
36 #include "misc.h"
37 #include "screens.h"
38 #include "talk.h"
39 #include "lang.h"
40 #include "power.h"
41 #include "alarm_menu.h"
42 #include "backlight.h"
43 #include "splash.h"
44 #include "statusbar.h"
45 #include "viewport.h"
47 static void speak_time(int hours, int minutes, bool speak_hours)
49 if (global_settings.talk_menu){
50 if(speak_hours) {
51 talk_value(hours, UNIT_HOUR, false);
52 talk_value(minutes, UNIT_MIN, true);
53 } else {
54 talk_value(minutes, UNIT_MIN, false);
59 bool alarm_screen(void)
61 int h, m;
62 bool done=false;
63 char buf[32];
64 struct tm *tm;
65 int togo;
66 int button;
67 int i;
68 bool update = true;
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) {
76 m = 0;
77 h = 12;
78 } else {
79 m = m / 5 * 5; /* 5 min accuracy should be enough */
81 FOR_NB_SCREENS(i)
83 viewport_set_defaults(&vp[i], i);
86 while(!done) {
87 if(update)
89 FOR_NB_SCREENS(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);
101 update = false;
104 snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
105 FOR_NB_SCREENS(i)
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);
114 switch(button) {
115 case ACTION_STD_OK:
116 /* prevent that an alarm occurs in the shutdown procedure */
117 /* accept alarms only if they are in 2 minutes or more */
118 tm = get_time();
119 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
121 if (togo > 1) {
122 rtc_init();
123 rtc_set_alarm(h,m);
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);
134 done = true;
135 } else {
136 splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
137 update = true;
139 break;
141 /* inc(m) */
142 case ACTION_SETTINGS_INC:
143 case ACTION_SETTINGS_INCREPEAT:
144 m += 5;
145 if (m == 60) {
146 h += 1;
147 m = 0;
148 hour_wrapped = true;
150 if (h == 24)
151 h = 0;
153 speak_time(h, m, hour_wrapped);
154 break;
156 /* dec(m) */
157 case ACTION_SETTINGS_DEC:
158 case ACTION_SETTINGS_DECREPEAT:
159 m -= 5;
160 if (m == -5) {
161 h -= 1;
162 m = 55;
163 hour_wrapped = true;
165 if (h == -1)
166 h = 23;
168 speak_time(h, m, hour_wrapped);
169 break;
171 /* inc(h) */
172 case ACTION_STD_NEXT:
173 case ACTION_STD_NEXTREPEAT:
174 h = (h+1) % 24;
176 if (global_settings.talk_menu)
177 talk_value(h, UNIT_HOUR, false);
178 break;
180 /* dec(h) */
181 case ACTION_STD_PREV:
182 case ACTION_STD_PREVREPEAT:
183 h = (h+23) % 24;
185 if (global_settings.talk_menu)
186 talk_value(h, UNIT_HOUR, false);
187 break;
189 case ACTION_STD_CANCEL:
190 rtc_enable_alarm(false);
191 splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
192 done = true;
193 break;
195 case ACTION_NONE:
196 hour_wrapped = false;
197 break;
199 default:
200 if(default_event_handler(button) == SYS_USB_CONNECTED)
202 rtc_enable_alarm(false);
203 return true;
205 break;
208 return false;
211 #endif /* HAVE_RTC_ALARM */