forked from len0rd/rockbox
alarm_menu share setter with settime
share the time picker with the alarm block the date portion, seconds are ignored Change-Id: Idc6974466772c33248ff532c8f3c62c744ee06d9
This commit is contained in:
parent
4c1fe3a899
commit
43830d0128
5 changed files with 43 additions and 158 deletions
|
|
@ -38,161 +38,56 @@
|
||||||
#include "splash.h"
|
#include "splash.h"
|
||||||
#include "viewport.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int alarm_screen(void)
|
int alarm_screen(void)
|
||||||
{
|
{
|
||||||
int h, m;
|
bool usb, update;
|
||||||
bool done = false;
|
struct tm *now = get_time();
|
||||||
struct tm *tm;
|
struct tm atm;
|
||||||
int togo;
|
memcpy(&atm, now, sizeof(struct tm));
|
||||||
int button;
|
rtc_get_alarm(&atm.tm_hour, &atm.tm_min);
|
||||||
bool update = true;
|
|
||||||
bool hour_wrapped = false;
|
|
||||||
struct viewport vp[NB_SCREENS];
|
|
||||||
struct viewport * last_vp;
|
|
||||||
|
|
||||||
rtc_get_alarm(&h, &m);
|
|
||||||
|
|
||||||
/* After a battery change the RTC values are out of range */
|
/* After a battery change the RTC values are out of range */
|
||||||
if (m > 60 || h > 24) {
|
if (!valid_time(&atm))
|
||||||
m = 0;
|
memcpy(&atm, now, sizeof(struct tm));
|
||||||
h = 12;
|
atm.tm_sec = 0;
|
||||||
} else {
|
|
||||||
m = m / 5 * 5; /* 5 min accuracy should be enough */
|
usb = set_time_screen(str(LANG_ALARM_MOD_TIME), &atm, false);
|
||||||
}
|
update = valid_time(&atm); /* set_time returns invalid time if canceled */
|
||||||
FOR_NB_SCREENS(i)
|
|
||||||
|
if (!usb && update)
|
||||||
{
|
{
|
||||||
viewport_set_defaults(&vp[i], i);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(!done) {
|
now = get_time();
|
||||||
if(update)
|
int nmins = now->tm_min + (now->tm_hour * 60);
|
||||||
{
|
int amins = atm.tm_min + (atm.tm_hour * 60);
|
||||||
FOR_NB_SCREENS(i)
|
int mins_togo = (amins - nmins + 1440) % 1440;
|
||||||
{
|
|
||||||
screens[i].set_viewport(&vp[i]);
|
|
||||||
screens[i].clear_viewport();
|
|
||||||
screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS));
|
|
||||||
}
|
|
||||||
/* Talk when entering the wakeup screen */
|
|
||||||
speak_time(h, m, true, true);
|
|
||||||
update = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
FOR_NB_SCREENS(i)
|
|
||||||
{
|
|
||||||
last_vp = screens[i].set_viewport(&vp[i]);
|
|
||||||
screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME));
|
|
||||||
screens[i].putsf(0, 2, "%02d:%02d", h, m);
|
|
||||||
screens[i].update_viewport();
|
|
||||||
screens[i].set_viewport(last_vp);
|
|
||||||
}
|
|
||||||
button = get_action(CONTEXT_SETTINGS,HZ);
|
|
||||||
|
|
||||||
switch(button) {
|
|
||||||
case ACTION_STD_OK:
|
|
||||||
/* prevent that an alarm occurs in the shutdown procedure */
|
/* prevent that an alarm occurs in the shutdown procedure */
|
||||||
/* accept alarms only if they are in 2 minutes or more */
|
/* accept alarms only if they are in 2 minutes or more */
|
||||||
tm = get_time();
|
if (mins_togo > 1) {
|
||||||
togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
|
|
||||||
|
|
||||||
if (togo > 1) {
|
|
||||||
rtc_init();
|
rtc_init();
|
||||||
rtc_set_alarm(h,m);
|
rtc_set_alarm(atm.tm_hour,atm.tm_min);
|
||||||
rtc_enable_alarm(true);
|
rtc_enable_alarm(true);
|
||||||
if (global_settings.talk_menu)
|
if (global_settings.talk_menu)
|
||||||
{
|
{
|
||||||
talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
|
talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
|
||||||
talk_value(togo / 60, UNIT_HOUR, true);
|
talk_value(mins_togo / 60, UNIT_HOUR, true);
|
||||||
talk_value(togo % 60, UNIT_MIN, true);
|
talk_value(mins_togo % 60, UNIT_MIN, true);
|
||||||
talk_force_enqueue_next();
|
talk_force_enqueue_next();
|
||||||
}
|
}
|
||||||
splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
|
splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
|
||||||
togo / 60, togo % 60);
|
mins_togo / 60, mins_togo % 60);
|
||||||
done = true;
|
|
||||||
} else {
|
} else {
|
||||||
splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
|
splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
|
||||||
update = true;
|
update = false;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
/* inc(m) */
|
if (usb || !update)
|
||||||
case ACTION_SETTINGS_INC:
|
{
|
||||||
case ACTION_SETTINGS_INCREPEAT:
|
if (!usb)
|
||||||
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));
|
splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
|
||||||
done = true;
|
rtc_enable_alarm(false);
|
||||||
break;
|
return 1;
|
||||||
|
|
||||||
case ACTION_NONE:
|
|
||||||
hour_wrapped = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if(default_event_handler(button) == SYS_USB_CONNECTED)
|
|
||||||
{
|
|
||||||
rtc_enable_alarm(false);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4183,31 +4183,16 @@
|
||||||
</phrase>
|
</phrase>
|
||||||
<phrase>
|
<phrase>
|
||||||
id: LANG_ALARM_MOD_KEYS
|
id: LANG_ALARM_MOD_KEYS
|
||||||
desc: Shown key functions in alarm menu (for the RTC alarm mod).
|
desc: deprecated
|
||||||
user: core
|
user: core
|
||||||
<source>
|
<source>
|
||||||
*: none
|
*: ""
|
||||||
alarm: "PLAY=Set OFF=Cancel"
|
|
||||||
gigabeats: "SELECT=Set POWER=Cancel"
|
|
||||||
ipod*: "SELECT=Set MENU=Cancel"
|
|
||||||
iriverh10,iriverh10_5gb: "SELECT=Set PREV=Cancel"
|
|
||||||
mpiohd300: "ENTER=Set MENU=Cancel"
|
|
||||||
sansafuzeplus: "SELECT=Set BACK=Cancel"
|
|
||||||
vibe500: "OK=Set C=Cancel"
|
|
||||||
</source>
|
</source>
|
||||||
<dest>
|
<dest>
|
||||||
*: none
|
*: ""
|
||||||
alarm: "PLAY=Set OFF=Cancel"
|
|
||||||
gigabeats: "SELECT=Set POWER=Cancel"
|
|
||||||
ipod*: "SELECT=Set MENU=Cancel"
|
|
||||||
iriverh10,iriverh10_5gb: "SELECT=Set PREV=Cancel"
|
|
||||||
mpiohd300: "ENTER=Set MENU=Cancel"
|
|
||||||
sansafuzeplus: "SELECT=Set BACK=Cancel"
|
|
||||||
vibe500: "OK=Set C=Cancel"
|
|
||||||
</dest>
|
</dest>
|
||||||
<voice>
|
<voice>
|
||||||
*: none
|
*: ""
|
||||||
alarm,ipod*: ""
|
|
||||||
</voice>
|
</voice>
|
||||||
</phrase>
|
</phrase>
|
||||||
<phrase>
|
<phrase>
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ static int timedate_set(void)
|
||||||
tm.tm_year = YEAR-1900;
|
tm.tm_year = YEAR-1900;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = (int)set_time_screen(str(LANG_SET_TIME), &tm);
|
result = (int)set_time_screen(str(LANG_SET_TIME), &tm, true);
|
||||||
|
|
||||||
if(tm.tm_year != -1) {
|
if(tm.tm_year != -1) {
|
||||||
set_time(&tm);
|
set_time(&tm);
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ static void say_time(int cursorpos, const struct tm *tm)
|
||||||
#define OFF_YEAR 9
|
#define OFF_YEAR 9
|
||||||
#define OFF_DAY 14
|
#define OFF_DAY 14
|
||||||
|
|
||||||
bool set_time_screen(const char* title, struct tm *tm)
|
bool set_time_screen(const char* title, struct tm *tm, bool set_date)
|
||||||
{
|
{
|
||||||
struct viewport viewports[NB_SCREENS];
|
struct viewport viewports[NB_SCREENS];
|
||||||
bool done = false, usb = false;
|
bool done = false, usb = false;
|
||||||
|
|
@ -139,6 +139,10 @@ bool set_time_screen(const char* title, struct tm *tm)
|
||||||
offsets_ptr[IDX_DAY] = OFF_YEAR;
|
offsets_ptr[IDX_DAY] = OFF_YEAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int last_item = IDX_DAY; /*time & date*/
|
||||||
|
if (!set_date)
|
||||||
|
last_item = IDX_SECONDS; /*time*/
|
||||||
|
|
||||||
/* speak selection when screen is entered */
|
/* speak selection when screen is entered */
|
||||||
say_time(cursorpos, tm);
|
say_time(cursorpos, tm);
|
||||||
|
|
||||||
|
|
@ -161,6 +165,7 @@ bool set_time_screen(const char* title, struct tm *tm)
|
||||||
unsigned char buffer[20];
|
unsigned char buffer[20];
|
||||||
#endif
|
#endif
|
||||||
int *valptr = NULL;
|
int *valptr = NULL;
|
||||||
|
|
||||||
static unsigned char daysinmonth[] =
|
static unsigned char daysinmonth[] =
|
||||||
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
|
||||||
|
|
@ -320,11 +325,11 @@ bool set_time_screen(const char* title, struct tm *tm)
|
||||||
button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
|
button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
|
||||||
switch ( button ) {
|
switch ( button ) {
|
||||||
case ACTION_STD_PREV:
|
case ACTION_STD_PREV:
|
||||||
cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
|
cursorpos = clamp_value_wrap(--cursorpos, last_item, 0);
|
||||||
say_time(cursorpos, tm);
|
say_time(cursorpos, tm);
|
||||||
break;
|
break;
|
||||||
case ACTION_STD_NEXT:
|
case ACTION_STD_NEXT:
|
||||||
cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
|
cursorpos = clamp_value_wrap(++cursorpos, last_item, 0);
|
||||||
say_time(cursorpos, tm);
|
say_time(cursorpos, tm);
|
||||||
break;
|
break;
|
||||||
case ACTION_SETTINGS_INC:
|
case ACTION_SETTINGS_INC:
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ int mmc_remove_request(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_RTC
|
#if CONFIG_RTC
|
||||||
bool set_time_screen(const char* title, struct tm *tm);
|
bool set_time_screen(const char* title, struct tm *tm, bool set_date);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool shutdown_screen(void);
|
bool shutdown_screen(void);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue