From da93299865a58e3c0c86b4065a4dbbc566b2317b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Doyon?= Date: Sat, 3 Nov 2007 05:00:49 +0000 Subject: Accept FS#7910: spontaneously speak out the battery level when it falls under 50%, 30% and 15%. Guarded by an option under voice settings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15422 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/kernel.h | 1 + firmware/powermgmt.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'firmware') diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index 041f846380..96a7752017 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h @@ -65,6 +65,7 @@ #define SYS_POWEROFF MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 0) #define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1) #define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2) +#define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3) #define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0) #define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0) #define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1) diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index fcc3030861..31c33a433f 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -80,6 +80,9 @@ static int shutdown_timeout = 0; charge_state_type charge_state; /* charging mode */ #endif +static void send_battery_level_event(void); +static int last_sent_battery_level = 100; + #if CONFIG_CHARGING charger_input_state_type charger_input_state IDATA_ATTR; #endif @@ -111,6 +114,7 @@ static void battery_status_update(void) batt_level = 100 * (batt_millivolts - BATT_MINMVOLT) / (BATT_MAXMVOLT - BATT_MINMVOLT); batt_time = batt_level * BATT_MAXRUNTIME / 100; } + send_battery_level_event(); } void battery_read_info(int *voltage, int *level) @@ -459,6 +463,7 @@ static void battery_status_update(void) } battery_percent = level; + send_battery_level_event(); } /* @@ -638,6 +643,7 @@ static void power_thread_sleep(int ticks) return; case CHARGER_PLUGGED: queue_broadcast(SYS_CHARGER_CONNECTED, 0); + last_sent_battery_level = 0; charger_input_state = CHARGER; break; case CHARGER: @@ -649,6 +655,7 @@ static void power_thread_sleep(int ticks) break; case CHARGER_UNPLUGGED: queue_broadcast(SYS_CHARGER_DISCONNECTED, 0); + last_sent_battery_level = 100; charger_input_state = NO_CHARGER; break; case CHARGER_PLUGGED: @@ -1192,3 +1199,22 @@ void shutdown_hw(void) power_off(); #endif /* #ifndef SIMULATOR */ } + +/* Send system battery level update events on reaching certain + significant levels. */ +static void send_battery_level_event(void) +{ + int current_level = battery_level(); + static const int levels[] = { 15, 30, 50, 0 }; + const int *level = levels; + while (*level) + { + if (current_level <= *level && last_sent_battery_level > *level) + { + last_sent_battery_level = *level; + queue_broadcast(SYS_BATTERY_UPDATE, last_sent_battery_level); + break; + } + level++; + } +} -- cgit v1.2.3