diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-03-30 08:53:40 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-03-30 09:05:28 -0400 |
commit | 43830d0128ed9483db769f0d29f3d6071e620144 (patch) | |
tree | 0597df9d45dcc8bc1e2ae276c66af1226b4e54c0 | |
parent | 4c1fe3a89963f4b2576e68d519d168a3d510cb75 (diff) | |
download | rockbox-43830d0128ed9483db769f0d29f3d6071e620144.tar.gz rockbox-43830d0128ed9483db769f0d29f3d6071e620144.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.c | 161 | ||||
-rw-r--r-- | apps/lang/english.lang | 23 | ||||
-rw-r--r-- | apps/menus/time_menu.c | 2 | ||||
-rw-r--r-- | apps/screens.c | 11 | ||||
-rw-r--r-- | apps/screens.h | 2 |
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 @@ | |||
38 | #include "splash.h" | 38 | #include "splash.h" |
39 | #include "viewport.h" | 39 | #include "viewport.h" |
40 | 40 | ||
41 | static void speak_time(int hours, int minutes, bool speak_hours, bool enqueue) | ||
42 | { | ||
43 | if (global_settings.talk_menu){ | ||
44 | if(speak_hours) { | ||
45 | talk_value(hours, UNIT_HOUR, enqueue); | ||
46 | talk_value(minutes, UNIT_MIN, true); | ||
47 | } else { | ||
48 | talk_value(minutes, UNIT_MIN, enqueue); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | int alarm_screen(void) | 41 | int alarm_screen(void) |
54 | { | 42 | { |
55 | int h, m; | 43 | bool usb, update; |
56 | bool done = false; | 44 | struct tm *now = get_time(); |
57 | struct tm *tm; | 45 | struct tm atm; |
58 | int togo; | 46 | memcpy(&atm, now, sizeof(struct tm)); |
59 | int button; | 47 | rtc_get_alarm(&atm.tm_hour, &atm.tm_min); |
60 | bool update = true; | ||
61 | bool hour_wrapped = false; | ||
62 | struct viewport vp[NB_SCREENS]; | ||
63 | struct viewport * last_vp; | ||
64 | |||
65 | rtc_get_alarm(&h, &m); | ||
66 | 48 | ||
67 | /* After a battery change the RTC values are out of range */ | 49 | /* After a battery change the RTC values are out of range */ |
68 | if (m > 60 || h > 24) { | 50 | if (!valid_time(&atm)) |
69 | m = 0; | 51 | memcpy(&atm, now, sizeof(struct tm)); |
70 | h = 12; | 52 | atm.tm_sec = 0; |
71 | } else { | ||
72 | m = m / 5 * 5; /* 5 min accuracy should be enough */ | ||
73 | } | ||
74 | FOR_NB_SCREENS(i) | ||
75 | { | ||
76 | viewport_set_defaults(&vp[i], i); | ||
77 | } | ||
78 | 53 | ||
79 | while(!done) { | 54 | usb = set_time_screen(str(LANG_ALARM_MOD_TIME), &atm, false); |
80 | if(update) | 55 | update = valid_time(&atm); /* set_time returns invalid time if canceled */ |
81 | { | ||
82 | FOR_NB_SCREENS(i) | ||
83 | { | ||
84 | screens[i].set_viewport(&vp[i]); | ||
85 | screens[i].clear_viewport(); | ||
86 | screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS)); | ||
87 | } | ||
88 | /* Talk when entering the wakeup screen */ | ||
89 | speak_time(h, m, true, true); | ||
90 | update = false; | ||
91 | } | ||
92 | 56 | ||
93 | FOR_NB_SCREENS(i) | 57 | if (!usb && update) |
94 | { | 58 | { |
95 | last_vp = screens[i].set_viewport(&vp[i]); | ||
96 | screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME)); | ||
97 | screens[i].putsf(0, 2, "%02d:%02d", h, m); | ||
98 | screens[i].update_viewport(); | ||
99 | screens[i].set_viewport(last_vp); | ||
100 | } | ||
101 | button = get_action(CONTEXT_SETTINGS,HZ); | ||
102 | 59 | ||
103 | switch(button) { | 60 | now = get_time(); |
104 | case ACTION_STD_OK: | 61 | int nmins = now->tm_min + (now->tm_hour * 60); |
62 | int amins = atm.tm_min + (atm.tm_hour * 60); | ||
63 | int mins_togo = (amins - nmins + 1440) % 1440; | ||
105 | /* prevent that an alarm occurs in the shutdown procedure */ | 64 | /* prevent that an alarm occurs in the shutdown procedure */ |
106 | /* accept alarms only if they are in 2 minutes or more */ | 65 | /* accept alarms only if they are in 2 minutes or more */ |
107 | tm = get_time(); | 66 | if (mins_togo > 1) { |
108 | togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440; | ||
109 | |||
110 | if (togo > 1) { | ||
111 | rtc_init(); | 67 | rtc_init(); |
112 | rtc_set_alarm(h,m); | 68 | rtc_set_alarm(atm.tm_hour,atm.tm_min); |
113 | rtc_enable_alarm(true); | 69 | rtc_enable_alarm(true); |
114 | if (global_settings.talk_menu) | 70 | if (global_settings.talk_menu) |
115 | { | 71 | { |
116 | talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); | 72 | talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); |
117 | talk_value(togo / 60, UNIT_HOUR, true); | 73 | talk_value(mins_togo / 60, UNIT_HOUR, true); |
118 | talk_value(togo % 60, UNIT_MIN, true); | 74 | talk_value(mins_togo % 60, UNIT_MIN, true); |
119 | talk_force_enqueue_next(); | 75 | talk_force_enqueue_next(); |
120 | } | 76 | } |
121 | splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO), | 77 | splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO), |
122 | togo / 60, togo % 60); | 78 | mins_togo / 60, mins_togo % 60); |
123 | done = true; | ||
124 | } else { | 79 | } else { |
125 | splash(HZ, ID2P(LANG_ALARM_MOD_ERROR)); | 80 | splash(HZ, ID2P(LANG_ALARM_MOD_ERROR)); |
126 | update = true; | 81 | update = false; |
127 | } | ||
128 | break; | ||
129 | |||
130 | /* inc(m) */ | ||
131 | case ACTION_SETTINGS_INC: | ||
132 | case ACTION_SETTINGS_INCREPEAT: | ||
133 | m += 5; | ||
134 | if (m == 60) { | ||
135 | h += 1; | ||
136 | m = 0; | ||
137 | hour_wrapped = true; | ||
138 | } | 82 | } |
139 | if (h == 24) | 83 | } |
140 | h = 0; | ||
141 | |||
142 | speak_time(h, m, hour_wrapped, false); | ||
143 | break; | ||
144 | |||
145 | /* dec(m) */ | ||
146 | case ACTION_SETTINGS_DEC: | ||
147 | case ACTION_SETTINGS_DECREPEAT: | ||
148 | m -= 5; | ||
149 | if (m == -5) { | ||
150 | h -= 1; | ||
151 | m = 55; | ||
152 | hour_wrapped = true; | ||
153 | } | ||
154 | if (h == -1) | ||
155 | h = 23; | ||
156 | |||
157 | speak_time(h, m, hour_wrapped, false); | ||
158 | break; | ||
159 | |||
160 | /* inc(h) */ | ||
161 | case ACTION_STD_NEXT: | ||
162 | case ACTION_STD_NEXTREPEAT: | ||
163 | h = (h+1) % 24; | ||
164 | |||
165 | if (global_settings.talk_menu) | ||
166 | talk_value(h, UNIT_HOUR, false); | ||
167 | break; | ||
168 | |||
169 | /* dec(h) */ | ||
170 | case ACTION_STD_PREV: | ||
171 | case ACTION_STD_PREVREPEAT: | ||
172 | h = (h+23) % 24; | ||
173 | |||
174 | if (global_settings.talk_menu) | ||
175 | talk_value(h, UNIT_HOUR, false); | ||
176 | break; | ||
177 | 84 | ||
178 | case ACTION_STD_CANCEL: | 85 | if (usb || !update) |
179 | rtc_enable_alarm(false); | 86 | { |
87 | if (!usb) | ||
180 | splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE)); | 88 | splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE)); |
181 | done = true; | 89 | rtc_enable_alarm(false); |
182 | break; | 90 | return 1; |
183 | |||
184 | case ACTION_NONE: | ||
185 | hour_wrapped = false; | ||
186 | break; | ||
187 | |||
188 | default: | ||
189 | if(default_event_handler(button) == SYS_USB_CONNECTED) | ||
190 | { | ||
191 | rtc_enable_alarm(false); | ||
192 | return 1; | ||
193 | } | ||
194 | break; | ||
195 | } | ||
196 | } | 91 | } |
197 | return 0; | 92 | return 0; |
198 | } | 93 | } |
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 @@ | |||
4183 | </phrase> | 4183 | </phrase> |
4184 | <phrase> | 4184 | <phrase> |
4185 | id: LANG_ALARM_MOD_KEYS | 4185 | id: LANG_ALARM_MOD_KEYS |
4186 | desc: Shown key functions in alarm menu (for the RTC alarm mod). | 4186 | desc: deprecated |
4187 | user: core | 4187 | user: core |
4188 | <source> | 4188 | <source> |
4189 | *: none | 4189 | *: "" |
4190 | alarm: "PLAY=Set OFF=Cancel" | ||
4191 | gigabeats: "SELECT=Set POWER=Cancel" | ||
4192 | ipod*: "SELECT=Set MENU=Cancel" | ||
4193 | iriverh10,iriverh10_5gb: "SELECT=Set PREV=Cancel" | ||
4194 | mpiohd300: "ENTER=Set MENU=Cancel" | ||
4195 | sansafuzeplus: "SELECT=Set BACK=Cancel" | ||
4196 | vibe500: "OK=Set C=Cancel" | ||
4197 | </source> | 4190 | </source> |
4198 | <dest> | 4191 | <dest> |
4199 | *: none | 4192 | *: "" |
4200 | alarm: "PLAY=Set OFF=Cancel" | ||
4201 | gigabeats: "SELECT=Set POWER=Cancel" | ||
4202 | ipod*: "SELECT=Set MENU=Cancel" | ||
4203 | iriverh10,iriverh10_5gb: "SELECT=Set PREV=Cancel" | ||
4204 | mpiohd300: "ENTER=Set MENU=Cancel" | ||
4205 | sansafuzeplus: "SELECT=Set BACK=Cancel" | ||
4206 | vibe500: "OK=Set C=Cancel" | ||
4207 | </dest> | 4193 | </dest> |
4208 | <voice> | 4194 | <voice> |
4209 | *: none | 4195 | *: "" |
4210 | alarm,ipod*: "" | ||
4211 | </voice> | 4196 | </voice> |
4212 | </phrase> | 4197 | </phrase> |
4213 | <phrase> | 4198 | <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) | |||
73 | tm.tm_year = YEAR-1900; | 73 | tm.tm_year = YEAR-1900; |
74 | } | 74 | } |
75 | 75 | ||
76 | result = (int)set_time_screen(str(LANG_SET_TIME), &tm); | 76 | result = (int)set_time_screen(str(LANG_SET_TIME), &tm, true); |
77 | 77 | ||
78 | if(tm.tm_year != -1) { | 78 | if(tm.tm_year != -1) { |
79 | set_time(&tm); | 79 | 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) | |||
123 | #define OFF_YEAR 9 | 123 | #define OFF_YEAR 9 |
124 | #define OFF_DAY 14 | 124 | #define OFF_DAY 14 |
125 | 125 | ||
126 | bool set_time_screen(const char* title, struct tm *tm) | 126 | bool set_time_screen(const char* title, struct tm *tm, bool set_date) |
127 | { | 127 | { |
128 | struct viewport viewports[NB_SCREENS]; | 128 | struct viewport viewports[NB_SCREENS]; |
129 | bool done = false, usb = false; | 129 | bool done = false, usb = false; |
@@ -139,6 +139,10 @@ bool set_time_screen(const char* title, struct tm *tm) | |||
139 | offsets_ptr[IDX_DAY] = OFF_YEAR; | 139 | offsets_ptr[IDX_DAY] = OFF_YEAR; |
140 | } | 140 | } |
141 | 141 | ||
142 | int last_item = IDX_DAY; /*time & date*/ | ||
143 | if (!set_date) | ||
144 | last_item = IDX_SECONDS; /*time*/ | ||
145 | |||
142 | /* speak selection when screen is entered */ | 146 | /* speak selection when screen is entered */ |
143 | say_time(cursorpos, tm); | 147 | say_time(cursorpos, tm); |
144 | 148 | ||
@@ -161,6 +165,7 @@ bool set_time_screen(const char* title, struct tm *tm) | |||
161 | unsigned char buffer[20]; | 165 | unsigned char buffer[20]; |
162 | #endif | 166 | #endif |
163 | int *valptr = NULL; | 167 | int *valptr = NULL; |
168 | |||
164 | static unsigned char daysinmonth[] = | 169 | static unsigned char daysinmonth[] = |
165 | {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 170 | {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
166 | 171 | ||
@@ -320,11 +325,11 @@ bool set_time_screen(const char* title, struct tm *tm) | |||
320 | button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK); | 325 | button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK); |
321 | switch ( button ) { | 326 | switch ( button ) { |
322 | case ACTION_STD_PREV: | 327 | case ACTION_STD_PREV: |
323 | cursorpos = clamp_value_wrap(--cursorpos, 5, 0); | 328 | cursorpos = clamp_value_wrap(--cursorpos, last_item, 0); |
324 | say_time(cursorpos, tm); | 329 | say_time(cursorpos, tm); |
325 | break; | 330 | break; |
326 | case ACTION_STD_NEXT: | 331 | case ACTION_STD_NEXT: |
327 | cursorpos = clamp_value_wrap(++cursorpos, 5, 0); | 332 | cursorpos = clamp_value_wrap(++cursorpos, last_item, 0); |
328 | say_time(cursorpos, tm); | 333 | say_time(cursorpos, tm); |
329 | break; | 334 | break; |
330 | case ACTION_SETTINGS_INC: | 335 | 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); | |||
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #if CONFIG_RTC | 38 | #if CONFIG_RTC |
39 | bool set_time_screen(const char* title, struct tm *tm); | 39 | bool set_time_screen(const char* title, struct tm *tm, bool set_date); |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | bool shutdown_screen(void); | 42 | bool shutdown_screen(void); |