Fix FS#10215 - peakmeter updates breaks scrolling lines in conditionally enalbed...
[kugel-rb.git] / apps / alarm_menu.c
blob6473bbab825e540290f8f077d8f41e27bb8ff664
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, bool enqueue)
46 if (global_settings.talk_menu){
47 if(speak_hours) {
48 talk_value(hours, UNIT_HOUR, enqueue);
49 talk_value(minutes, UNIT_MIN, true);
50 } else {
51 talk_value(minutes, UNIT_MIN, enqueue);
56 bool alarm_screen(void)
58 int h, m;
59 bool done = false;
60 struct tm *tm;
61 int togo;
62 int button;
63 int i;
64 bool update = true;
65 bool hour_wrapped = false;
66 struct viewport vp[NB_SCREENS];
68 rtc_get_alarm(&h, &m);
70 /* After a battery change the RTC values are out of range */
71 if (m > 60 || h > 24) {
72 m = 0;
73 h = 12;
74 } else {
75 m = m / 5 * 5; /* 5 min accuracy should be enough */
77 FOR_NB_SCREENS(i)
79 viewport_set_defaults(&vp[i], i);
82 while(!done) {
83 if(update)
85 FOR_NB_SCREENS(i)
87 screens[i].set_viewport(&vp[i]);
88 screens[i].clear_viewport();
89 screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS));
91 /* Talk when entering the wakeup screen */
92 speak_time(h, m, true, true);
93 update = false;
96 FOR_NB_SCREENS(i)
98 screens[i].set_viewport(&vp[i]);
99 screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME), h, m);
100 screens[i].update_viewport();
101 screens[i].set_viewport(NULL);
103 button = get_action(CONTEXT_SETTINGS,HZ);
105 switch(button) {
106 case ACTION_STD_OK:
107 /* prevent that an alarm occurs in the shutdown procedure */
108 /* accept alarms only if they are in 2 minutes or more */
109 tm = get_time();
110 togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
112 if (togo > 1) {
113 rtc_init();
114 rtc_set_alarm(h,m);
115 rtc_enable_alarm(true);
116 if (global_settings.talk_menu)
118 talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
119 talk_value(togo / 60, UNIT_HOUR, true);
120 talk_value(togo % 60, UNIT_MIN, true);
121 talk_force_enqueue_next();
123 splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
124 togo / 60, togo % 60);
125 done = true;
126 } else {
127 splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
128 update = true;
130 break;
132 /* inc(m) */
133 case ACTION_SETTINGS_INC:
134 case ACTION_SETTINGS_INCREPEAT:
135 m += 5;
136 if (m == 60) {
137 h += 1;
138 m = 0;
139 hour_wrapped = true;
141 if (h == 24)
142 h = 0;
144 speak_time(h, m, hour_wrapped, false);
145 break;
147 /* dec(m) */
148 case ACTION_SETTINGS_DEC:
149 case ACTION_SETTINGS_DECREPEAT:
150 m -= 5;
151 if (m == -5) {
152 h -= 1;
153 m = 55;
154 hour_wrapped = true;
156 if (h == -1)
157 h = 23;
159 speak_time(h, m, hour_wrapped, false);
160 break;
162 /* inc(h) */
163 case ACTION_STD_NEXT:
164 case ACTION_STD_NEXTREPEAT:
165 h = (h+1) % 24;
167 if (global_settings.talk_menu)
168 talk_value(h, UNIT_HOUR, false);
169 break;
171 /* dec(h) */
172 case ACTION_STD_PREV:
173 case ACTION_STD_PREVREPEAT:
174 h = (h+23) % 24;
176 if (global_settings.talk_menu)
177 talk_value(h, UNIT_HOUR, false);
178 break;
180 case ACTION_STD_CANCEL:
181 rtc_enable_alarm(false);
182 splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
183 done = true;
184 break;
186 case ACTION_NONE:
187 hour_wrapped = false;
188 break;
190 default:
191 if(default_event_handler(button) == SYS_USB_CONNECTED)
193 rtc_enable_alarm(false);
194 return true;
196 break;
199 return false;
202 #endif /* HAVE_RTC_ALARM */