Shutdown and powermanagement cleanup: * Use the proper function for determining whether the battery level is safe, and get rid of the extra one. Low battery warning now appears at 10% or less. * Don't delay shutdown artificially by 3 seconds due to low/critical battery warning. * Shutdown at critical battery level: Skip all disk-hitting housekeeping, make sure dircache stops, and don't mark disk as clean in eeprom.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13734 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2007-06-29 19:01:24 +00:00
parent 63c266e5e5
commit da5910eac0
3 changed files with 44 additions and 49 deletions

View file

@ -611,7 +611,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
if(!charger_inserted())
#endif
{
bool batt_crit = battery_level_critical();
bool batt_safe = battery_level_safe();
int audio_stat = audio_status();
FOR_NB_SCREENS(i)
@ -619,15 +619,8 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
#ifdef X5_BACKLIGHT_SHUTDOWN
x5_backlight_shutdown();
#endif
if (!battery_level_safe())
gui_syncsplash(3*HZ, "%s %s",
str(LANG_WARNING_BATTERY_EMPTY),
str(LANG_SHUTTINGDOWN));
else if (battery_level_critical())
gui_syncsplash(3*HZ, "%s %s",
str(LANG_WARNING_BATTERY_LOW),
str(LANG_SHUTTINGDOWN));
else {
if (batt_safe)
{
#ifdef HAVE_TAGCACHE
if (!tagcache_prepare_shutdown())
{
@ -636,44 +629,60 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
return false;
}
#endif
gui_syncsplash(0, str(LANG_SHUTTINGDOWN));
if (battery_level() > 10)
gui_syncsplash(0, str(LANG_SHUTTINGDOWN));
else
gui_syncsplash(0, "%s %s",
str(LANG_WARNING_BATTERY_LOW),
str(LANG_SHUTTINGDOWN));
}
else
{
gui_syncsplash(0, "%s %s",
str(LANG_WARNING_BATTERY_EMPTY),
str(LANG_SHUTTINGDOWN));
}
if (global_settings.fade_on_stop
if (global_settings.fade_on_stop
&& (audio_stat & AUDIO_STATUS_PLAY))
{
fade(0);
}
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
if (!batt_crit && (audio_stat & AUDIO_STATUS_RECORD))
if (batt_safe) /* do not save on critical battery */
{
audio_stop_recording();
while(audio_status() & AUDIO_STATUS_RECORD)
sleep(1);
}
audio_close_recording();
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
if (audio_stat & AUDIO_STATUS_RECORD)
audio_stop_recording();
#endif
/* audio_stop_recording == audio_stop for HWCODEC */
/* audio_stop_recording == audio_stop for HWCODEC */
audio_stop();
audio_stop();
while (audio_status())
sleep(1);
if (callback != NULL)
callback(parameter);
if (callback != NULL)
callback(parameter);
if (!batt_crit) /* do not save on critical battery */
/* wait for audio_stop or audio_stop_recording to complete */
while (audio_status())
sleep(1);
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
audio_close_recording();
#endif
system_flush();
#ifdef HAVE_EEPROM_SETTINGS
if (firmware_settings.initialized)
{
firmware_settings.disk_clean = true;
firmware_settings.bl_version = 0;
eeprom_settings_store();
}
if (firmware_settings.initialized)
{
firmware_settings.disk_clean = true;
firmware_settings.bl_version = 0;
eeprom_settings_store();
}
#endif
}
#ifdef HAVE_DIRCACHE
else
dircache_disable();
#endif
shutdown_hw();
}
#endif

View file

@ -144,9 +144,6 @@ void battery_read_info(int *adc, int *voltage, int *level);
/* Tells if the battery level is safe for disk writes */
bool battery_level_safe(void);
/* Tells if battery is in critical power saving state */
bool battery_level_critical(void);
void set_poweroff_timeout(int timeout);
void set_battery_capacity(int capacity); /* set local battery capacity value */
void set_battery_type(int type); /* set local battery type */

View file

@ -143,11 +143,6 @@ bool battery_level_safe(void)
return battery_level() >= 10;
}
bool battery_level_critical(void)
{
return false;
}
void set_poweroff_timeout(int timeout)
{
(void)timeout;
@ -422,12 +417,6 @@ bool battery_level_safe(void)
return battery_centivolts > battery_level_dangerous[battery_type];
}
/* Tells if the battery is in critical powersaving state */
bool battery_level_critical(void)
{
return ((battery_capacity * battery_percent / BATTERY_CAPACITY_MIN) < 10);
}
void set_poweroff_timeout(int timeout)
{
poweroff_timeout = timeout;
@ -1291,7 +1280,7 @@ void shutdown_hw(void)
}
#endif
audio_stop();
if (!battery_level_critical()) { /* do not save on critical battery */
if (battery_level_safe()) { /* do not save on critical battery */
#ifdef HAVE_LCD_BITMAP
glyph_cache_save();
#endif