skin tags: fix the id3 track/disc numbers in conditionals
[maemo-rb.git] / apps / alarm_menu.c
blob12bc03ca20209c558d169e2eee8542834103eb1d
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 #include <stdbool.h>
25 #include "lcd.h"
26 #include "action.h"
27 #include "kernel.h"
28 #include <string.h>
29 #include "settings.h"
30 #include "power.h"
31 #include "icons.h"
32 #include "rtc.h"
33 #include "misc.h"
34 #include "screens.h"
35 #include "talk.h"
36 #include "lang.h"
37 #include "alarm_menu.h"
38 #include "splash.h"
39 #include "viewport.h"
41 static void speak_time(int hours, int minutes, bool speak_hours, bool enqueue)
43 if (global_settings.talk_menu){
44 if(speak_hours) {
45 talk_value(hours, UNIT_HOUR, enqueue);
46 talk_value(minutes, UNIT_MIN, true);
47 } else {
48 talk_value(minutes, UNIT_MIN, enqueue);
53 bool alarm_screen(void)
55 int h, m;
56 bool done = false;
57 struct tm *tm;
58 int togo;
59 int button;
60 bool update = true;
61 bool hour_wrapped = false;
62 struct viewport vp[NB_SCREENS];
64 rtc_get_alarm(&h, &m);
66 /* After a battery change the RTC values are out of range */
67 if (m > 60 || h > 24) {
68 m = 0;
69 h = 12;
70 } else {
71 m = m / 5 * 5; /* 5 min accuracy should be enough */
73 FOR_NB_SCREENS(i)
75 viewport_set_defaults(&vp[i], i);
78 while(!done) {
79 if(update)
81 FOR_NB_SCREENS(i)
83 screens[i].set_viewport(&vp[i]);
84 screens[i].clear_viewport();
85 screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS));
87 /* Talk when entering the wakeup screen */
88 speak_time(h, m, true, true);
89 update = false;
92 FOR_NB_SCREENS(i)
94 screens[i].set_viewport(&vp[i]);
95 screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME));
96 screens[i].putsf(0, 2, "%02d:%02d", h, m);
97 screens[i].update_viewport();
98 screens[i].set_viewport(NULL);
100 button = get_action(CONTEXT_SETTINGS,HZ);
102 switch(button) {
103 case ACTION_STD_OK:
104 /* prevent that an alarm occurs in the shutdown procedure */
105 /* accept alarms only if they are in 2 minutes or more */
106 tm = get_time();
107 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
109 if (togo > 1) {
110 rtc_init();
111 rtc_set_alarm(h,m);
112 rtc_enable_alarm(true);
113 if (global_settings.talk_menu)
115 talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
116 talk_value(togo / 60, UNIT_HOUR, true);
117 talk_value(togo % 60, UNIT_MIN, true);
118 talk_force_enqueue_next();
120 splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
121 togo / 60, togo % 60);
122 done = true;
123 } else {
124 splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
125 update = true;
127 break;
129 /* inc(m) */
130 case ACTION_SETTINGS_INC:
131 case ACTION_SETTINGS_INCREPEAT:
132 m += 5;
133 if (m == 60) {
134 h += 1;
135 m = 0;
136 hour_wrapped = true;
138 if (h == 24)
139 h = 0;
141 speak_time(h, m, hour_wrapped, false);
142 break;
144 /* dec(m) */
145 case ACTION_SETTINGS_DEC:
146 case ACTION_SETTINGS_DECREPEAT:
147 m -= 5;
148 if (m == -5) {
149 h -= 1;
150 m = 55;
151 hour_wrapped = true;
153 if (h == -1)
154 h = 23;
156 speak_time(h, m, hour_wrapped, false);
157 break;
159 /* inc(h) */
160 case ACTION_STD_NEXT:
161 case ACTION_STD_NEXTREPEAT:
162 h = (h+1) % 24;
164 if (global_settings.talk_menu)
165 talk_value(h, UNIT_HOUR, false);
166 break;
168 /* dec(h) */
169 case ACTION_STD_PREV:
170 case ACTION_STD_PREVREPEAT:
171 h = (h+23) % 24;
173 if (global_settings.talk_menu)
174 talk_value(h, UNIT_HOUR, false);
175 break;
177 case ACTION_STD_CANCEL:
178 rtc_enable_alarm(false);
179 splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
180 done = true;
181 break;
183 case ACTION_NONE:
184 hour_wrapped = false;
185 break;
187 default:
188 if(default_event_handler(button) == SYS_USB_CONNECTED)
190 rtc_enable_alarm(false);
191 return true;
193 break;
196 return false;