1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2003 Uwe Freese
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
#include <stdbool.h>
#include "lcd.h"
#include "action.h"
#include "kernel.h"
#include <string.h>
#include "settings.h"
#include "power.h"
#include "icons.h"
#include "rtc.h"
#include "misc.h"
#include "screens.h"
#include "talk.h"
#include "lang.h"
#include "alarm_menu.h"
#include "splash.h"
#include "viewport.h"
static void speak_time(int hours, int minutes, bool speak_hours, bool enqueue)
{
if (global_settings.talk_menu){
if(speak_hours) {
talk_value(hours, UNIT_HOUR, enqueue);
talk_value(minutes, UNIT_MIN, true);
} else {
talk_value(minutes, UNIT_MIN, enqueue);
}
}
}
bool alarm_screen(void)
{
int h, m;
bool done = false;
struct tm *tm;
int togo;
int button;
int i;
bool update = true;
bool hour_wrapped = false;
struct viewport vp[NB_SCREENS];
rtc_get_alarm(&h, &m);
/* After a battery change the RTC values are out of range */
if (m > 60 || h > 24) {
m = 0;
h = 12;
} else {
m = m / 5 * 5; /* 5 min accuracy should be enough */
}
FOR_NB_SCREENS(i)
{
viewport_set_defaults(&vp[i], i);
}
while(!done) {
if(update)
{
FOR_NB_SCREENS(i)
{
screens[i].set_viewport(&vp[i]);
screens[i].clear_viewport();
screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS));
}
/* Talk when entering the wakeup screen */
speak_time(h, m, true, true);
update = false;
}
FOR_NB_SCREENS(i)
{
screens[i].set_viewport(&vp[i]);
screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME), h, m);
screens[i].update_viewport();
screens[i].set_viewport(NULL);
}
button = get_action(CONTEXT_SETTINGS,HZ);
switch(button) {
case ACTION_STD_OK:
/* prevent that an alarm occurs in the shutdown procedure */
/* accept alarms only if they are in 2 minutes or more */
tm = get_time();
togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
if (togo > 1) {
rtc_init();
rtc_set_alarm(h,m);
rtc_enable_alarm(true);
if (global_settings.talk_menu)
{
talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
talk_value(togo / 60, UNIT_HOUR, true);
talk_value(togo % 60, UNIT_MIN, true);
talk_force_enqueue_next();
}
splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
togo / 60, togo % 60);
done = true;
} else {
splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
update = true;
}
break;
/* inc(m) */
case ACTION_SETTINGS_INC:
case ACTION_SETTINGS_INCREPEAT:
m += 5;
if (m == 60) {
h += 1;
m = 0;
hour_wrapped = true;
}
if (h == 24)
h = 0;
speak_time(h, m, hour_wrapped, false);
break;
/* dec(m) */
case ACTION_SETTINGS_DEC:
case ACTION_SETTINGS_DECREPEAT:
m -= 5;
if (m == -5) {
h -= 1;
m = 55;
hour_wrapped = true;
}
if (h == -1)
h = 23;
speak_time(h, m, hour_wrapped, false);
break;
/* inc(h) */
case ACTION_STD_NEXT:
case ACTION_STD_NEXTREPEAT:
h = (h+1) % 24;
if (global_settings.talk_menu)
talk_value(h, UNIT_HOUR, false);
break;
/* dec(h) */
case ACTION_STD_PREV:
case ACTION_STD_PREVREPEAT:
h = (h+23) % 24;
if (global_settings.talk_menu)
talk_value(h, UNIT_HOUR, false);
break;
case ACTION_STD_CANCEL:
rtc_enable_alarm(false);
splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
done = true;
break;
case ACTION_NONE:
hour_wrapped = false;
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
{
rtc_enable_alarm(false);
return true;
}
break;
}
}
return false;
}
|