summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-03-30 08:53:40 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2022-03-30 09:05:28 -0400
commit43830d0128ed9483db769f0d29f3d6071e620144 (patch)
tree0597df9d45dcc8bc1e2ae276c66af1226b4e54c0
parent4c1fe3a89963f4b2576e68d519d168a3d510cb75 (diff)
downloadrockbox-43830d0128.tar.gz
rockbox-43830d0128.zip
alarm_menu share setter with settime
share the time picker with the alarm block the date portion, seconds are ignored Change-Id: Idc6974466772c33248ff532c8f3c62c744ee06d9
-rw-r--r--apps/alarm_menu.c161
-rw-r--r--apps/lang/english.lang23
-rw-r--r--apps/menus/time_menu.c2
-rw-r--r--apps/screens.c11
-rw-r--r--apps/screens.h2
5 files changed, 42 insertions, 157 deletions
diff --git a/apps/alarm_menu.c b/apps/alarm_menu.c
index 62b54a84bb..67f8d1e8dd 100644
--- a/apps/alarm_menu.c
+++ b/apps/alarm_menu.c
@@ -38,161 +38,56 @@
#include "splash.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 h, m;
- bool done = false;
- struct tm *tm;
- int togo;
- int button;
- bool update = true;
- bool hour_wrapped = false;
- struct viewport vp[NB_SCREENS];
- struct viewport * last_vp;
-
- rtc_get_alarm(&h, &m);
+ bool usb, update;
+ struct tm *now = get_time();
+ struct tm atm;
+ memcpy(&atm, now, sizeof(struct tm));
+ rtc_get_alarm(&atm.tm_hour, &atm.tm_min);
/* After a battery change the RTC values are out of range */
- if (m > 60 || h > 24) {
- m = 0;
- h = 12;
- } else {
- m = m / 5 * 5; /* 5 min accuracy should be enough */
- }
- FOR_NB_SCREENS(i)
- {
- viewport_set_defaults(&vp[i], i);
- }
+ if (!valid_time(&atm))
+ memcpy(&atm, now, sizeof(struct tm));
+ atm.tm_sec = 0;
- while(!done) {
- if(update)
- {
- FOR_NB_SCREENS(i)
- {
- 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;
- }
+ 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)
- {
- 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);
+ if (!usb && update)
+ {
- switch(button) {
- case ACTION_STD_OK:
+ now = get_time();
+ int nmins = now->tm_min + (now->tm_hour * 60);
+ int amins = atm.tm_min + (atm.tm_hour * 60);
+ int mins_togo = (amins - nmins + 1440) % 1440;
/* prevent that an alarm occurs in the shutdown procedure */
/* accept alarms only if they are in 2 minutes or more */
- tm = get_time();
- togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
-
- if (togo > 1) {
+ if (mins_togo > 1) {
rtc_init();
- rtc_set_alarm(h,m);
+ rtc_set_alarm(atm.tm_hour,atm.tm_min);
rtc_enable_alarm(true);
if (global_settings.talk_menu)
{
talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
- talk_value(togo / 60, UNIT_HOUR, true);
- talk_value(togo % 60, UNIT_MIN, true);
+ talk_value(mins_togo / 60, UNIT_HOUR, true);
+ talk_value(mins_togo % 60, UNIT_MIN, true);
talk_force_enqueue_next();
}
splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
- togo / 60, togo % 60);
- done = true;
+ mins_togo / 60, mins_togo % 60);
} else {
splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
- update = true;
- }
- break;
-
- /* inc(m) */
- case ACTION_SETTINGS_INC:
- case ACTION_SETTINGS_INCREPEAT:
- m += 5;
- if (m == 60) {
- h += 1;
- m = 0;
- hour_wrapped = true;
+ update = false;
}
- 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);
+ if (usb || !update)
+ {
+ if (!usb)
splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
- done = true;
- break;
-
- case ACTION_NONE:
- hour_wrapped = false;
- break;
-
- default:
- if(default_event_handler(button) == SYS_USB_CONNECTED)
- {
- rtc_enable_alarm(false);
- return 1;
- }
- break;
- }
+ rtc_enable_alarm(false);
+ return 1;
}
return 0;
}
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index aa23647fd2..cfeb6d8edf 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -4183,31 +4183,16 @@
</phrase>
<phrase>
id: LANG_ALARM_MOD_KEYS
- desc: Shown key functions in alarm menu (for the RTC alarm mod).
+ desc: deprecated
user: core
<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>
<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>
<voice>
- *: none
- alarm,ipod*: ""
+ *: ""
</voice>
</phrase>
<phrase>
diff --git a/apps/menus/time_menu.c b/apps/menus/time_menu.c
index 674279c01a..e37e2b5637 100644
--- a/apps/menus/time_menu.c
+++ b/apps/menus/time_menu.c
@@ -73,7 +73,7 @@ static int timedate_set(void)
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) {
set_time(&tm);
diff --git a/apps/screens.c b/apps/screens.c
index f3a969a838..2d3a521a88 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -123,7 +123,7 @@ static void say_time(int cursorpos, const struct tm *tm)
#define OFF_YEAR 9
#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];
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;
}
+ int last_item = IDX_DAY; /*time & date*/
+ if (!set_date)
+ last_item = IDX_SECONDS; /*time*/
+
/* speak selection when screen is entered */
say_time(cursorpos, tm);
@@ -161,6 +165,7 @@ bool set_time_screen(const char* title, struct tm *tm)
unsigned char buffer[20];
#endif
int *valptr = NULL;
+
static unsigned char daysinmonth[] =
{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);
switch ( button ) {
case ACTION_STD_PREV:
- cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
+ cursorpos = clamp_value_wrap(--cursorpos, last_item, 0);
say_time(cursorpos, tm);
break;
case ACTION_STD_NEXT:
- cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
+ cursorpos = clamp_value_wrap(++cursorpos, last_item, 0);
say_time(cursorpos, tm);
break;
case ACTION_SETTINGS_INC:
diff --git a/apps/screens.h b/apps/screens.h
index 92b00062cb..b505dcb79b 100644
--- a/apps/screens.h
+++ b/apps/screens.h
@@ -36,7 +36,7 @@ int mmc_remove_request(void);
#endif
#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
bool shutdown_screen(void);