2003-01-22 12:50:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Uwe Freese
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2003-01-22 12:50:34 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
2005-07-06 08:24:24 +00:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
#include "lcd.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2003-01-22 12:50:34 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "settings.h"
|
|
|
|
#include "power.h"
|
2005-07-06 08:24:24 +00:00
|
|
|
#include "icons.h"
|
2003-01-22 12:50:34 +00:00
|
|
|
#include "rtc.h"
|
2005-07-06 08:24:24 +00:00
|
|
|
#include "misc.h"
|
|
|
|
#include "screens.h"
|
2008-05-29 08:20:07 +00:00
|
|
|
#include "talk.h"
|
2003-01-22 12:50:34 +00:00
|
|
|
#include "lang.h"
|
|
|
|
#include "alarm_menu.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2008-05-29 08:20:07 +00:00
|
|
|
#include "viewport.h"
|
2003-01-22 12:50:34 +00:00
|
|
|
|
2009-10-17 18:02:48 +00:00
|
|
|
static void speak_time(int hours, int minutes, bool speak_hours, bool enqueue)
|
2007-10-04 08:56:49 +00:00
|
|
|
{
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu){
|
2007-10-04 08:56:49 +00:00
|
|
|
if(speak_hours) {
|
2009-10-17 18:02:48 +00:00
|
|
|
talk_value(hours, UNIT_HOUR, enqueue);
|
2007-10-04 08:56:49 +00:00
|
|
|
talk_value(minutes, UNIT_MIN, true);
|
|
|
|
} else {
|
2009-10-17 18:02:48 +00:00
|
|
|
talk_value(minutes, UNIT_MIN, enqueue);
|
2007-10-04 08:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
bool alarm_screen(void)
|
|
|
|
{
|
2005-07-06 08:24:24 +00:00
|
|
|
int h, m;
|
2009-10-17 18:02:48 +00:00
|
|
|
bool done = false;
|
2005-07-06 08:24:24 +00:00
|
|
|
struct tm *tm;
|
|
|
|
int togo;
|
|
|
|
int button;
|
|
|
|
bool update = true;
|
2007-10-04 08:56:49 +00:00
|
|
|
bool hour_wrapped = false;
|
2008-05-29 08:20:07 +00:00
|
|
|
struct viewport vp[NB_SCREENS];
|
2003-03-03 14:23:39 +00:00
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
rtc_get_alarm(&h, &m);
|
2003-03-03 14:23:39 +00:00
|
|
|
|
2005-07-06 08:24:24 +00:00
|
|
|
/* After a battery change the RTC values are out of range */
|
|
|
|
if (m > 60 || h > 24) {
|
2003-03-03 14:23:39 +00:00
|
|
|
m = 0;
|
|
|
|
h = 12;
|
|
|
|
} else {
|
|
|
|
m = m / 5 * 5; /* 5 min accuracy should be enough */
|
|
|
|
}
|
2008-05-29 08:20:07 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
viewport_set_defaults(&vp[i], i);
|
|
|
|
}
|
2003-03-03 14:23:39 +00:00
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
while(!done) {
|
2005-07-06 08:24:24 +00:00
|
|
|
if(update)
|
|
|
|
{
|
2005-11-20 01:02:14 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2008-05-29 08:20:07 +00:00
|
|
|
screens[i].set_viewport(&vp[i]);
|
|
|
|
screens[i].clear_viewport();
|
2010-05-22 00:28:10 +00:00
|
|
|
screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS));
|
2005-11-20 01:02:14 +00:00
|
|
|
}
|
2007-10-04 08:56:49 +00:00
|
|
|
/* Talk when entering the wakeup screen */
|
2009-10-17 18:02:48 +00:00
|
|
|
speak_time(h, m, true, true);
|
2005-07-06 08:24:24 +00:00
|
|
|
update = false;
|
|
|
|
}
|
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2008-05-29 08:20:07 +00:00
|
|
|
screens[i].set_viewport(&vp[i]);
|
2010-05-22 00:28:10 +00:00
|
|
|
screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME));
|
|
|
|
screens[i].putsf(0, 2, "%02d:%02d", h, m);
|
2008-05-29 08:20:07 +00:00
|
|
|
screens[i].update_viewport();
|
|
|
|
screens[i].set_viewport(NULL);
|
2005-11-20 01:02:14 +00:00
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
button = get_action(CONTEXT_SETTINGS,HZ);
|
2005-11-20 01:02:14 +00:00
|
|
|
|
2005-07-06 08:24:24 +00:00
|
|
|
switch(button) {
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_OK:
|
2003-01-22 12:50:34 +00:00
|
|
|
/* prevent that an alarm occurs in the shutdown procedure */
|
|
|
|
/* accept alarms only if they are in 2 minutes or more */
|
2005-07-06 08:24:24 +00:00
|
|
|
tm = get_time();
|
|
|
|
togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
|
2007-10-04 08:56:49 +00:00
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
if (togo > 1) {
|
|
|
|
rtc_init();
|
|
|
|
rtc_set_alarm(h,m);
|
2005-02-06 17:21:42 +00:00
|
|
|
rtc_enable_alarm(true);
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu)
|
2007-10-04 08:56:49 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
|
2007-10-04 08:56:49 +00:00
|
|
|
togo / 60, togo % 60);
|
2005-11-20 01:02:14 +00:00
|
|
|
done = true;
|
2003-01-22 12:50:34 +00:00
|
|
|
} else {
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
|
2005-07-06 08:24:24 +00:00
|
|
|
update = true;
|
2003-01-22 12:50:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* inc(m) */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_SETTINGS_INC:
|
|
|
|
case ACTION_SETTINGS_INCREPEAT:
|
2003-01-22 12:50:34 +00:00
|
|
|
m += 5;
|
|
|
|
if (m == 60) {
|
|
|
|
h += 1;
|
|
|
|
m = 0;
|
2007-10-04 08:56:49 +00:00
|
|
|
hour_wrapped = true;
|
2003-01-22 12:50:34 +00:00
|
|
|
}
|
|
|
|
if (h == 24)
|
|
|
|
h = 0;
|
2007-10-04 08:56:49 +00:00
|
|
|
|
2009-10-17 18:02:48 +00:00
|
|
|
speak_time(h, m, hour_wrapped, false);
|
2003-01-22 12:50:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* dec(m) */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_SETTINGS_DEC:
|
|
|
|
case ACTION_SETTINGS_DECREPEAT:
|
2003-01-22 12:50:34 +00:00
|
|
|
m -= 5;
|
|
|
|
if (m == -5) {
|
|
|
|
h -= 1;
|
|
|
|
m = 55;
|
2007-10-04 08:56:49 +00:00
|
|
|
hour_wrapped = true;
|
2003-01-22 12:50:34 +00:00
|
|
|
}
|
|
|
|
if (h == -1)
|
|
|
|
h = 23;
|
2007-10-04 08:56:49 +00:00
|
|
|
|
2009-10-17 18:02:48 +00:00
|
|
|
speak_time(h, m, hour_wrapped, false);
|
2003-01-22 12:50:34 +00:00
|
|
|
break;
|
2005-11-20 01:02:14 +00:00
|
|
|
|
|
|
|
/* inc(h) */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_NEXT:
|
|
|
|
case ACTION_STD_NEXTREPEAT:
|
2003-01-22 12:50:34 +00:00
|
|
|
h = (h+1) % 24;
|
2007-10-04 08:56:49 +00:00
|
|
|
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu)
|
2007-10-04 08:56:49 +00:00
|
|
|
talk_value(h, UNIT_HOUR, false);
|
2003-01-22 12:50:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* dec(h) */
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_STD_PREV:
|
2006-08-15 12:49:22 +00:00
|
|
|
case ACTION_STD_PREVREPEAT:
|
2003-01-22 12:50:34 +00:00
|
|
|
h = (h+23) % 24;
|
2007-10-04 08:56:49 +00:00
|
|
|
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu)
|
2007-10-04 08:56:49 +00:00
|
|
|
talk_value(h, UNIT_HOUR, false);
|
2003-01-22 12:50:34 +00:00
|
|
|
break;
|
2006-08-15 12:27:07 +00:00
|
|
|
|
2006-08-15 12:49:22 +00:00
|
|
|
case ACTION_STD_CANCEL:
|
2005-02-06 17:21:42 +00:00
|
|
|
rtc_enable_alarm(false);
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
|
2003-01-22 12:50:34 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
2005-07-06 08:24:24 +00:00
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_NONE:
|
2007-10-04 08:56:49 +00:00
|
|
|
hour_wrapped = false;
|
2005-07-06 08:24:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
{
|
|
|
|
rtc_enable_alarm(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2003-01-22 12:50:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|