From c1bd9b0361ba92c29ceef68d74093e70a1a3e481 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Tue, 3 Jan 2012 23:44:38 +0000 Subject: 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 --- uisimulator/common/powermgmt-sim.c | 60 ++++++++++++-------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) (limited to 'uisimulator/common/powermgmt-sim.c') 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 @@ #include #include "kernel.h" #include "powermgmt.h" +#include "power.h" -#define BATT_MINMVOLT 2500 /* minimum millivolts of battery */ -#define BATT_MAXMVOLT 4500 /* maximum millivolts of battery */ +#define BATT_MINMVOLT 3300 /* minimum millivolts of battery */ +#define BATT_MAXMVOLT 4300 /* maximum millivolts of battery */ #define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in minutes */ extern void send_battery_level_event(void); extern int last_sent_battery_level; extern int battery_percent; +static bool charging = false; static unsigned int battery_millivolts = BATT_MAXMVOLT; -/* estimated remaining time in minutes */ -static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME; + +void powermgmt_init_target(void) {} static void battery_status_update(void) { static time_t last_change = 0; - static bool charging = false; time_t now; time(&now); @@ -76,57 +77,34 @@ static void battery_status_update(void) battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) / (BATT_MAXMVOLT - BATT_MINMVOLT); - - powermgmt_est_runningtime_min = - battery_percent * BATT_MAXRUNTIME / 100; } - - send_battery_level_event(); } -void battery_read_info(int *voltage, int *level) -{ - battery_status_update(); +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { 3200 }; +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = { 3200 }; - if (voltage) - *voltage = battery_millivolts; +/* make the simulated curve nicely linear */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ { 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 } }; +const unsigned short percent_to_volt_charge[11] = +{ 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 }; - if (level) - *level = battery_percent; -} -unsigned int battery_voltage(void) +int _battery_voltage(void) { battery_status_update(); return battery_millivolts; } -int battery_level(void) -{ - battery_status_update(); - return battery_percent; -} - -int battery_time(void) -{ - battery_status_update(); - return powermgmt_est_runningtime_min; -} - -bool battery_level_safe(void) -{ - return battery_level() >= 10; -} - -void set_battery_capacity(int capacity) +#if CONFIG_CHARGING +unsigned int power_input_status(void) { - (void)capacity; + return charging ? POWER_INPUT_NONE : POWER_INPUT_MAIN; } -#if BATTERY_TYPES_COUNT > 1 -void set_battery_type(int type) +bool charging_state(void) { - (void)type; + return charging; } #endif -- cgit v1.2.3