summaryrefslogtreecommitdiff
path: root/uisimulator/common/powermgmt-sim.c
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/common/powermgmt-sim.c
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/common/powermgmt-sim.c')
-rw-r--r--uisimulator/common/powermgmt-sim.c60
1 files changed, 19 insertions, 41 deletions
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