Auto-poweroff, by Lee Marlow
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2374 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
040e80c3ad
commit
083a6dbc4e
5 changed files with 50 additions and 2 deletions
|
@ -781,3 +781,8 @@ id: LANG_TETRIS_LEVEL
|
||||||
desc: tetris game
|
desc: tetris game
|
||||||
eng: "0 Rows - Level 0"
|
eng: "0 Rows - Level 0"
|
||||||
new:
|
new:
|
||||||
|
|
||||||
|
id: LANG_POWEROFF_IDLE
|
||||||
|
desc: in settings_menu
|
||||||
|
eng: "Idle Poweroff"
|
||||||
|
new:
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct user_settings
|
||||||
/* device settings */
|
/* device settings */
|
||||||
|
|
||||||
int contrast; /* lcd contrast: 0-100 0=low 100=high */
|
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 */
|
int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */
|
||||||
bool discharge; /* maintain charge of at least: false = 90%, true = 10% */
|
bool discharge; /* maintain charge of at least: false = 90%, true = 10% */
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,17 @@ static Menu backlight_timer(void)
|
||||||
return MENU_OK;
|
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)
|
static Menu scroll_speed(void)
|
||||||
{
|
{
|
||||||
set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed,
|
set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed,
|
||||||
|
@ -337,7 +348,8 @@ static Menu system_settings_menu(void)
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
{ str(LANG_TIME), timedate_set },
|
{ str(LANG_TIME), timedate_set },
|
||||||
#endif
|
#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) );
|
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
#include "sprintf.h"
|
#include "sprintf.h"
|
||||||
#include "ata.h"
|
#include "ata.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "ata.h"
|
||||||
|
#include "mpeg.h"
|
||||||
#include "powermgmt.h"
|
#include "powermgmt.h"
|
||||||
|
|
||||||
#ifdef SIMULATOR
|
#ifdef SIMULATOR
|
||||||
|
@ -44,9 +47,16 @@ bool battery_level_safe(void)
|
||||||
|
|
||||||
#else /* not SIMULATOR */
|
#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_stack[DEFAULT_STACK_SIZE];
|
||||||
static char power_thread_name[] = "power";
|
static char power_thread_name[] = "power";
|
||||||
|
|
||||||
|
static int poweroff_timeout = 0;
|
||||||
|
|
||||||
unsigned short power_history[POWER_HISTORY_LEN];
|
unsigned short power_history[POWER_HISTORY_LEN];
|
||||||
#ifdef HAVE_CHARGE_CTRL
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
char power_message[POWER_MESSAGE_LEN] = "";
|
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;
|
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
|
* This power thread maintains a history of battery voltage
|
||||||
* and implements a charging algorithm.
|
* and implements a charging algorithm.
|
||||||
|
@ -233,6 +260,8 @@ static void power_thread(void)
|
||||||
|
|
||||||
/* sleep for roughly a minute */
|
/* sleep for roughly a minute */
|
||||||
sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP));
|
sleep(HZ*(60 - POWER_AVG_N * POWER_AVG_SLEEP));
|
||||||
|
|
||||||
|
handle_auto_poweroff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,4 +61,6 @@ int battery_level(void);
|
||||||
/* Tells if the battery level is safe for disk writes */
|
/* Tells if the battery level is safe for disk writes */
|
||||||
bool battery_level_safe(void);
|
bool battery_level_safe(void);
|
||||||
|
|
||||||
|
void set_poweroff_timeout(int timeout);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue