Greek language update by Ioannis Koutoulakis - needs an increase of the language...
[Rockbox.git] / apps / alarm_menu.c
blob93777280d1de60efa9f2296f582b821bdfe4c0fb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2003 Uwe Freese
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
21 #ifdef HAVE_ALARM_MOD
23 #include <stdbool.h>
25 #include "options.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"
39 #include "lang.h"
40 #include "power.h"
41 #include "alarm_menu.h"
42 #include "backlight.h"
44 #include "splash.h"
45 #include "statusbar.h"
46 #include "textarea.h"
47 #define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0)
49 bool alarm_screen(void)
51 int h, m;
52 bool done=false;
53 char buf[32];
54 struct tm *tm;
55 int togo;
56 int button;
57 int i;
58 bool update = true;
61 rtc_get_alarm(&h, &m);
63 /* After a battery change the RTC values are out of range */
64 if (m > 60 || h > 24) {
65 m = 0;
66 h = 12;
67 } else {
68 m = m / 5 * 5; /* 5 min accuracy should be enough */
71 while(!done) {
72 if(update)
74 FOR_NB_SCREENS(i)
76 gui_textarea_clear(&screens[i]);
77 screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS));
79 update = false;
82 snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
83 FOR_NB_SCREENS(i)
85 screens[i].puts(0, 1, buf);
86 gui_textarea_update(&screens[i]);
88 button = get_action(CONTEXT_SETTINGS,HZ);
90 switch(button) {
91 case ACTION_STD_OK:
92 /* prevent that an alarm occurs in the shutdown procedure */
93 /* accept alarms only if they are in 2 minutes or more */
94 tm = get_time();
95 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
96 if (togo > 1) {
97 rtc_init();
98 rtc_set_alarm(h,m);
99 rtc_enable_alarm(true);
100 gui_syncsplash(HZ*2, true, str(LANG_ALARM_MOD_TIME_TO_GO),
101 togo / 60, togo % 60);
102 done = true;
103 } else {
104 gui_syncsplash(HZ, true, str(LANG_ALARM_MOD_ERROR));
105 update = true;
107 break;
109 /* inc(m) */
110 case ACTION_SETTINGS_INC:
111 case ACTION_SETTINGS_INCREPEAT:
112 m += 5;
113 if (m == 60) {
114 h += 1;
115 m = 0;
117 if (h == 24)
118 h = 0;
119 break;
121 /* dec(m) */
122 case ACTION_SETTINGS_DEC:
123 case ACTION_SETTINGS_DECREPEAT:
124 m -= 5;
125 if (m == -5) {
126 h -= 1;
127 m = 55;
129 if (h == -1)
130 h = 23;
131 break;
133 /* inc(h) */
134 case ACTION_STD_NEXT:
135 case ACTION_STD_NEXTREPEAT:
136 h = (h+1) % 24;
137 break;
139 /* dec(h) */
140 case ACTION_STD_PREV:
141 case ACTION_STD_PREVREPEAT:
142 h = (h+23) % 24;
143 break;
145 case ACTION_STD_CANCEL:
146 rtc_enable_alarm(false);
147 gui_syncsplash(HZ*2, true, str(LANG_ALARM_MOD_DISABLE));
148 done = true;
149 break;
151 case ACTION_NONE:
152 gui_syncstatusbar_draw(&statusbars, false);
153 break;
155 default:
156 if(default_event_handler(button) == SYS_USB_CONNECTED)
158 rtc_enable_alarm(false);
159 return true;
161 break;
164 action_signalscreenchange();
165 return false;
168 #endif /* HAVE_ALARM_MOD */