summaryrefslogtreecommitdiff
path: root/apps/sleeptimer.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-12-03 22:41:50 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-12-03 22:41:50 +0000
commitb43dba87607b4d5e1de42574ee43141719f41a87 (patch)
tree727c09f69141a63c20c28a73d72ac97f3824ec92 /apps/sleeptimer.c
parent2c639f5f862b5834ac411630873e0b8fdf7e6c46 (diff)
downloadrockbox-b43dba87607b4d5e1de42574ee43141719f41a87.tar.gz
rockbox-b43dba87607b4d5e1de42574ee43141719f41a87.zip
Sleep timer, inspired by Jim Hagani
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2918 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/sleeptimer.c')
-rw-r--r--apps/sleeptimer.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/apps/sleeptimer.c b/apps/sleeptimer.c
new file mode 100644
index 0000000000..c846e08486
--- /dev/null
+++ b/apps/sleeptimer.c
@@ -0,0 +1,136 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Linus Nielsen Feltzing
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "options.h"
21
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 "status.h"
32
33#include "lang.h"
34
35//#define SMALL_STEP_SIZE 15*60 /* Seconds */
36#define SMALL_STEP_SIZE 2*60 /* Seconds */
37#define LARGE_STEP_SIZE 30*60 /* Seconds */
38#define THRESHOLD 60 /* Minutes */
39#define MAX_TIME 5*60*60 /* Hours */
40
41bool sleeptimer_screen(void)
42{
43#ifdef HAVE_LCD_BITMAP
44 int w, h;
45#endif
46 unsigned long seconds;
47 int hours, minutes;
48 int button;
49 bool done = false;
50 char buf[32];
51 int oldtime, newtime;
52
53#ifdef HAVE_LCD_BITMAP
54 lcd_setfont(FONT_UI);
55 lcd_getstringsize("M", &w, &h);
56 lcd_setmargins(w, 8);
57#endif
58 int amount = 0;
59
60 while(!done)
61 {
62 button = button_get_w_tmo(HZ/20);
63 switch(button)
64 {
65#ifdef HAVE_PLAYER_KEYPAD
66 case BUTTON_STOP:
67#else
68 case BUTTON_OFF:
69 case BUTTON_LEFT:
70#endif
71 done = true;
72 break;
73
74#ifdef HAVE_PLAYER_KEYPAD
75 case BUTTON_RIGHT:
76#else
77 case BUTTON_UP:
78#endif
79 oldtime = (get_sleep_timer()+59) / 60;
80
81 if(oldtime < THRESHOLD)
82 amount = SMALL_STEP_SIZE;
83 else
84 amount = LARGE_STEP_SIZE;
85
86 newtime = oldtime * 60 + amount;
87 if(newtime > MAX_TIME)
88 newtime = MAX_TIME;
89
90 set_sleep_timer(newtime);
91 break;
92
93#ifdef HAVE_PLAYER_KEYPAD
94 case BUTTON_LEFT:
95#else
96 case BUTTON_DOWN:
97#endif
98 oldtime = (get_sleep_timer()+59) / 60;
99
100 if(oldtime <= THRESHOLD)
101 amount = SMALL_STEP_SIZE;
102 else
103 amount = LARGE_STEP_SIZE;
104
105 newtime = oldtime*60 - amount;
106 if(newtime < 0)
107 newtime = 0;
108
109 set_sleep_timer(newtime);
110 break;
111 }
112
113 seconds = get_sleep_timer();
114
115 lcd_clear_display();
116 lcd_puts(0, 0, str(LANG_SLEEP_TIMER));
117 if(seconds)
118 {
119 seconds += 59; /* Round up for a "friendlier" display */
120 hours = seconds / 3600;
121 minutes = (seconds - (hours * 3600)) / 60;
122 snprintf(buf, 32, "%d:%02d",
123 hours, minutes);
124 lcd_puts(0, 1, buf);
125 }
126 else
127 {
128 lcd_puts(0, 1, str(LANG_OFF));
129 }
130
131 status_draw();
132
133 lcd_update();
134 }
135 return false;
136}