Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2003 Uwe Freese |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #include "config.h" |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 22 | |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 23 | #include <stdbool.h> |
| 24 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 25 | #include "lcd.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 26 | #include "action.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 27 | #include "kernel.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 28 | #include <string.h> |
| 29 | #include "settings.h" |
| 30 | #include "power.h" |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 31 | #include "icons.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 32 | #include "rtc.h" |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 33 | #include "misc.h" |
| 34 | #include "screens.h" |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 35 | #include "talk.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 36 | #include "lang.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 37 | #include "alarm_menu.h" |
Kevin Ferrare | e991bee | 2005-11-16 15:12:15 +0000 | [diff] [blame] | 38 | #include "splash.h" |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 39 | #include "viewport.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 40 | |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 41 | static void speak_time(int hours, int minutes, bool speak_hours, bool enqueue) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 42 | { |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 43 | if (global_settings.talk_menu){ |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 44 | if(speak_hours) { |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 45 | talk_value(hours, UNIT_HOUR, enqueue); |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 46 | talk_value(minutes, UNIT_MIN, true); |
| 47 | } else { |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 48 | talk_value(minutes, UNIT_MIN, enqueue); |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 53 | int alarm_screen(void) |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 54 | { |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 55 | int h, m; |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 56 | bool done = false; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 57 | struct tm *tm; |
| 58 | int togo; |
| 59 | int button; |
| 60 | bool update = true; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 61 | bool hour_wrapped = false; |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 62 | struct viewport vp[NB_SCREENS]; |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 63 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 64 | rtc_get_alarm(&h, &m); |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 65 | |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 66 | /* After a battery change the RTC values are out of range */ |
| 67 | if (m > 60 || h > 24) { |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 68 | m = 0; |
| 69 | h = 12; |
| 70 | } else { |
| 71 | m = m / 5 * 5; /* 5 min accuracy should be enough */ |
| 72 | } |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 73 | FOR_NB_SCREENS(i) |
| 74 | { |
| 75 | viewport_set_defaults(&vp[i], i); |
| 76 | } |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 77 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 78 | while(!done) { |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 79 | if(update) |
| 80 | { |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 81 | FOR_NB_SCREENS(i) |
| 82 | { |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 83 | screens[i].set_viewport(&vp[i]); |
| 84 | screens[i].clear_viewport(); |
Rafaël Carré | 8302c5f | 2010-05-22 00:28:10 +0000 | [diff] [blame] | 85 | screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS)); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 86 | } |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 87 | /* Talk when entering the wakeup screen */ |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 88 | speak_time(h, m, true, true); |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 89 | update = false; |
| 90 | } |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 91 | |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 92 | FOR_NB_SCREENS(i) |
| 93 | { |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 94 | screens[i].set_viewport(&vp[i]); |
Rafaël Carré | 8302c5f | 2010-05-22 00:28:10 +0000 | [diff] [blame] | 95 | screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME)); |
| 96 | screens[i].putsf(0, 2, "%02d:%02d", h, m); |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 97 | screens[i].update_viewport(); |
| 98 | screens[i].set_viewport(NULL); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 99 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 100 | button = get_action(CONTEXT_SETTINGS,HZ); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 101 | |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 102 | switch(button) { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 103 | case ACTION_STD_OK: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 104 | /* prevent that an alarm occurs in the shutdown procedure */ |
| 105 | /* accept alarms only if they are in 2 minutes or more */ |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 106 | tm = get_time(); |
| 107 | togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 108 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 109 | if (togo > 1) { |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 110 | rtc_init(); |
| 111 | rtc_set_alarm(h,m); |
Christi Scarborough | a83ffb2 | 2005-02-06 17:21:42 +0000 | [diff] [blame] | 112 | rtc_enable_alarm(true); |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 113 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 114 | { |
| 115 | talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); |
| 116 | talk_value(togo / 60, UNIT_HOUR, true); |
| 117 | talk_value(togo % 60, UNIT_MIN, true); |
| 118 | talk_force_enqueue_next(); |
| 119 | } |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 120 | splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO), |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 121 | togo / 60, togo % 60); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 122 | done = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 123 | } else { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 124 | splash(HZ, ID2P(LANG_ALARM_MOD_ERROR)); |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 125 | update = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 126 | } |
| 127 | break; |
| 128 | |
| 129 | /* inc(m) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 130 | case ACTION_SETTINGS_INC: |
| 131 | case ACTION_SETTINGS_INCREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 132 | m += 5; |
| 133 | if (m == 60) { |
| 134 | h += 1; |
| 135 | m = 0; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 136 | hour_wrapped = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 137 | } |
| 138 | if (h == 24) |
| 139 | h = 0; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 140 | |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 141 | speak_time(h, m, hour_wrapped, false); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 142 | break; |
| 143 | |
| 144 | /* dec(m) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 145 | case ACTION_SETTINGS_DEC: |
| 146 | case ACTION_SETTINGS_DECREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 147 | m -= 5; |
| 148 | if (m == -5) { |
| 149 | h -= 1; |
| 150 | m = 55; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 151 | hour_wrapped = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 152 | } |
| 153 | if (h == -1) |
| 154 | h = 23; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 155 | |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 156 | speak_time(h, m, hour_wrapped, false); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 157 | break; |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 158 | |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 159 | /* inc(h) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 160 | case ACTION_STD_NEXT: |
| 161 | case ACTION_STD_NEXTREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 162 | h = (h+1) % 24; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 163 | |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 164 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 165 | talk_value(h, UNIT_HOUR, false); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 166 | break; |
| 167 | |
| 168 | /* dec(h) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 169 | case ACTION_STD_PREV: |
Linus Nielsen Feltzing | d723e6e | 2006-08-15 12:49:22 +0000 | [diff] [blame] | 170 | case ACTION_STD_PREVREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 171 | h = (h+23) % 24; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 172 | |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 173 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 174 | talk_value(h, UNIT_HOUR, false); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 175 | break; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 176 | |
Linus Nielsen Feltzing | d723e6e | 2006-08-15 12:49:22 +0000 | [diff] [blame] | 177 | case ACTION_STD_CANCEL: |
Christi Scarborough | a83ffb2 | 2005-02-06 17:21:42 +0000 | [diff] [blame] | 178 | rtc_enable_alarm(false); |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 179 | splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE)); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 180 | done = true; |
| 181 | break; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 182 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 183 | case ACTION_NONE: |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 184 | hour_wrapped = false; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 185 | break; |
| 186 | |
| 187 | default: |
| 188 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 189 | { |
| 190 | rtc_enable_alarm(false); |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 191 | return 1; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 192 | } |
| 193 | break; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 196 | return 0; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 197 | } |