diff options
| author | Thomas Martitz <kugel@rockbox.org> | 2012-01-03 23:44:38 +0000 |
|---|---|---|
| committer | Thomas Martitz <kugel@rockbox.org> | 2012-01-03 23:44:38 +0000 |
| commit | c1bd9b0361ba92c29ceef68d74093e70a1a3e481 (patch) | |
| tree | 1a42acdf2099b7f5ac06eee11e1d488b388c6d9f /apps | |
| parent | 949e6398c89e3c277a4c542f67a5ee788c6f642d (diff) | |
| download | rockbox-c1bd9b0361ba92c29ceef68d74093e70a1a3e481.zip rockbox-c1bd9b0361ba92c29ceef68d74093e70a1a3e481.tar.gz rockbox-c1bd9b0361ba92c29ceef68d74093e70a1a3e481.tar.bz2 rockbox-c1bd9b0361ba92c29ceef68d74093e70a1a3e481.tar.xz | |
Rework powermgmt to enable code re-use on appliation and sims.
* Introduce CONFIG_BATTERY_MEASURE define, to allow targets (application)
to break powermgmt.c's assumption about the ability to read battery voltage.
There's now additionally percentage (android) and remaining time measure
(maemo). No measure at all also works (sdl app). If voltage can't be measured,
then battery_level() is king and it'll be used for power_history and runtime
estimation.
* Implement target's API in the simulator, i.e. _battery_voltage(), so it
doesn't need to implement it's own powermgmt.c and other stubs. Now
the sim behaves much more like a native target, although it still
changes the simulated battery voltage quickly,
* Other changes include include renaming battery_adc_voltage() to
_battery_voltage(), for consistency with the new target functions and
making some of the apps code aware that voltage and runtime estimation
is not always available.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31548 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/debug_menu.c | 66 | ||||
| -rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 10 | ||||
| -rw-r--r-- | apps/menus/main_menu.c | 6 | ||||
| -rw-r--r-- | apps/menus/theme_menu.c | 6 | ||||
| -rw-r--r-- | apps/misc.c | 4 | ||||
| -rw-r--r-- | apps/plugin.c | 2 | ||||
| -rw-r--r-- | apps/plugin.h | 4 | ||||
| -rw-r--r-- | apps/plugins/SOURCES | 2 | ||||
| -rw-r--r-- | apps/settings.h | 2 | ||||
| -rw-r--r-- | apps/settings_list.c | 2 |
10 files changed, 68 insertions, 36 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index b4d917a..3404071 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -900,8 +900,7 @@ static bool tsc2100_debug(void) return simplelist_show_list(&info); } #endif -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) -#ifdef HAVE_LCD_BITMAP +#if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR) /* * view_battery() shows a automatically scaled graph of the battery voltage * over time. Usable for estimating battery life / charging rate. @@ -909,13 +908,14 @@ static bool tsc2100_debug(void) */ #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN) -#define BAT_YSPACE (LCD_HEIGHT - 20) +#define BAT_TSPACE 20 +#define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE) static bool view_battery(void) { int view = 0; - int i, x, y, y1, y2, grid, graph; + int i, x, y, z, y1, y2, grid, graph; unsigned short maxv, minv; lcd_setfont(FONT_SYSFIXED); @@ -934,19 +934,28 @@ static bool view_battery(void) if (power_history[i] < minv) minv = power_history[i]; } - + /* print header */ +#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) /* adjust grid scale */ if ((maxv - minv) > 50) grid = 50; else grid = 5; - - /* print header */ + lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000, power_history[0] % 1000); lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)", minv / 1000, minv % 1000, maxv / 1000, maxv % 1000, grid); +#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) + /* adjust grid scale */ + if ((maxv - minv) > 10) + grid = 10; + else + grid = 1; + lcd_putsf(0, 0, "battery %d%%", power_history[0]); + lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid); +#endif i = 1; while ((y = (minv - (minv % grid)+i*grid)) < maxv) @@ -971,11 +980,11 @@ static bool view_battery(void) { y1 = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv); - y1 = MIN(MAX(LCD_HEIGHT-1 - y1, 20), + y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE), LCD_HEIGHT-1); y2 = (power_history[i-1] - minv) * BAT_YSPACE / (maxv - minv); - y2 = MIN(MAX(LCD_HEIGHT-1 - y2, 20), + y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE), LCD_HEIGHT-1); lcd_set_drawmode(DRMODE_SOLID); @@ -999,10 +1008,13 @@ static bool view_battery(void) lcd_putsf(0, 0, "Pwr status: %s", charging_state() ? "charging" : "discharging"); #else - lcd_puts(0, 0, "Power status:"); + lcd_puts(0, 0, "Power status: unknown"); #endif - battery_read_info(&y, NULL); - lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000); + battery_read_info(&y, &z); + if (y > 0) + lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z); + else if (z > 0) + lcd_putsf(0, 1, "Battery: %d %%", z); #ifdef ADC_EXT_POWER y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000; lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000); @@ -1169,16 +1181,23 @@ static bool view_battery(void) #endif /* target type */ #endif /* CONFIG_CHARGING */ break; - case 2: /* voltage deltas: */ +#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) lcd_puts(0, 0, "Voltage deltas:"); - - for (i = 0; i <= 6; i++) { + for (i = 0; i < POWER_HISTORY_LEN-1; i++) { y = power_history[i] - power_history[i+1]; - lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i, - (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000, + lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i, + (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000, ((y < 0) ? y * -1 : y ) % 1000); } +#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) + lcd_puts(0, 0, "Percentage deltas:"); + for (i = 0; i < POWER_HISTORY_LEN-1; i++) { + y = power_history[i] - power_history[i+1]; + lcd_putsf(0, i+1, "-%d min: %c%d%%", i, + (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y)); + } +#endif break; case 3: /* remaining time estimation: */ @@ -1195,13 +1214,19 @@ static bool view_battery(void) lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec); #endif /* ARCHOS_RECORDER */ +#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) lcd_putsf(0, 5, "Last PwrHist: %d.%03dV", power_history[0] / 1000, power_history[0] % 1000); +#endif lcd_putsf(0, 6, "battery level: %d%%", battery_level()); - lcd_putsf(0, 7, "Est. remain: %d m", battery_time()); + int time_left = battery_time(); + if (time_left >= 0) + lcd_putsf(0, 7, "Est. remain: %d m", time_left); + else + lcd_puts(0, 7, "Estimation n/a"); break; } @@ -1228,8 +1253,7 @@ static bool view_battery(void) return false; } -#endif /* HAVE_LCD_BITMAP */ -#endif +#endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */ #if (CONFIG_PLATFORM & PLATFORM_NATIVE) #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) @@ -2168,7 +2192,7 @@ static const struct the_menu_item menuitems[] = { { "View CPU stats", dbg_cpuinfo }, #endif #ifdef HAVE_LCD_BITMAP -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) +#if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR) { "View battery", view_battery }, #endif #ifndef APPLICATION diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 169c4a3..bae8ae8 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -1068,9 +1068,13 @@ const char *get_token_value(struct gui_wps *gwps, case SKIN_TOKEN_BATTERY_VOLTS: { - unsigned int v = battery_voltage(); - snprintf(buf, buf_size, "%d.%02d", v / 1000, (v % 1000) / 10); - return buf; + int v = battery_voltage(); + if (v >= 0) { + snprintf(buf, buf_size, "%d.%02d", v / 1000, (v % 1000) / 10); + return buf; + } else { + return "?"; + } } case SKIN_TOKEN_BATTERY_TIME: diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index cefc395..b7472a6 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c @@ -210,7 +210,7 @@ static const char* info_getname(int selected_item, void *data, snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME), battery_level(), battery_time() / 60, battery_time() % 60); else - return "(n/a)"; + return "Battery n/a"; /* translating worth it? */ break; case INFO_DISK1: /* disk usage 1 */ #ifdef HAVE_MULTIVOLUME @@ -289,9 +289,11 @@ static int info_speak_item(int selected_item, void * data) #endif /* CONFIG_CHARGING = */ if (battery_level() >= 0) { + int time_left = battery_time(); talk_id(LANG_BATTERY_TIME, false); talk_value(battery_level(), UNIT_PERCENT, true); - talk_value(battery_time() *60, UNIT_TIME, true); + if (time_left >= 0) + talk_value(time_left * 60, UNIT_TIME, true); } else talk_id(VOICE_BLANK, false); break; diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c index e1077a5..5e04191 100644 --- a/apps/menus/theme_menu.c +++ b/apps/menus/theme_menu.c @@ -219,7 +219,11 @@ MAKE_MENU(bars_menu, ID2P(LANG_BARS_MENU), 0, Icon_NOICON, #if CONFIG_KEYPAD == RECORDER_PAD &buttonbar, #endif - &volume_type, &battery_display); + &volume_type +#if (CONFIG_BATTERY_MEASURE != 0) + , &battery_display +#endif + ); #endif /* HAVE_LCD_BITMAP */ /* */ diff --git a/apps/misc.c b/apps/misc.c index b1def59..30c7471 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -277,6 +277,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) if (batt_safe) { + int level; #ifdef HAVE_TAGCACHE if (!tagcache_prepare_shutdown()) { @@ -285,7 +286,8 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) return false; } #endif - if (battery_level() > 10) + level = battery_level(); + if (level > 10 || level < 0) splash(0, str(LANG_SHUTTINGDOWN)); else { diff --git a/apps/plugin.c b/apps/plugin.c index f17ad3c..2528075 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -664,9 +664,7 @@ static const struct plugin_api rockbox_api = { battery_level, battery_level_safe, battery_time, -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) battery_voltage, -#endif #if CONFIG_CHARGING charger_inserted, # if CONFIG_CHARGING >= CHARGING_MONITOR diff --git a/apps/plugin.h b/apps/plugin.h index 0bb7262..918206a 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -794,9 +794,7 @@ struct plugin_api { int (*battery_level)(void); bool (*battery_level_safe)(void); int (*battery_time)(void); -#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) - unsigned int (*battery_voltage)(void); -#endif + int (*battery_voltage)(void); #if CONFIG_CHARGING bool (*charger_inserted)(void); # if CONFIG_CHARGING >= CHARGING_MONITOR diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 1b14c0d..a72579e 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -1,5 +1,5 @@ /* plugins common to all models */ -#ifndef SIMULATOR +#if !defined(SIMULATOR) && (CONFIG_BATTERY_MEASURE != 0) battery_bench.c #endif chessclock.c diff --git a/apps/settings.h b/apps/settings.h index 676e5bf..d0fd320 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -638,7 +638,7 @@ struct user_settings /* power settings */ int poweroff; /* idle power off timer */ -#ifdef BATTERY_CAPACITY_DEFAULT +#if BATTERY_CAPACITY_DEFAULT > 0 int battery_capacity; /* in mAh */ #endif diff --git a/apps/settings_list.c b/apps/settings_list.c index c9003bb..dff5ed2 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -838,7 +838,7 @@ const struct settings_list settings[] = { NULL, NULL, NULL), /* use this setting for user code even if there's no exchangable battery * support enabled */ -#ifdef BATTERY_CAPACITY_DEFAULT +#if BATTERY_CAPACITY_DEFAULT > 0 /* define min/max/inc for this file if there's only one battery */ #ifndef BATTERY_CAPACITY_MIN #define BATTERY_CAPACITY_MIN BATTERY_CAPACITY_DEFAULT |