Code for alarm mod. Enable with adding -DHAVE_ALARM_MOD in Makefile (EXTRA_DEFINES).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3150 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
fa22295598
commit
86352ccc3f
7 changed files with 388 additions and 6 deletions
154
apps/alarm_menu.c
Normal file
154
apps/alarm_menu.c
Normal file
|
@ -0,0 +1,154 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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 */
|
||||
|
||||
int h, m, hour, minute;
|
||||
|
||||
rtc_get_alarm(&h, &m);
|
||||
|
||||
m = m / 5 * 5; /* 5 min accuracy should be enough */
|
||||
|
||||
bool done=false;
|
||||
char buf[32];
|
||||
|
||||
lcd_clear_display();
|
||||
lcd_puts(0,1, str(LANG_ALARM_MOD_KEYS));
|
||||
|
||||
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);
|
||||
/* in some cases enabling the alarm results in an activated AF flag */
|
||||
/* this should not happen, but it does */
|
||||
/* if you know why, tell me! */
|
||||
/* for now, we try again forever in this case */
|
||||
while (rtc_enable_alarm(true)) { /* error occured */
|
||||
sleep(HZ / 10);
|
||||
rtc_init();
|
||||
rtc_set_alarm(h,m);
|
||||
}
|
||||
sleep(HZ);
|
||||
lcd_puts(0,1,str(LANG_ALARM_MOD_SHUTDOWN));
|
||||
lcd_update();
|
||||
sleep(HZ);
|
||||
power_off();
|
||||
} 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;
|
||||
|
||||
#ifdef HAVE_RECORDER_KEYPAD
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_RECORDER_KEYPAD
|
||||
case BUTTON_OFF:
|
||||
#else
|
||||
case BUTTON_STOP:
|
||||
case BUTTON_MENU:
|
||||
#endif
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* HAVE_ALARM_MOD */
|
24
apps/alarm_menu.h
Normal file
24
apps/alarm_menu.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef _ALARM_MENU_H
|
||||
#define _ALARM_MENU_H
|
||||
|
||||
bool alarm_screen(void);
|
||||
|
||||
#endif
|
|
@ -1208,3 +1208,83 @@ id: LANG_QUEUE_TOTAL
|
|||
desc: number of queued tracks %d
|
||||
eng: "Total queued: %d"
|
||||
new: "Anzahl: %d"
|
||||
|
||||
id: LANG_ALARM_MOD_ALARM_MENU
|
||||
desc: The name of the additional entry in the main menu for the RTC alarm mod.
|
||||
eng: "Wake-Up Alarm"
|
||||
new: "Wecker"
|
||||
|
||||
id: LANG_ALARM_MOD_ERROR
|
||||
desc: The text that tells that the time is incorrect (for the RTC alarm mod).
|
||||
eng: "Alarm time is too soon!"
|
||||
new: "Weckzeit ist zu früh!"
|
||||
|
||||
id: LANG_ALARM_MOD_KEYS
|
||||
desc: Shown key functions in alarm menu (for the RTC alarm mod).
|
||||
eng: "PLAY=Set OFF=Cancel"
|
||||
new: "PLAY=OK OFF=Abbruch"
|
||||
|
||||
id: LANG_ALARM_MOD_SHUTDOWN
|
||||
desc: The text that tells the user that the alarm time is ok and the device shuts off (for the RTC alarm mod).
|
||||
eng: "Shutting down..."
|
||||
new: "Schalte aus..."
|
||||
|
||||
id: LANG_ALARM_MOD_TIME
|
||||
desc: The current alarm time shown in the alarm menu for the RTC alarm mod.
|
||||
eng: "Alarm time: %02d:%02d"
|
||||
new: "Weckzeit: %02d:%02d"
|
||||
|
||||
id: LANG_ALARM_MOD_TIME_TO_GO
|
||||
desc: The time until the alarm will go off shown in the alarm menu for the RTC alarm mod.
|
||||
eng: "Waking up in %d:%02d"
|
||||
new: "Einschalten in %d:%02d"
|
||||
|
||||
id: LANG_DELETE
|
||||
desc: The verb/action Delete
|
||||
eng: "Delete"
|
||||
new: "Löschen"
|
||||
|
||||
id: LANG_DELETED
|
||||
desc: A file has beed deleted
|
||||
eng: "Deleted"
|
||||
new: "Gelöscht"
|
||||
|
||||
id: LANG_FAILED
|
||||
desc: Something failed. To be appended after above actions
|
||||
eng: "failed"
|
||||
new: "fehlgeschlagen"
|
||||
|
||||
id: LANG_MENU_SETTING_CANCEL
|
||||
desc: Visual confirmation of canceling a changed setting
|
||||
eng: "Canceled"
|
||||
new: "Abgebrochen"
|
||||
|
||||
id: LANG_MENU_SETTING_OK
|
||||
desc: Visual confirmation of changing a setting
|
||||
eng: "OK"
|
||||
new: "OK"
|
||||
|
||||
id: LANG_PLAYER_ONPLAY_1
|
||||
desc:
|
||||
eng: "\x81 Queue"
|
||||
new: "\x81 Warteschlange"
|
||||
|
||||
id: LANG_PLAYER_ONPLAY_2
|
||||
desc:
|
||||
eng: "- Ren + Del"
|
||||
new: "- Umb + Ent"
|
||||
|
||||
id: LANG_QUEUE
|
||||
desc: The verb/action Queue
|
||||
eng: "Queue"
|
||||
new: "in Warteschlange stellen"
|
||||
|
||||
id: LANG_REALLY_DELETE
|
||||
desc: Really Delete?
|
||||
eng: "Delete?"
|
||||
new: "Löschen?"
|
||||
|
||||
id: LANG_RENAME
|
||||
desc: The verb/action Rename
|
||||
eng: "Rename"
|
||||
new: "Umbenennen"
|
||||
|
|
|
@ -1286,3 +1286,33 @@ id: LANG_FAILED
|
|||
desc: Something failed. To be appended after above actions
|
||||
eng: "failed"
|
||||
new:
|
||||
|
||||
id: LANG_ALARM_MOD_ALARM_MENU
|
||||
desc: The name of the additional entry in the main menu for the RTC alarm mod.
|
||||
eng: "Wake-Up Alarm"
|
||||
new:
|
||||
|
||||
id: LANG_ALARM_MOD_TIME
|
||||
desc: The current alarm time shown in the alarm menu for the RTC alarm mod.
|
||||
eng: "Alarm time: %02d:%02d"
|
||||
new:
|
||||
|
||||
id: LANG_ALARM_MOD_TIME_TO_GO
|
||||
desc: The time until the alarm will go off shown in the alarm menu for the RTC alarm mod.
|
||||
eng: "Waking up in %d:%02d"
|
||||
new:
|
||||
|
||||
id: LANG_ALARM_MOD_SHUTDOWN
|
||||
desc: The text that tells the user that the alarm time is ok and the device shuts off (for the RTC alarm mod).
|
||||
eng: "Shutting down..."
|
||||
new:
|
||||
|
||||
id: LANG_ALARM_MOD_ERROR
|
||||
desc: The text that tells that the time is incorrect (for the RTC alarm mod).
|
||||
eng: "Alarm time is too soon!"
|
||||
new:
|
||||
|
||||
id: LANG_ALARM_MOD_KEYS
|
||||
desc: Shown key functions in alarm menu (for the RTC alarm mod).
|
||||
eng: "PLAY=Set OFF=Cancel"
|
||||
new:
|
||||
|
|
|
@ -47,6 +47,10 @@
|
|||
#include "recording.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ALARM_MOD
|
||||
#include "alarm_menu.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
#include "bmp.h"
|
||||
#include "icons.h"
|
||||
|
@ -254,6 +258,9 @@ bool main_menu(void)
|
|||
{ str(LANG_SOUND_SETTINGS), sound_menu },
|
||||
{ str(LANG_GENERAL_SETTINGS), settings_menu },
|
||||
{ str(LANG_SLEEP_TIMER), sleeptimer_screen },
|
||||
#ifdef HAVE_ALARM_MOD
|
||||
{ str(LANG_ALARM_MOD_ALARM_MENU), alarm_screen },
|
||||
#endif
|
||||
#ifdef HAVE_MAS3587F
|
||||
{ str(LANG_RECORDING_SETTINGS), recording_menu },
|
||||
{ str(LANG_RECORDING), recording_screen },
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
||||
* Copyright (C) 2002 by Linus Nielsen Feltzing, 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.
|
||||
|
@ -20,6 +20,7 @@
|
|||
#ifdef HAVE_RTC
|
||||
#include "i2c.h"
|
||||
#include "rtc.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define RTC_ADR 0xd0
|
||||
#define RTC_DEV_WRITE (RTC_ADR | 0x00)
|
||||
|
@ -43,8 +44,85 @@ void rtc_init(void)
|
|||
data &= ~0x40;
|
||||
rtc_write(0x0c,data);
|
||||
}
|
||||
|
||||
#ifdef HAVE_ALARM_MOD
|
||||
|
||||
/* Clear Trec bit, write-protecting the RTC for 200ms when shutting off */
|
||||
/* without this, the alarm won't work! */
|
||||
|
||||
data = rtc_read(0x04);
|
||||
if (data & 0x80)
|
||||
{
|
||||
data &= ~0x80;
|
||||
rtc_write(0x04, data);
|
||||
}
|
||||
|
||||
rtc_enable_alarm(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_ALARM_MOD
|
||||
|
||||
/* set alarm time registers to the given time (repeat once per day) */
|
||||
void rtc_set_alarm(int h, int m)
|
||||
{
|
||||
unsigned char data;
|
||||
|
||||
/* for daily alarm, RPT5=RPT4=on, RPT1=RPT2=RPT3=off */
|
||||
|
||||
rtc_write(0x0e, 0x00); /* seconds 0 and RTP1 */
|
||||
rtc_write(0x0d, ((m / 10) << 4) | (m % 10)); /* minutes and RPT2 */
|
||||
rtc_write(0x0c, ((h / 10) << 4) | (h % 10)); /* hour and RPT3 */
|
||||
rtc_write(0x0b, 0xc1); /* set date 01 and RPT4 and RTP5 */
|
||||
|
||||
/* set month to 1, if it's invalid, the rtc does an alarm every second instead */
|
||||
data = rtc_read(0x0a);
|
||||
data &= 0xe0;
|
||||
data |= 0x01;
|
||||
rtc_write(0x0a, data);
|
||||
}
|
||||
|
||||
/* read out the current alarm time */
|
||||
void rtc_get_alarm(int *h, int *m)
|
||||
{
|
||||
unsigned char data;
|
||||
|
||||
data = rtc_read(0x0c);
|
||||
*h = ((data & 0x30) >> 4) * 10 + (data & 0x0f);
|
||||
|
||||
data = rtc_read(0x0d);
|
||||
*m = ((data & 0x70) >> 4) * 10 + (data & 0x0f);
|
||||
}
|
||||
|
||||
/* turn alarm on or off by setting the alarm flag enable */
|
||||
/* the alarm is automatically disabled when the RTC gets Vcc power at startup */
|
||||
/* avoid that an alarm occurs when the device is on because this locks the ON key forever */
|
||||
/* returns false if alarm was set and alarm flag (output) is off */
|
||||
/* returns true if alarm flag went on, which would lock the device, so the alarm was disabled again */
|
||||
bool rtc_enable_alarm(bool enable)
|
||||
{
|
||||
unsigned char data = rtc_read(0x0a);
|
||||
if (enable)
|
||||
{
|
||||
data |= 0xa0; /* turn bit d7=AFE and d5=ABE on */
|
||||
}
|
||||
else
|
||||
data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */
|
||||
rtc_write(0x0a, data);
|
||||
|
||||
/* check if alarm flag AF is off (as it sould be) */
|
||||
if ((rtc_read(0x0f) & 0x40) != 0) /* on */
|
||||
{
|
||||
data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */
|
||||
rtc_write(0x0a, data);
|
||||
return true;
|
||||
} else {
|
||||
return false; /* all ok */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_ALARM_MOD */
|
||||
|
||||
int rtc_write(unsigned char address, unsigned char value)
|
||||
{
|
||||
int ret = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
||||
* Copyright (C) 2002 by Linus Nielsen Feltzing, 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.
|
||||
|
@ -19,11 +19,20 @@
|
|||
#ifndef _RTC_H_
|
||||
#define _RTC_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef HAVE_RTC
|
||||
void rtc_init(void);
|
||||
int rtc_read(unsigned char address);
|
||||
int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes);
|
||||
int rtc_write(unsigned char address, unsigned char value);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ALARM_MOD
|
||||
void rtc_set_alarm(int h, int m);
|
||||
void rtc_get_alarm(int *h, int *m);
|
||||
bool rtc_enable_alarm(bool enable);
|
||||
#endif /* HAVE_ALARM_MOD */
|
||||
|
||||
#endif /* HAVE_RTC */
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue