Introduce names for header and row color in the tables so that they are the same...
[maemo-rb.git] / apps / alarm_menu.c
blob413d176c7e577a0af466fd302b587f6a097b8891
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 "alarm_menu.h"
41 #include "splash.h"
42 #include "viewport.h"
44 static void speak_time(int hours, int minutes, bool speak_hours)
46 if (global_settings.talk_menu){
47 if(speak_hours) {
48 talk_value(hours, UNIT_HOUR, false);
49 talk_value(minutes, UNIT_MIN, true);
50 } else {
51 talk_value(minutes, UNIT_MIN, false);
56 bool alarm_screen(void)
58 int h, m;
59 bool done=false;
60 char buf[32];
61 struct tm *tm;
62 int togo;
63 int button;
64 int i;
65 bool update = true;
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) {
73 m = 0;
74 h = 12;
75 } else {
76 m = m / 5 * 5; /* 5 min accuracy should be enough */
78 FOR_NB_SCREENS(i)
80 viewport_set_defaults(&vp[i], i);
83 while(!done) {
84 if(update)
86 FOR_NB_SCREENS(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);
98 update = false;
101 snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
102 FOR_NB_SCREENS(i)
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);
111 switch(button) {
112 case ACTION_STD_OK:
113 /* prevent that an alarm occurs in the shutdown procedure */
114 /* accept alarms only if they are in 2 minutes or more */
115 tm = get_time();
116 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
118 if (togo > 1) {
119 rtc_init();
120 rtc_set_alarm(h,m);
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);
131 done = true;
132 } else {
133 splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
134 update = true;
136 break;
138 /* inc(m) */
139 case ACTION_SETTINGS_INC:
140 case ACTION_SETTINGS_INCREPEAT:
141 m += 5;
142 if (m == 60) {
143 h += 1;
144 m = 0;
145 hour_wrapped = true;
147 if (h == 24)
148 h = 0;
150 speak_time(h, m, hour_wrapped);
151 break;
153 /* dec(m) */
154 case ACTION_SETTINGS_DEC:
155 case ACTION_SETTINGS_DECREPEAT:
156 m -= 5;
157 if (m == -5) {
158 h -= 1;
159 m = 55;
160 hour_wrapped = true;
162 if (h == -1)
163 h = 23;
165 speak_time(h, m, hour_wrapped);
166 break;
168 /* inc(h) */
169 case ACTION_STD_NEXT:
170 case ACTION_STD_NEXTREPEAT:
171 h = (h+1) % 24;
173 if (global_settings.talk_menu)
174 talk_value(h, UNIT_HOUR, false);
175 break;
177 /* dec(h) */
178 case ACTION_STD_PREV:
179 case ACTION_STD_PREVREPEAT:
180 h = (h+23) % 24;
182 if (global_settings.talk_menu)
183 talk_value(h, UNIT_HOUR, false);
184 break;
186 case ACTION_STD_CANCEL:
187 rtc_enable_alarm(false);
188 splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
189 done = true;
190 break;
192 case ACTION_NONE:
193 hour_wrapped = false;
194 break;
196 default:
197 if(default_event_handler(button) == SYS_USB_CONNECTED)
199 rtc_enable_alarm(false);
200 return true;
202 break;
205 return false;
208 #endif /* HAVE_RTC_ALARM */