2003-01-22 12:50:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Uwe Freese
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "sprintf.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "settings.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "rtc.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "lang.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "alarm_menu.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_ALARM_MOD
|
|
|
|
|
|
|
|
bool alarm_screen(void)
|
|
|
|
{
|
|
|
|
/* get alarm time from RTC */
|
2003-03-03 14:23:39 +00:00
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
int h, m, hour, minute;
|
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
|
|
|
|
|
|
|
if (m > 60 || h > 24) { /* after battery-change RTC-values are out of range */
|
|
|
|
m = 0;
|
|
|
|
h = 12;
|
|
|
|
} else {
|
|
|
|
m = m / 5 * 5; /* 5 min accuracy should be enough */
|
|
|
|
}
|
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
bool done=false;
|
|
|
|
char buf[32];
|
2003-03-03 14:23:39 +00:00
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
lcd_clear_display();
|
2003-11-20 01:43:09 +00:00
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
lcd_setmargins(0, 0);
|
2003-01-22 12:50:34 +00:00
|
|
|
lcd_puts(0,1, str(LANG_ALARM_MOD_KEYS));
|
2003-03-03 14:23:39 +00:00
|
|
|
|
2003-01-22 12:50:34 +00:00
|
|
|
while(!done) {
|
|
|
|
snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m);
|
|
|
|
lcd_puts(0,0, buf);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
switch(button_get(true)) {
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
/* prevent that an alarm occurs in the shutdown procedure */
|
|
|
|
/* accept alarms only if they are in 2 minutes or more */
|
|
|
|
hour = rtc_read(0x03);
|
|
|
|
hour = ((hour & 0x30) >> 4) * 10 + (hour & 0x0f);
|
|
|
|
minute = rtc_read(0x02);
|
|
|
|
minute = ((minute & 0x70) >> 4) * 10 + (minute & 0x0f);
|
|
|
|
int togo = (m + h * 60 - minute - hour * 60 + 1440) % 1440;
|
|
|
|
if (togo > 1) {
|
|
|
|
lcd_clear_display();
|
|
|
|
snprintf(buf, 32, str(LANG_ALARM_MOD_TIME_TO_GO), togo / 60, togo % 60);
|
|
|
|
lcd_puts(0,0, buf);
|
|
|
|
lcd_update();
|
|
|
|
rtc_init();
|
|
|
|
rtc_set_alarm(h,m);
|
2005-02-06 17:21:42 +00:00
|
|
|
rtc_enable_alarm(true);
|
2003-01-22 12:50:34 +00:00
|
|
|
lcd_puts(0,1,str(LANG_ALARM_MOD_SHUTDOWN));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ);
|
2005-02-06 17:21:42 +00:00
|
|
|
done = true;
|
2003-01-22 12:50:34 +00:00
|
|
|
} else {
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,str(LANG_ALARM_MOD_ERROR));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,1,str(LANG_ALARM_MOD_KEYS));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* inc(m) */
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
|
|
|
m += 5;
|
|
|
|
if (m == 60) {
|
|
|
|
h += 1;
|
|
|
|
m = 0;
|
|
|
|
}
|
|
|
|
if (h == 24)
|
|
|
|
h = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* dec(m) */
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
m -= 5;
|
|
|
|
if (m == -5) {
|
|
|
|
h -= 1;
|
|
|
|
m = 55;
|
|
|
|
}
|
|
|
|
if (h == -1)
|
|
|
|
h = 23;
|
|
|
|
break;
|
|
|
|
|
2004-09-28 22:13:26 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2003-01-22 12:50:34 +00:00
|
|
|
/* inc(h) */
|
|
|
|
case BUTTON_UP:
|
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
|
|
|
h = (h+1) % 24;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* dec(h) */
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
|
|
|
h = (h+23) % 24;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-09-28 22:13:26 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2003-01-22 12:50:34 +00:00
|
|
|
case BUTTON_OFF:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
|
|
|
case BUTTON_MENU:
|
|
|
|
#endif
|
2005-02-06 17:21:42 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0,0,str(LANG_ALARM_MOD_DISABLE));
|
|
|
|
lcd_update();
|
|
|
|
sleep(HZ);
|
|
|
|
rtc_enable_alarm(false);
|
2003-01-22 12:50:34 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-01-23 19:54:01 +00:00
|
|
|
#endif /* HAVE_ALARM_MOD */
|