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/debug_menu.c | |
parent | 949e6398c89e3c277a4c542f67a5ee788c6f642d (diff) | |
download | rockbox-c1bd9b0361ba92c29ceef68d74093e70a1a3e481.tar.gz rockbox-c1bd9b0361ba92c29ceef68d74093e70a1a3e481.zip |
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/debug_menu.c')
-rw-r--r-- | apps/debug_menu.c | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index b4d917a3eb..340407176c 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -900,8 +900,7 @@ static bool tsc2100_debug(void) | |||
900 | return simplelist_show_list(&info); | 900 | return simplelist_show_list(&info); |
901 | } | 901 | } |
902 | #endif | 902 | #endif |
903 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) | 903 | #if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR) |
904 | #ifdef HAVE_LCD_BITMAP | ||
905 | /* | 904 | /* |
906 | * view_battery() shows a automatically scaled graph of the battery voltage | 905 | * view_battery() shows a automatically scaled graph of the battery voltage |
907 | * over time. Usable for estimating battery life / charging rate. | 906 | * over time. Usable for estimating battery life / charging rate. |
@@ -909,13 +908,14 @@ static bool tsc2100_debug(void) | |||
909 | */ | 908 | */ |
910 | 909 | ||
911 | #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN) | 910 | #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN) |
912 | #define BAT_YSPACE (LCD_HEIGHT - 20) | 911 | #define BAT_TSPACE 20 |
912 | #define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE) | ||
913 | 913 | ||
914 | 914 | ||
915 | static bool view_battery(void) | 915 | static bool view_battery(void) |
916 | { | 916 | { |
917 | int view = 0; | 917 | int view = 0; |
918 | int i, x, y, y1, y2, grid, graph; | 918 | int i, x, y, z, y1, y2, grid, graph; |
919 | unsigned short maxv, minv; | 919 | unsigned short maxv, minv; |
920 | 920 | ||
921 | lcd_setfont(FONT_SYSFIXED); | 921 | lcd_setfont(FONT_SYSFIXED); |
@@ -934,19 +934,28 @@ static bool view_battery(void) | |||
934 | if (power_history[i] < minv) | 934 | if (power_history[i] < minv) |
935 | minv = power_history[i]; | 935 | minv = power_history[i]; |
936 | } | 936 | } |
937 | 937 | /* print header */ | |
938 | #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) | ||
938 | /* adjust grid scale */ | 939 | /* adjust grid scale */ |
939 | if ((maxv - minv) > 50) | 940 | if ((maxv - minv) > 50) |
940 | grid = 50; | 941 | grid = 50; |
941 | else | 942 | else |
942 | grid = 5; | 943 | grid = 5; |
943 | 944 | ||
944 | /* print header */ | ||
945 | lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000, | 945 | lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000, |
946 | power_history[0] % 1000); | 946 | power_history[0] % 1000); |
947 | lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)", | 947 | lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)", |
948 | minv / 1000, minv % 1000, maxv / 1000, maxv % 1000, | 948 | minv / 1000, minv % 1000, maxv / 1000, maxv % 1000, |
949 | grid); | 949 | grid); |
950 | #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) | ||
951 | /* adjust grid scale */ | ||
952 | if ((maxv - minv) > 10) | ||
953 | grid = 10; | ||
954 | else | ||
955 | grid = 1; | ||
956 | lcd_putsf(0, 0, "battery %d%%", power_history[0]); | ||
957 | lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid); | ||
958 | #endif | ||
950 | 959 | ||
951 | i = 1; | 960 | i = 1; |
952 | while ((y = (minv - (minv % grid)+i*grid)) < maxv) | 961 | while ((y = (minv - (minv % grid)+i*grid)) < maxv) |
@@ -971,11 +980,11 @@ static bool view_battery(void) | |||
971 | { | 980 | { |
972 | y1 = (power_history[i] - minv) * BAT_YSPACE / | 981 | y1 = (power_history[i] - minv) * BAT_YSPACE / |
973 | (maxv - minv); | 982 | (maxv - minv); |
974 | y1 = MIN(MAX(LCD_HEIGHT-1 - y1, 20), | 983 | y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE), |
975 | LCD_HEIGHT-1); | 984 | LCD_HEIGHT-1); |
976 | y2 = (power_history[i-1] - minv) * BAT_YSPACE / | 985 | y2 = (power_history[i-1] - minv) * BAT_YSPACE / |
977 | (maxv - minv); | 986 | (maxv - minv); |
978 | y2 = MIN(MAX(LCD_HEIGHT-1 - y2, 20), | 987 | y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE), |
979 | LCD_HEIGHT-1); | 988 | LCD_HEIGHT-1); |
980 | 989 | ||
981 | lcd_set_drawmode(DRMODE_SOLID); | 990 | lcd_set_drawmode(DRMODE_SOLID); |
@@ -999,10 +1008,13 @@ static bool view_battery(void) | |||
999 | lcd_putsf(0, 0, "Pwr status: %s", | 1008 | lcd_putsf(0, 0, "Pwr status: %s", |
1000 | charging_state() ? "charging" : "discharging"); | 1009 | charging_state() ? "charging" : "discharging"); |
1001 | #else | 1010 | #else |
1002 | lcd_puts(0, 0, "Power status:"); | 1011 | lcd_puts(0, 0, "Power status: unknown"); |
1003 | #endif | 1012 | #endif |
1004 | battery_read_info(&y, NULL); | 1013 | battery_read_info(&y, &z); |
1005 | lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000); | 1014 | if (y > 0) |
1015 | lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z); | ||
1016 | else if (z > 0) | ||
1017 | lcd_putsf(0, 1, "Battery: %d %%", z); | ||
1006 | #ifdef ADC_EXT_POWER | 1018 | #ifdef ADC_EXT_POWER |
1007 | y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000; | 1019 | y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000; |
1008 | lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000); | 1020 | lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000); |
@@ -1169,16 +1181,23 @@ static bool view_battery(void) | |||
1169 | #endif /* target type */ | 1181 | #endif /* target type */ |
1170 | #endif /* CONFIG_CHARGING */ | 1182 | #endif /* CONFIG_CHARGING */ |
1171 | break; | 1183 | break; |
1172 | |||
1173 | case 2: /* voltage deltas: */ | 1184 | case 2: /* voltage deltas: */ |
1185 | #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) | ||
1174 | lcd_puts(0, 0, "Voltage deltas:"); | 1186 | lcd_puts(0, 0, "Voltage deltas:"); |
1175 | 1187 | for (i = 0; i < POWER_HISTORY_LEN-1; i++) { | |
1176 | for (i = 0; i <= 6; i++) { | ||
1177 | y = power_history[i] - power_history[i+1]; | 1188 | y = power_history[i] - power_history[i+1]; |
1178 | lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i, | 1189 | lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i, |
1179 | (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000, | 1190 | (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000, |
1180 | ((y < 0) ? y * -1 : y ) % 1000); | 1191 | ((y < 0) ? y * -1 : y ) % 1000); |
1181 | } | 1192 | } |
1193 | #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) | ||
1194 | lcd_puts(0, 0, "Percentage deltas:"); | ||
1195 | for (i = 0; i < POWER_HISTORY_LEN-1; i++) { | ||
1196 | y = power_history[i] - power_history[i+1]; | ||
1197 | lcd_putsf(0, i+1, "-%d min: %c%d%%", i, | ||
1198 | (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y)); | ||
1199 | } | ||
1200 | #endif | ||
1182 | break; | 1201 | break; |
1183 | 1202 | ||
1184 | case 3: /* remaining time estimation: */ | 1203 | case 3: /* remaining time estimation: */ |
@@ -1195,13 +1214,19 @@ static bool view_battery(void) | |||
1195 | lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec); | 1214 | lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec); |
1196 | #endif /* ARCHOS_RECORDER */ | 1215 | #endif /* ARCHOS_RECORDER */ |
1197 | 1216 | ||
1217 | #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) | ||
1198 | lcd_putsf(0, 5, "Last PwrHist: %d.%03dV", | 1218 | lcd_putsf(0, 5, "Last PwrHist: %d.%03dV", |
1199 | power_history[0] / 1000, | 1219 | power_history[0] / 1000, |
1200 | power_history[0] % 1000); | 1220 | power_history[0] % 1000); |
1221 | #endif | ||
1201 | 1222 | ||
1202 | lcd_putsf(0, 6, "battery level: %d%%", battery_level()); | 1223 | lcd_putsf(0, 6, "battery level: %d%%", battery_level()); |
1203 | 1224 | ||
1204 | lcd_putsf(0, 7, "Est. remain: %d m", battery_time()); | 1225 | int time_left = battery_time(); |
1226 | if (time_left >= 0) | ||
1227 | lcd_putsf(0, 7, "Est. remain: %d m", time_left); | ||
1228 | else | ||
1229 | lcd_puts(0, 7, "Estimation n/a"); | ||
1205 | break; | 1230 | break; |
1206 | } | 1231 | } |
1207 | 1232 | ||
@@ -1228,8 +1253,7 @@ static bool view_battery(void) | |||
1228 | return false; | 1253 | return false; |
1229 | } | 1254 | } |
1230 | 1255 | ||
1231 | #endif /* HAVE_LCD_BITMAP */ | 1256 | #endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */ |
1232 | #endif | ||
1233 | 1257 | ||
1234 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | 1258 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) |
1235 | #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) | 1259 | #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) |
@@ -2168,7 +2192,7 @@ static const struct the_menu_item menuitems[] = { | |||
2168 | { "View CPU stats", dbg_cpuinfo }, | 2192 | { "View CPU stats", dbg_cpuinfo }, |
2169 | #endif | 2193 | #endif |
2170 | #ifdef HAVE_LCD_BITMAP | 2194 | #ifdef HAVE_LCD_BITMAP |
2171 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) | 2195 | #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR) |
2172 | { "View battery", view_battery }, | 2196 | { "View battery", view_battery }, |
2173 | #endif | 2197 | #endif |
2174 | #ifndef APPLICATION | 2198 | #ifndef APPLICATION |