Fix for ff/rw in long MP3 files.
[kugel-rb.git] / apps / alarm_menu.c
blobe8b421955c877c1df3d2f0c5206e70f81f1fdb6a
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 "font.h"
29 #include "button.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include <string.h>
33 #include "settings.h"
34 #include "power.h"
35 #include "status.h"
36 #include "icons.h"
37 #include "rtc.h"
38 #include "misc.h"
39 #include "screens.h"
41 #include "lang.h"
42 #include "power.h"
43 #include "alarm_menu.h"
44 #include "backlight.h"
46 #define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0)
48 bool alarm_screen(void)
50 int h, m;
51 bool done=false;
52 char buf[32];
53 struct tm *tm;
54 int togo;
55 int button;
56 bool update = true;
58 rtc_get_alarm(&h, &m);
60 /* After a battery change the RTC values are out of range */
61 if (m > 60 || h > 24) {
62 m = 0;
63 h = 12;
64 } else {
65 m = m / 5 * 5; /* 5 min accuracy should be enough */
68 while(!done) {
69 if(update)
71 lcd_clear_display();
72 status_draw(true);
73 lcd_setfont(FONT_SYSFIXED);
74 lcd_setmargins(0, MARGIN_Y);
75 lcd_puts(0, 3, str(LANG_ALARM_MOD_KEYS));
76 update = false;
79 snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
80 lcd_puts(0, 1, buf);
81 lcd_update();
83 button = button_get_w_tmo(HZ);
85 switch(button) {
86 case BUTTON_PLAY:
87 /* prevent that an alarm occurs in the shutdown procedure */
88 /* accept alarms only if they are in 2 minutes or more */
89 tm = get_time();
90 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
91 if (togo > 1) {
92 rtc_init();
93 rtc_set_alarm(h,m);
94 rtc_enable_alarm(true);
95 splash(HZ*2, true, str(LANG_ALARM_MOD_TIME_TO_GO),
96 togo / 60, togo % 60);
97 done = true;
98 } else {
99 splash(HZ, true, str(LANG_ALARM_MOD_ERROR));
100 update = true;
102 break;
104 /* inc(m) */
105 case BUTTON_RIGHT:
106 case BUTTON_RIGHT | BUTTON_REPEAT:
107 m += 5;
108 if (m == 60) {
109 h += 1;
110 m = 0;
112 if (h == 24)
113 h = 0;
114 break;
116 /* dec(m) */
117 case BUTTON_LEFT:
118 case BUTTON_LEFT | BUTTON_REPEAT:
119 m -= 5;
120 if (m == -5) {
121 h -= 1;
122 m = 55;
124 if (h == -1)
125 h = 23;
126 break;
128 #if CONFIG_KEYPAD == RECORDER_PAD
129 /* inc(h) */
130 case BUTTON_UP:
131 case BUTTON_UP | BUTTON_REPEAT:
132 h = (h+1) % 24;
133 break;
135 /* dec(h) */
136 case BUTTON_DOWN:
137 case BUTTON_DOWN | BUTTON_REPEAT:
138 h = (h+23) % 24;
139 break;
140 #endif
142 #if CONFIG_KEYPAD == RECORDER_PAD
143 case BUTTON_OFF:
144 #else
145 case BUTTON_STOP:
146 case BUTTON_MENU:
147 #endif
148 rtc_enable_alarm(false);
149 splash(HZ*2, true, str(LANG_ALARM_MOD_DISABLE));
150 done = true;
151 break;
153 case BUTTON_NONE:
154 status_draw(false);
155 break;
157 default:
158 if(default_event_handler(button) == SYS_USB_CONNECTED)
160 rtc_enable_alarm(false);
161 return true;
163 break;
167 return false;
170 #endif /* HAVE_ALARM_MOD */