summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/lang/english.lang5
-rw-r--r--apps/main_menu.c2
-rw-r--r--apps/sleeptimer.c136
-rw-r--r--apps/sleeptimer.h24
-rw-r--r--docs/CREDITS1
-rw-r--r--firmware/powermgmt.c38
-rw-r--r--firmware/powermgmt.h3
7 files changed, 209 insertions, 0 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 45270293f5..af1d812743 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -1166,3 +1166,8 @@ id: LANG_BATTERY_TIME
desc: battery level in % and estimated time remaining
eng: "%d%% %dh %dm"
new:
+
+id: LANG_SLEEP_TIMER
+desc: sleep timer setting
+eng: "Sleep timer"
+new:
diff --git a/apps/main_menu.c b/apps/main_menu.c
index a5517f928d..234a21f3d5 100644
--- a/apps/main_menu.c
+++ b/apps/main_menu.c
@@ -39,6 +39,7 @@
#include "sound_menu.h"
#include "status.h"
#include "fat.h"
+#include "sleeptimer.h"
#include "lang.h"
@@ -247,6 +248,7 @@ bool main_menu(void)
struct menu_items items[] = {
{ str(LANG_SOUND_SETTINGS), sound_menu },
{ str(LANG_GENERAL_SETTINGS), settings_menu },
+ { str(LANG_SLEEP_TIMER), sleeptimer_screen },
#ifdef HAVE_MAS3587F
{ str(LANG_RECORDING_SETTINGS), recording_menu },
{ str(LANG_RECORDING), recording_screen },
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include "options.h"
+
+#include "lcd.h"
+#include "font.h"
+#include "button.h"
+#include "kernel.h"
+#include "sprintf.h"
+#include <string.h>
+#include "settings.h"
+#include "power.h"
+#include "powermgmt.h"
+#include "status.h"
+
+#include "lang.h"
+
+//#define SMALL_STEP_SIZE 15*60 /* Seconds */
+#define SMALL_STEP_SIZE 2*60 /* Seconds */
+#define LARGE_STEP_SIZE 30*60 /* Seconds */
+#define THRESHOLD 60 /* Minutes */
+#define MAX_TIME 5*60*60 /* Hours */
+
+bool sleeptimer_screen(void)
+{
+#ifdef HAVE_LCD_BITMAP
+ int w, h;
+#endif
+ unsigned long seconds;
+ int hours, minutes;
+ int button;
+ bool done = false;
+ char buf[32];
+ int oldtime, newtime;
+
+#ifdef HAVE_LCD_BITMAP
+ lcd_setfont(FONT_UI);
+ lcd_getstringsize("M", &w, &h);
+ lcd_setmargins(w, 8);
+#endif
+ int amount = 0;
+
+ while(!done)
+ {
+ button = button_get_w_tmo(HZ/20);
+ switch(button)
+ {
+#ifdef HAVE_PLAYER_KEYPAD
+ case BUTTON_STOP:
+#else
+ case BUTTON_OFF:
+ case BUTTON_LEFT:
+#endif
+ done = true;
+ break;
+
+#ifdef HAVE_PLAYER_KEYPAD
+ case BUTTON_RIGHT:
+#else
+ case BUTTON_UP:
+#endif
+ oldtime = (get_sleep_timer()+59) / 60;
+
+ if(oldtime < THRESHOLD)
+ amount = SMALL_STEP_SIZE;
+ else
+ amount = LARGE_STEP_SIZE;
+
+ newtime = oldtime * 60 + amount;
+ if(newtime > MAX_TIME)
+ newtime = MAX_TIME;
+
+ set_sleep_timer(newtime);
+ break;
+
+#ifdef HAVE_PLAYER_KEYPAD
+ case BUTTON_LEFT:
+#else
+ case BUTTON_DOWN:
+#endif
+ oldtime = (get_sleep_timer()+59) / 60;
+
+ if(oldtime <= THRESHOLD)
+ amount = SMALL_STEP_SIZE;
+ else
+ amount = LARGE_STEP_SIZE;
+
+ newtime = oldtime*60 - amount;
+ if(newtime < 0)
+ newtime = 0;
+
+ set_sleep_timer(newtime);
+ break;
+ }
+
+ seconds = get_sleep_timer();
+
+ lcd_clear_display();
+ lcd_puts(0, 0, str(LANG_SLEEP_TIMER));
+ if(seconds)
+ {
+ seconds += 59; /* Round up for a "friendlier" display */
+ hours = seconds / 3600;
+ minutes = (seconds - (hours * 3600)) / 60;
+ snprintf(buf, 32, "%d:%02d",
+ hours, minutes);
+ lcd_puts(0, 1, buf);
+ }
+ else
+ {
+ lcd_puts(0, 1, str(LANG_OFF));
+ }
+
+ status_draw();
+
+ lcd_update();
+ }
+ return false;
+}
diff --git a/apps/sleeptimer.h b/apps/sleeptimer.h
new file mode 100644
index 0000000000..b57580dc3a
--- /dev/null
+++ b/apps/sleeptimer.h
@@ -0,0 +1,24 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _SLEEPTIMER_H_
+#define _SLEEPTIMER_H_
+
+bool sleeptimer_screen(void);
+
+#endif
diff --git a/docs/CREDITS b/docs/CREDITS
index 1478bef569..4b9855212f 100644
--- a/docs/CREDITS
+++ b/docs/CREDITS
@@ -55,3 +55,4 @@ Mark Hillebrand
Damien Teney
Andreas Zwirtes
Kjell Ericson
+Jim Hagani
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 3ccb57fcaf..27c200aaeb 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -87,6 +87,9 @@ static int poweroff_timeout = 0;
static long last_charge_time = 0;
static int powermgmt_est_runningtime_min = -1;
+static bool sleeptimer_active = false;
+static unsigned long sleeptimer_endtick;
+
unsigned short power_history[POWER_HISTORY_LEN];
#ifdef HAVE_CHARGE_CTRL
char power_message[POWER_MESSAGE_LEN] = "";
@@ -190,6 +193,28 @@ void set_poweroff_timeout(int timeout)
poweroff_timeout = timeout;
}
+void set_sleep_timer(int seconds)
+{
+ if(seconds)
+ {
+ sleeptimer_active = true;
+ sleeptimer_endtick = current_tick + seconds * HZ;
+ }
+ else
+ {
+ sleeptimer_active = false;
+ sleeptimer_endtick = 0;
+ }
+}
+
+int get_sleep_timer(void)
+{
+ if(sleeptimer_active)
+ return (sleeptimer_endtick - current_tick) / HZ;
+ else
+ return 0;
+}
+
/* We shut off in the following cases:
1) The unit is idle, not playing music
2) The unit is playing music, but is paused
@@ -224,6 +249,19 @@ static void handle_auto_poweroff(void)
TIME_AFTER(current_tick, last_charge_time + timeout))
power_off();
}
+ else
+ {
+ /* Handle sleeptimer */
+ if(sleeptimer_endtick &&
+ !usb_inserted())
+ {
+ if(TIME_AFTER(current_tick, sleeptimer_endtick))
+ {
+ DEBUGF("Sleep timer timeout. Shutting off...\n");
+ power_off();
+ }
+ }
+ }
}
/*
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h
index f0c34a4fb1..8e8209bc43 100644
--- a/firmware/powermgmt.h
+++ b/firmware/powermgmt.h
@@ -76,4 +76,7 @@ bool battery_level_safe(void);
void set_poweroff_timeout(int timeout);
+void set_sleep_timer(int seconds);
+int get_sleep_timer(void);
+
#endif