Fix b&w LCD targets.
[maemo-rb.git] / apps / alarm_menu.c
blobae5d5bb7526de21c023b690b8606841fdddf9628
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 "button.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;
60 rtc_get_alarm(&h, &m);
62 /* After a battery change the RTC values are out of range */
63 if (m > 60 || h > 24) {
64 m = 0;
65 h = 12;
66 } else {
67 m = m / 5 * 5; /* 5 min accuracy should be enough */
70 while(!done) {
71 if(update)
73 FOR_NB_SCREENS(i)
75 gui_textarea_clear(&screens[i]);
76 screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS));
78 update = false;
81 snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
82 FOR_NB_SCREENS(i)
84 screens[i].puts(0, 1, buf);
85 gui_textarea_update(&screens[i]);
87 button = button_get_w_tmo(HZ);
89 switch(button) {
90 case BUTTON_PLAY:
91 /* prevent that an alarm occurs in the shutdown procedure */
92 /* accept alarms only if they are in 2 minutes or more */
93 tm = get_time();
94 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
95 if (togo > 1) {
96 rtc_init();
97 rtc_set_alarm(h,m);
98 rtc_enable_alarm(true);
99 gui_syncsplash(HZ*2, true, str(LANG_ALARM_MOD_TIME_TO_GO),
100 togo / 60, togo % 60);
101 done = true;
102 } else {
103 gui_syncsplash(HZ, true, str(LANG_ALARM_MOD_ERROR));
104 update = true;
106 break;
108 /* inc(m) */
109 case BUTTON_RIGHT:
110 case BUTTON_RIGHT | BUTTON_REPEAT:
111 m += 5;
112 if (m == 60) {
113 h += 1;
114 m = 0;
116 if (h == 24)
117 h = 0;
118 break;
120 /* dec(m) */
121 case BUTTON_LEFT:
122 case BUTTON_LEFT | BUTTON_REPEAT:
123 m -= 5;
124 if (m == -5) {
125 h -= 1;
126 m = 55;
128 if (h == -1)
129 h = 23;
130 break;
132 #if CONFIG_KEYPAD == RECORDER_PAD
133 /* inc(h) */
134 case BUTTON_UP:
135 case BUTTON_UP | BUTTON_REPEAT:
136 h = (h+1) % 24;
137 break;
139 /* dec(h) */
140 case BUTTON_DOWN:
141 case BUTTON_DOWN | BUTTON_REPEAT:
142 h = (h+23) % 24;
143 break;
144 #endif
146 #if CONFIG_KEYPAD == RECORDER_PAD
147 case BUTTON_OFF:
148 #else
149 case BUTTON_STOP:
150 case BUTTON_MENU:
151 #endif
152 rtc_enable_alarm(false);
153 gui_syncsplash(HZ*2, true, str(LANG_ALARM_MOD_DISABLE));
154 done = true;
155 break;
157 case BUTTON_NONE:
158 gui_syncstatusbar_draw(&statusbars, false);
159 break;
161 default:
162 if(default_event_handler(button) == SYS_USB_CONNECTED)
164 rtc_enable_alarm(false);
165 return true;
167 break;
171 return false;
174 #endif /* HAVE_ALARM_MOD */