1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Thomas Martitz 2012-01-03 23:44:38 +00:00
parent 949e6398c8
commit c1bd9b0361
156 changed files with 525 additions and 384 deletions

View file

@ -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

View file

@ -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:

View file

@ -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;

View file

@ -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 */
/* */

View file

@ -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
{

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,5 @@
/* plugins common to all models */
#ifndef SIMULATOR
#if !defined(SIMULATOR) && (CONFIG_BATTERY_MEASURE != 0)
battery_bench.c
#endif
chessclock.c

View file

@ -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

View file

@ -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