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: [PATCH] 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 --- apps/lang/english.lang | 14 ++++++++++++++ apps/menus/settings_menu.c | 5 ++++- apps/misc.c | 10 ++++++++++ apps/plugin.h | 4 ++-- apps/settings.h | 1 + apps/settings_list.c | 3 +++ firmware/export/kernel.h | 1 + firmware/powermgmt.c | 26 ++++++++++++++++++++++++++ 8 files changed, 61 insertions(+), 3 deletions(-) diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 91fb2905dd..f676da1184 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -11448,3 +11448,17 @@ multivolume: "Not present" + + id: LANG_TALK_BATTERY_LEVEL + desc: Setting for spontaneous battery level announcement + user: + + *: "Announce Battery Level" + + + *: "Announce Battery Level" + + + *: "Announce Battery Level" + + diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 8adcfe9b7a..1cea2b8c53 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -443,9 +443,12 @@ static int talk_callback(int action,const struct menu_item_ex *this_item) } return action; } +MENUITEM_SETTING(talk_battery_level_item, + &global_settings.talk_battery_level, NULL); MAKE_MENU(voice_settings_menu, ID2P(LANG_VOICE), 0, Icon_Voice, &talk_menu_item, &talk_dir_item, &talk_dir_clip_item, - &talk_file_item, &talk_file_clip_item); + &talk_file_item, &talk_file_clip_item, + &talk_battery_level_item); /* VOICE MENU */ /***********************************/ diff --git a/apps/misc.c b/apps/misc.c index 3c6ffd3032..d81794d5e7 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -857,6 +857,16 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame { switch(event) { + case SYS_BATTERY_UPDATE: + if(global_settings.talk_battery_level) + { + talk_ids(true, VOICE_PAUSE, VOICE_PAUSE, + LANG_BATTERY_TIME, + TALK_ID(battery_level(), UNIT_PERCENT), + VOICE_PAUSE); + talk_force_enqueue_next(); + } + break; case SYS_USB_CONNECTED: if (callback != NULL) callback(parameter); diff --git a/apps/plugin.h b/apps/plugin.h index 9e08dda7c7..16333bb092 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -112,12 +112,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 86 +#define PLUGIN_API_VERSION 87 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 86 +#define PLUGIN_MIN_API_VERSION 87 /* plugin return codes */ enum plugin_status { diff --git a/apps/settings.h b/apps/settings.h index f54569b462..2f926c91f6 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -529,6 +529,7 @@ struct user_settings bool talk_dir_clip; /* use directory .talk clips */ int talk_file; /* voice file mode: 0=off, 1=number, 2=spell */ bool talk_file_clip; /* use file .talk clips */ + bool talk_battery_level; /* file browser sorting */ int sort_file; /* 0=alpha, 1=date, 2=date (new first), 3=type */ diff --git a/apps/settings_list.c b/apps/settings_list.c index 609802c3a0..82f56c2bf9 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -753,6 +753,9 @@ const struct settings_list settings[] = { ID2P(LANG_OFF), ID2P(LANG_VOICE_NUMBER), ID2P(LANG_VOICE_SPELL)), OFFON_SETTING(F_TEMPVAR, talk_file_clip, LANG_VOICE_FILE_TALK, false, "talk file clip", NULL), + OFFON_SETTING(F_TEMPVAR, talk_battery_level, + LANG_TALK_BATTERY_LEVEL, false, + "Announce Battery Level", NULL), /* file sorting */ CHOICE_SETTING(0, sort_file, LANG_SORT_FILE, 0 , 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++; + } +}