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 | |
Thom Johansen | 8fd6d65 | 2007-02-28 21:55:11 +0000 | [diff] [blame] | 23 | #ifdef HAVE_RTC_ALARM |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 24 | |
| 25 | #include <stdbool.h> |
| 26 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 27 | #include "lcd.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 28 | #include "action.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 29 | #include "kernel.h" |
| 30 | #include "sprintf.h" |
| 31 | #include <string.h> |
| 32 | #include "settings.h" |
| 33 | #include "power.h" |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 34 | #include "icons.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 35 | #include "rtc.h" |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 36 | #include "misc.h" |
| 37 | #include "screens.h" |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 38 | #include "talk.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 39 | #include "lang.h" |
| 40 | #include "power.h" |
| 41 | #include "alarm_menu.h" |
| 42 | #include "backlight.h" |
Kevin Ferrare | e991bee | 2005-11-16 15:12:15 +0000 | [diff] [blame] | 43 | #include "splash.h" |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 44 | #include "statusbar.h" |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 45 | #include "viewport.h" |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 46 | |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 47 | static void speak_time(int hours, int minutes, bool speak_hours) |
| 48 | { |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 49 | if (global_settings.talk_menu){ |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 50 | if(speak_hours) { |
| 51 | talk_value(hours, UNIT_HOUR, false); |
| 52 | talk_value(minutes, UNIT_MIN, true); |
| 53 | } else { |
| 54 | talk_value(minutes, UNIT_MIN, false); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 59 | bool alarm_screen(void) |
| 60 | { |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 61 | int h, m; |
| 62 | bool done=false; |
| 63 | char buf[32]; |
| 64 | struct tm *tm; |
| 65 | int togo; |
| 66 | int button; |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 67 | int i; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 68 | bool update = true; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 69 | bool hour_wrapped = false; |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 70 | struct viewport vp[NB_SCREENS]; |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 71 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 72 | rtc_get_alarm(&h, &m); |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 73 | |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 74 | /* After a battery change the RTC values are out of range */ |
| 75 | if (m > 60 || h > 24) { |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 76 | m = 0; |
| 77 | h = 12; |
| 78 | } else { |
| 79 | m = m / 5 * 5; /* 5 min accuracy should be enough */ |
| 80 | } |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 81 | FOR_NB_SCREENS(i) |
| 82 | { |
| 83 | viewport_set_defaults(&vp[i], i); |
| 84 | } |
Uwe Freese | 5bfa9b7 | 2003-03-03 14:23:39 +0000 | [diff] [blame] | 85 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 86 | while(!done) { |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 87 | if(update) |
| 88 | { |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 89 | FOR_NB_SCREENS(i) |
| 90 | { |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 91 | screens[i].set_viewport(&vp[i]); |
| 92 | screens[i].clear_viewport(); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 93 | screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS)); |
| 94 | } |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 95 | /* Talk when entering the wakeup screen */ |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 96 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 97 | { |
| 98 | talk_value(h, UNIT_HOUR, true); |
| 99 | talk_value(m, UNIT_MIN, true); |
| 100 | } |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 101 | update = false; |
| 102 | } |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 103 | |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 104 | snprintf(buf, 32, str(LANG_ALARM_MOD_TIME), h, m); |
| 105 | FOR_NB_SCREENS(i) |
| 106 | { |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 107 | screens[i].set_viewport(&vp[i]); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 108 | screens[i].puts(0, 1, buf); |
Jonathan Gordon | d0ed371 | 2008-05-29 08:20:07 +0000 | [diff] [blame] | 109 | screens[i].update_viewport(); |
| 110 | screens[i].set_viewport(NULL); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 111 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 112 | button = get_action(CONTEXT_SETTINGS,HZ); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 113 | |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 114 | switch(button) { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 115 | case ACTION_STD_OK: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 116 | /* prevent that an alarm occurs in the shutdown procedure */ |
| 117 | /* accept alarms only if they are in 2 minutes or more */ |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 118 | tm = get_time(); |
| 119 | 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] | 120 | |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 121 | if (togo > 1) { |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 122 | rtc_init(); |
| 123 | rtc_set_alarm(h,m); |
Christi Scarborough | a83ffb2 | 2005-02-06 17:21:42 +0000 | [diff] [blame] | 124 | rtc_enable_alarm(true); |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 125 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 126 | { |
| 127 | talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); |
| 128 | talk_value(togo / 60, UNIT_HOUR, true); |
| 129 | talk_value(togo % 60, UNIT_MIN, true); |
| 130 | talk_force_enqueue_next(); |
| 131 | } |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 132 | gui_syncsplash(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO), |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 133 | togo / 60, togo % 60); |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 134 | done = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 135 | } else { |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 136 | gui_syncsplash(HZ, ID2P(LANG_ALARM_MOD_ERROR)); |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 137 | update = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 138 | } |
| 139 | break; |
| 140 | |
| 141 | /* inc(m) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 142 | case ACTION_SETTINGS_INC: |
| 143 | case ACTION_SETTINGS_INCREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 144 | m += 5; |
| 145 | if (m == 60) { |
| 146 | h += 1; |
| 147 | m = 0; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 148 | hour_wrapped = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 149 | } |
| 150 | if (h == 24) |
| 151 | h = 0; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 152 | |
| 153 | speak_time(h, m, hour_wrapped); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 154 | break; |
| 155 | |
| 156 | /* dec(m) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 157 | case ACTION_SETTINGS_DEC: |
| 158 | case ACTION_SETTINGS_DECREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 159 | m -= 5; |
| 160 | if (m == -5) { |
| 161 | h -= 1; |
| 162 | m = 55; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 163 | hour_wrapped = true; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 164 | } |
| 165 | if (h == -1) |
| 166 | h = 23; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 167 | |
| 168 | speak_time(h, m, hour_wrapped); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 169 | break; |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 170 | |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 171 | /* inc(h) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 172 | case ACTION_STD_NEXT: |
| 173 | case ACTION_STD_NEXTREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 174 | h = (h+1) % 24; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 175 | |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 176 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 177 | talk_value(h, UNIT_HOUR, false); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 178 | break; |
| 179 | |
| 180 | /* dec(h) */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 181 | case ACTION_STD_PREV: |
Linus Nielsen Feltzing | d723e6e | 2006-08-15 12:49:22 +0000 | [diff] [blame] | 182 | case ACTION_STD_PREVREPEAT: |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 183 | h = (h+23) % 24; |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 184 | |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 185 | if (global_settings.talk_menu) |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 186 | talk_value(h, UNIT_HOUR, false); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 187 | break; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 188 | |
Linus Nielsen Feltzing | d723e6e | 2006-08-15 12:49:22 +0000 | [diff] [blame] | 189 | case ACTION_STD_CANCEL: |
Christi Scarborough | a83ffb2 | 2005-02-06 17:21:42 +0000 | [diff] [blame] | 190 | rtc_enable_alarm(false); |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 191 | gui_syncsplash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE)); |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 192 | done = true; |
| 193 | break; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 194 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 195 | case ACTION_NONE: |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 196 | gui_syncstatusbar_draw(&statusbars, false); |
Linus Nielsen Feltzing | b0a3736 | 2007-10-04 08:56:49 +0000 | [diff] [blame] | 197 | hour_wrapped = false; |
Linus Nielsen Feltzing | 50d9e3f | 2005-07-06 08:24:24 +0000 | [diff] [blame] | 198 | break; |
| 199 | |
| 200 | default: |
| 201 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 202 | { |
| 203 | rtc_enable_alarm(false); |
| 204 | return true; |
| 205 | } |
| 206 | break; |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
Uwe Freese | 86352cc | 2003-01-22 12:50:34 +0000 | [diff] [blame] | 209 | return false; |
| 210 | } |
| 211 | |
Thom Johansen | 8fd6d65 | 2007-02-28 21:55:11 +0000 | [diff] [blame] | 212 | #endif /* HAVE_RTC_ALARM */ |