summaryrefslogtreecommitdiff
path: root/uisimulator
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-01-03 23:44:38 +0000
committerThomas Martitz <kugel@rockbox.org>2012-01-03 23:44:38 +0000
commitc1bd9b0361ba92c29ceef68d74093e70a1a3e481 (patch)
tree1a42acdf2099b7f5ac06eee11e1d488b388c6d9f /uisimulator
parent949e6398c89e3c277a4c542f67a5ee788c6f642d (diff)
downloadrockbox-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 'uisimulator')
-rw-r--r--uisimulator/common/SOURCES5
-rw-r--r--uisimulator/common/lcd-common.c6
-rw-r--r--uisimulator/common/powermgmt-sim.c60
-rw-r--r--uisimulator/common/stubs.c26
4 files changed, 26 insertions, 71 deletions
diff --git a/uisimulator/common/SOURCES b/uisimulator/common/SOURCES
index a632706a6b..939f1638c3 100644
--- a/uisimulator/common/SOURCES
+++ b/uisimulator/common/SOURCES
@@ -9,10 +9,7 @@ sim_tasks.c
9fmradio.c 9fmradio.c
10backlight-sim.c 10backlight-sim.c
11stubs.c 11stubs.c
12powermgmt-sim.c
12#endif 13#endif
13 14
14io.c 15io.c
15/* this is still needed for application since it has some stubs */
16#if !(CONFIG_PLATFORM & PLATFORM_MAEMO)
17powermgmt-sim.c
18#endif
diff --git a/uisimulator/common/lcd-common.c b/uisimulator/common/lcd-common.c
index 2acf4b386d..47ca114cbc 100644
--- a/uisimulator/common/lcd-common.c
+++ b/uisimulator/common/lcd-common.c
@@ -119,3 +119,9 @@ bool lcd_active(void)
119 return retval; 119 return retval;
120} 120}
121#endif 121#endif
122
123#ifdef HAVE_LCD_SHUTDOWN
124void lcd_shutdown(void)
125{
126}
127#endif
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c
index e747d7d782..2d9acab51d 100644
--- a/uisimulator/common/powermgmt-sim.c
+++ b/uisimulator/common/powermgmt-sim.c
@@ -24,24 +24,25 @@
24#include <time.h> 24#include <time.h>
25#include "kernel.h" 25#include "kernel.h"
26#include "powermgmt.h" 26#include "powermgmt.h"
27#include "power.h"
27 28
28#define BATT_MINMVOLT 2500 /* minimum millivolts of battery */ 29#define BATT_MINMVOLT 3300 /* minimum millivolts of battery */
29#define BATT_MAXMVOLT 4500 /* maximum millivolts of battery */ 30#define BATT_MAXMVOLT 4300 /* maximum millivolts of battery */
30#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in 31#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
31 minutes */ 32 minutes */
32 33
33extern void send_battery_level_event(void); 34extern void send_battery_level_event(void);
34extern int last_sent_battery_level; 35extern int last_sent_battery_level;
35extern int battery_percent; 36extern int battery_percent;
37static bool charging = false;
36 38
37static unsigned int battery_millivolts = BATT_MAXMVOLT; 39static unsigned int battery_millivolts = BATT_MAXMVOLT;
38/* estimated remaining time in minutes */ 40
39static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME; 41void powermgmt_init_target(void) {}
40 42
41static void battery_status_update(void) 43static void battery_status_update(void)
42{ 44{
43 static time_t last_change = 0; 45 static time_t last_change = 0;
44 static bool charging = false;
45 time_t now; 46 time_t now;
46 47
47 time(&now); 48 time(&now);
@@ -76,57 +77,34 @@ static void battery_status_update(void)
76 77
77 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) / 78 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
78 (BATT_MAXMVOLT - BATT_MINMVOLT); 79 (BATT_MAXMVOLT - BATT_MINMVOLT);
79
80 powermgmt_est_runningtime_min =
81 battery_percent * BATT_MAXRUNTIME / 100;
82 } 80 }
83
84 send_battery_level_event();
85} 81}
86 82
87void battery_read_info(int *voltage, int *level) 83const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { 3200 };
88{ 84const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = { 3200 };
89 battery_status_update();
90 85
91 if (voltage) 86/* make the simulated curve nicely linear */
92 *voltage = battery_millivolts; 87const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
88{ { 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 } };
89const unsigned short percent_to_volt_charge[11] =
90{ 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 };
93 91
94 if (level)
95 *level = battery_percent;
96}
97 92
98unsigned int battery_voltage(void) 93int _battery_voltage(void)
99{ 94{
100 battery_status_update(); 95 battery_status_update();
101 return battery_millivolts; 96 return battery_millivolts;
102} 97}
103 98
104int battery_level(void) 99#if CONFIG_CHARGING
105{ 100unsigned int power_input_status(void)
106 battery_status_update();
107 return battery_percent;
108}
109
110int battery_time(void)
111{
112 battery_status_update();
113 return powermgmt_est_runningtime_min;
114}
115
116bool battery_level_safe(void)
117{
118 return battery_level() >= 10;
119}
120
121void set_battery_capacity(int capacity)
122{ 101{
123 (void)capacity; 102 return charging ? POWER_INPUT_NONE : POWER_INPUT_MAIN;
124} 103}
125 104
126#if BATTERY_TYPES_COUNT > 1 105bool charging_state(void)
127void set_battery_type(int type)
128{ 106{
129 (void)type; 107 return charging;
130} 108}
131#endif 109#endif
132 110
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index f8b8fdc912..ba4faff6e2 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -317,32 +317,6 @@ bool usb_charging_enable(bool on)
317} 317}
318#endif 318#endif
319 319
320#if CONFIG_CHARGING
321bool charger_inserted(void)
322{
323 return false;
324}
325
326bool power_input_present(void)
327{
328 return false;
329}
330
331unsigned int power_input_status(void)
332{
333#ifdef HAVE_BATTERY_SWITCH
334 return POWER_INPUT_BATTERY;
335#else
336 return POWER_INPUT_NONE;
337#endif
338}
339
340bool charging_state(void)
341{
342 return false;
343}
344#endif /* CONFIG_CHARGING */
345
346#ifndef USB_NONE 320#ifndef USB_NONE
347bool usb_inserted(void) 321bool usb_inserted(void)
348{ 322{