1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
39 #include "alarm_menu.h"
40 #include "backlight.h"
42 #include "statusbar.h"
45 static void speak_time(int hours
, int minutes
, bool speak_hours
)
47 if (global_settings
.talk_menu
){
49 talk_value(hours
, UNIT_HOUR
, false);
50 talk_value(minutes
, UNIT_MIN
, true);
52 talk_value(minutes
, UNIT_MIN
, false);
57 bool alarm_screen(void)
67 bool hour_wrapped
= false;
68 struct viewport vp
[NB_SCREENS
];
70 rtc_get_alarm(&h
, &m
);
72 /* After a battery change the RTC values are out of range */
73 if (m
> 60 || h
> 24) {
77 m
= m
/ 5 * 5; /* 5 min accuracy should be enough */
81 viewport_set_defaults(&vp
[i
], i
);
89 screens
[i
].set_viewport(&vp
[i
]);
90 screens
[i
].clear_viewport();
91 screens
[i
].puts(0, 3, str(LANG_ALARM_MOD_KEYS
));
93 /* Talk when entering the wakeup screen */
94 if (global_settings
.talk_menu
)
96 talk_value(h
, UNIT_HOUR
, true);
97 talk_value(m
, UNIT_MIN
, true);
102 snprintf(buf
, 32, str(LANG_ALARM_MOD_TIME
), h
, m
);
105 screens
[i
].set_viewport(&vp
[i
]);
106 screens
[i
].puts(0, 1, buf
);
107 screens
[i
].update_viewport();
108 screens
[i
].set_viewport(NULL
);
110 button
= get_action(CONTEXT_SETTINGS
,HZ
);
114 /* prevent that an alarm occurs in the shutdown procedure */
115 /* accept alarms only if they are in 2 minutes or more */
117 togo
= (m
+ h
* 60 - tm
->tm_min
- tm
->tm_hour
* 60 + 1440) % 1440;
122 rtc_enable_alarm(true);
123 if (global_settings
.talk_menu
)
125 talk_id(LANG_ALARM_MOD_TIME_TO_GO
, true);
126 talk_value(togo
/ 60, UNIT_HOUR
, true);
127 talk_value(togo
% 60, UNIT_MIN
, true);
128 talk_force_enqueue_next();
130 gui_syncsplash(HZ
*2, str(LANG_ALARM_MOD_TIME_TO_GO
),
131 togo
/ 60, togo
% 60);
134 gui_syncsplash(HZ
, ID2P(LANG_ALARM_MOD_ERROR
));
140 case ACTION_SETTINGS_INC
:
141 case ACTION_SETTINGS_INCREPEAT
:
151 speak_time(h
, m
, hour_wrapped
);
155 case ACTION_SETTINGS_DEC
:
156 case ACTION_SETTINGS_DECREPEAT
:
166 speak_time(h
, m
, hour_wrapped
);
170 case ACTION_STD_NEXT
:
171 case ACTION_STD_NEXTREPEAT
:
174 if (global_settings
.talk_menu
)
175 talk_value(h
, UNIT_HOUR
, false);
179 case ACTION_STD_PREV
:
180 case ACTION_STD_PREVREPEAT
:
183 if (global_settings
.talk_menu
)
184 talk_value(h
, UNIT_HOUR
, false);
187 case ACTION_STD_CANCEL
:
188 rtc_enable_alarm(false);
189 gui_syncsplash(HZ
*2, ID2P(LANG_ALARM_MOD_DISABLE
));
194 gui_syncstatusbar_draw(&statusbars
, false);
195 hour_wrapped
= false;
199 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
201 rtc_enable_alarm(false);
210 #endif /* HAVE_RTC_ALARM */