summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-09-23 11:42:48 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-09-23 11:42:48 +0000
commit083a6dbc4eebbc0d74cbf44c661008e14c744070 (patch)
treef903da302094edca2fe20eeb86785cae6b4c4754
parent040e80c3ad00ee9b100f97d510a0acd37489cb9b (diff)
downloadrockbox-083a6dbc4eebbc0d74cbf44c661008e14c744070.zip
rockbox-083a6dbc4eebbc0d74cbf44c661008e14c744070.tar.gz
rockbox-083a6dbc4eebbc0d74cbf44c661008e14c744070.tar.bz2
rockbox-083a6dbc4eebbc0d74cbf44c661008e14c744070.tar.xz
Auto-poweroff, by Lee Marlow
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2374 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/lang/english.lang5
-rw-r--r--apps/settings.h2
-rw-r--r--apps/settings_menu.c14
-rw-r--r--firmware/powermgmt.c29
-rw-r--r--firmware/powermgmt.h2
5 files changed, 50 insertions, 2 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 7962b55..6402f8c 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -781,3 +781,8 @@ id: LANG_TETRIS_LEVEL
desc: tetris game
eng: "0 Rows - Level 0"
new:
+
+id: LANG_POWEROFF_IDLE
+desc: in settings_menu
+eng: "Idle Poweroff"
+new:
diff --git a/apps/settings.h b/apps/settings.h
index d03a5f6..374b6e4 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -62,7 +62,7 @@ struct user_settings
/* device settings */
int contrast; /* lcd contrast: 0-100 0=low 100=high */
- int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */
+ int poweroff; /* power off timer */
int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */
bool discharge; /* maintain charge of at least: false = 90%, true = 10% */
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 5ad7a1e..1e7f2f7 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -99,6 +99,17 @@ static Menu backlight_timer(void)
return MENU_OK;
}
+static Menu poweroff_idle_timer(void)
+{
+ char* names[] = { str(LANG_OFF),
+ "1m ", "2m ", "3m ", "4m ", "5m ",
+ "6m ", "7m ", "8m ", "9m ", "10m",
+ "15m", "30m", "45m", "60m"};
+ set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff, names,
+ 15, set_poweroff_timeout);
+ return MENU_OK;
+}
+
static Menu scroll_speed(void)
{
set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed,
@@ -337,7 +348,8 @@ static Menu system_settings_menu(void)
#ifdef HAVE_LCD_BITMAP
{ str(LANG_TIME), timedate_set },
#endif
- { str(LANG_RESET), reset_settings },
+ { str(LANG_POWEROFF_IDLE), poweroff_idle_timer },
+ { str(LANG_RESET), reset_settings },
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 1f54aae..30b4d09 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -28,6 +28,9 @@
#include "sprintf.h"
#include "ata.h"
#include "power.h"
+#include "button.h"
+#include "ata.h"
+#include "mpeg.h"
#include "powermgmt.h"
#ifdef SIMULATOR
@@ -44,9 +47,16 @@ bool battery_level_safe(void)
#else /* not SIMULATOR */
+static int poweroff_idle_timeout_value[15] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60
+};
+
static char power_stack[DEFAULT_STACK_SIZE];
static char power_thread_name[] = "power";
+static int poweroff_timeout = 0;
+
unsigned short power_history[POWER_HISTORY_LEN];
#ifdef HAVE_CHARGE_CTRL
char power_message[POWER_MESSAGE_LEN] = "";
@@ -91,6 +101,23 @@ bool battery_level_safe(void)
return adc_read(ADC_UNREG_POWER) > (BATTERY_LEVEL_DANGEROUS * 10000) / BATTERY_SCALE_FACTOR;
}
+void set_poweroff_timeout(int timeout)
+{
+ poweroff_timeout = timeout;
+}
+
+static void handle_auto_poweroff(void)
+{
+ long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ;
+
+ if(timeout && !mpeg_is_playing() && !charger_inserted())
+ {
+ if(TIME_AFTER(current_tick, last_keypress + timeout) &&
+ TIME_AFTER(current_tick, last_disk_activity + timeout))
+ power_off();
+ }
+}
+
/*
* This power thread maintains a history of battery voltage
* and implements a charging algorithm.
@@ -233,6 +260,8 @@ static void power_thread(void)
/* sleep for roughly a minute */
sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP));
+
+ handle_auto_poweroff();
}
}
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h
index 3fa6f3e..329bf60 100644
--- a/firmware/powermgmt.h
+++ b/firmware/powermgmt.h
@@ -61,4 +61,6 @@ int battery_level(void);
/* Tells if the battery level is safe for disk writes */
bool battery_level_safe(void);
+void set_poweroff_timeout(int timeout);
+
#endif