Patch #3060 from Andrew Scott - iPod mini button driver
[Rockbox.git] / apps / sleeptimer.c
blobe9b0924388b55697b2c88aebce0b202b56690cc1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
20 #include "options.h"
22 #include "lcd.h"
23 #include "font.h"
24 #include "button.h"
25 #include "kernel.h"
26 #include "sprintf.h"
27 #include <string.h>
28 #include "settings.h"
29 #include "power.h"
30 #include "powermgmt.h"
31 #include "statusbar.h"
32 #include "debug.h"
33 #include "talk.h"
34 #include "icons.h"
36 #include "lang.h"
38 #define SMALL_STEP_SIZE 15*60 /* Seconds */
39 #define LARGE_STEP_SIZE 30*60 /* Seconds */
40 #define THRESHOLD 60 /* Minutes */
41 #define MAX_TIME 5*60*60 /* Hours */
43 bool sleeptimer_screen(void)
45 unsigned long seconds;
46 int hours, minutes;
47 int button;
48 bool done = false;
49 char buf[32];
50 int oldtime, newtime;
51 int amount = 0;
52 int org_timer=get_sleep_timer();
53 bool changed=false;
54 bool sayit = true;
56 #ifdef HAVE_LCD_BITMAP
57 if (global_settings.statusbar)
58 lcd_setmargins(0, STATUSBAR_HEIGHT);
59 else
60 lcd_setmargins(0, 0);
61 #endif
63 lcd_clear_display();
64 lcd_puts_scroll(0, 0, str(LANG_SLEEP_TIMER));
66 while(!done)
68 button = button_get_w_tmo(HZ);
69 switch(button)
71 #ifdef SETTINGS_OK2
72 case SETTINGS_OK2:
73 #endif
74 case SETTINGS_OK:
75 done = true;
76 break;
78 case SETTINGS_CANCEL:
79 if (changed) {
80 lcd_stop_scroll();
81 lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL));
82 lcd_update();
83 set_sleep_timer(org_timer);
84 sleep(HZ/2);
86 done = true;
87 break;
89 case SETTINGS_INC:
90 oldtime = (get_sleep_timer()+59) / 60;
91 if(oldtime < THRESHOLD)
92 amount = SMALL_STEP_SIZE;
93 else
94 amount = LARGE_STEP_SIZE;
96 newtime = oldtime * 60 + amount;
97 if(newtime > MAX_TIME)
98 newtime = MAX_TIME;
100 changed = sayit = true;
101 set_sleep_timer(newtime);
102 break;
104 case SETTINGS_DEC:
105 oldtime = (get_sleep_timer()+59) / 60;
106 if(oldtime <= THRESHOLD)
107 amount = SMALL_STEP_SIZE;
108 else
109 amount = LARGE_STEP_SIZE;
111 newtime = oldtime*60 - amount;
112 if(newtime < 0)
113 newtime = 0;
115 changed = sayit = true;
116 set_sleep_timer(newtime);
117 break;
120 seconds = get_sleep_timer();
122 if(seconds)
124 seconds += 59; /* Round up for a "friendlier" display */
125 hours = seconds / 3600;
126 minutes = (seconds - (hours * 3600)) / 60;
127 snprintf(buf, 32, "%d:%02d",
128 hours, minutes);
129 lcd_puts(0, 1, (unsigned char *)buf);
131 if (sayit && global_settings.talk_menu)
133 bool enqueue = false; /* first one should not ne queued */
135 if (hours)
137 talk_value(hours, UNIT_HOUR, enqueue);
138 enqueue = true; /* queue any following */
140 if (minutes)
142 talk_value(minutes, UNIT_MIN, enqueue);
145 sayit = false;
148 else
150 lcd_puts(0, 1, str(LANG_OFF));
151 if (sayit && global_settings.talk_menu)
153 talk_id(LANG_OFF, false);
154 sayit = false;
158 gui_syncstatusbar_draw(&statusbars, true);
160 lcd_update();
162 lcd_stop_scroll();
163 return false;