summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/SOURCES1
-rw-r--r--apps/settings_menu.c32
-rw-r--r--apps/sleeptimer.c164
-rw-r--r--apps/sleeptimer.h24
4 files changed, 30 insertions, 191 deletions
diff --git a/apps/SOURCES b/apps/SOURCES
index dee4e6e002..e872531408 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -19,7 +19,6 @@ plugin.c
19screens.c 19screens.c
20settings.c 20settings.c
21settings_menu.c 21settings_menu.c
22sleeptimer.c
23sound_menu.c 22sound_menu.c
24status.c 23status.c
25#if !defined(SIMULATOR) || CONFIG_CODEC == SWCODEC 24#if !defined(SIMULATOR) || CONFIG_CODEC == SWCODEC
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 70703a23ce..5141416ecb 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -36,7 +36,6 @@
36#include "backlight.h" 36#include "backlight.h"
37#include "playlist.h" /* for playlist_shuffle */ 37#include "playlist.h" /* for playlist_shuffle */
38#include "fat.h" /* For dotfile settings */ 38#include "fat.h" /* For dotfile settings */
39#include "sleeptimer.h"
40#include "powermgmt.h" 39#include "powermgmt.h"
41#include "rtc.h" 40#include "rtc.h"
42#include "ata.h" 41#include "ata.h"
@@ -799,6 +798,35 @@ static bool poweroff_idle_timer(void)
799 INT, names, 15, set_poweroff_timeout); 798 INT, names, 15, set_poweroff_timeout);
800} 799}
801 800
801static void sleep_timer_formatter(char* buffer, int buffer_size, int value,
802 const char* unit)
803{
804 int minutes, hours;
805
806 (void) unit;
807
808 if (value) {
809 hours = value / 60;
810 minutes = value - (hours * 60);
811 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
812 } else {
813 snprintf(buffer, buffer_size, "%s", str(LANG_OFF));
814 }
815}
816
817static void sleep_timer_set(int minutes)
818{
819 set_sleep_timer(minutes * 60);
820}
821
822static bool sleep_timer(void)
823{
824 int minutes = get_sleep_timer() / 60;
825
826 return set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
827 &sleep_timer_set, 15, 0, 300, sleep_timer_formatter);
828}
829
802static bool scroll_speed(void) 830static bool scroll_speed(void)
803{ 831{
804 return set_int(str(LANG_SCROLL), "", UNIT_INT, 832 return set_int(str(LANG_SCROLL), "", UNIT_INT,
@@ -1864,7 +1892,7 @@ static bool system_settings_menu(void)
1864 { ID2P(LANG_TIME_MENU), time_settings_menu }, 1892 { ID2P(LANG_TIME_MENU), time_settings_menu },
1865#endif 1893#endif
1866 { ID2P(LANG_POWEROFF_IDLE), poweroff_idle_timer }, 1894 { ID2P(LANG_POWEROFF_IDLE), poweroff_idle_timer },
1867 { ID2P(LANG_SLEEP_TIMER), sleeptimer_screen }, 1895 { ID2P(LANG_SLEEP_TIMER), sleep_timer },
1868#ifdef HAVE_ALARM_MOD 1896#ifdef HAVE_ALARM_MOD
1869 { ID2P(LANG_ALARM_MOD_ALARM_MENU), alarm_screen }, 1897 { ID2P(LANG_ALARM_MOD_ALARM_MENU), alarm_screen },
1870#endif 1898#endif
diff --git a/apps/sleeptimer.c b/apps/sleeptimer.c
deleted file mode 100644
index e9b0924388..0000000000
--- a/apps/sleeptimer.c
+++ /dev/null
@@ -1,164 +0,0 @@
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 "statusbar.h"
32#include "debug.h"
33#include "talk.h"
34#include "icons.h"
35
36#include "lang.h"
37
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 */
42
43bool sleeptimer_screen(void)
44{
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;
55
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
62
63 lcd_clear_display();
64 lcd_puts_scroll(0, 0, str(LANG_SLEEP_TIMER));
65
66 while(!done)
67 {
68 button = button_get_w_tmo(HZ);
69 switch(button)
70 {
71#ifdef SETTINGS_OK2
72 case SETTINGS_OK2:
73#endif
74 case SETTINGS_OK:
75 done = true;
76 break;
77
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);
85 }
86 done = true;
87 break;
88
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;
95
96 newtime = oldtime * 60 + amount;
97 if(newtime > MAX_TIME)
98 newtime = MAX_TIME;
99
100 changed = sayit = true;
101 set_sleep_timer(newtime);
102 break;
103
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;
110
111 newtime = oldtime*60 - amount;
112 if(newtime < 0)
113 newtime = 0;
114
115 changed = sayit = true;
116 set_sleep_timer(newtime);
117 break;
118 }
119
120 seconds = get_sleep_timer();
121
122 if(seconds)
123 {
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);
130
131 if (sayit && global_settings.talk_menu)
132 {
133 bool enqueue = false; /* first one should not ne queued */
134
135 if (hours)
136 {
137 talk_value(hours, UNIT_HOUR, enqueue);
138 enqueue = true; /* queue any following */
139 }
140 if (minutes)
141 {
142 talk_value(minutes, UNIT_MIN, enqueue);
143 }
144
145 sayit = false;
146 }
147 }
148 else
149 {
150 lcd_puts(0, 1, str(LANG_OFF));
151 if (sayit && global_settings.talk_menu)
152 {
153 talk_id(LANG_OFF, false);
154 sayit = false;
155 }
156 }
157
158 gui_syncstatusbar_draw(&statusbars, true);
159
160 lcd_update();
161 }
162 lcd_stop_scroll();
163 return false;
164}
diff --git a/apps/sleeptimer.h b/apps/sleeptimer.h
deleted file mode 100644
index b57580dc3a..0000000000
--- a/apps/sleeptimer.h
+++ /dev/null
@@ -1,24 +0,0 @@
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#ifndef _SLEEPTIMER_H_
20#define _SLEEPTIMER_H_
21
22bool sleeptimer_screen(void);
23
24#endif