summaryrefslogtreecommitdiff
path: root/uisimulator/common/powermgmt-sim.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/common/powermgmt-sim.c')
-rw-r--r--uisimulator/common/powermgmt-sim.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c
index 511648bc9d..5d669bcae2 100644
--- a/uisimulator/common/powermgmt-sim.c
+++ b/uisimulator/common/powermgmt-sim.c
@@ -39,9 +39,10 @@
39#define POWER_AFTER_CHARGE_TICKS (8 * HZ) 39#define POWER_AFTER_CHARGE_TICKS (8 * HZ)
40#endif 40#endif
41 41
42extern int battery_percent;
43static bool charging = false; 42static bool charging = false;
44static unsigned int battery_millivolts = BATT_MAXMVOLT; 43static unsigned int batt_millivolts = BATT_MAXMVOLT;
44static unsigned int batt_percent = 100;
45static unsigned int batt_runtime = BATT_MAXRUNTIME;
45 46
46void powermgmt_init_target(void) {} 47void powermgmt_init_target(void) {}
47 48
@@ -54,7 +55,7 @@ static void battery_status_update(void)
54 static unsigned int ext_power_until_tick = 0; 55 static unsigned int ext_power_until_tick = 0;
55#endif 56#endif
56 57
57 if TIME_BEFORE(current_tick, update_after_tick) 58 if(TIME_BEFORE(current_tick, update_after_tick))
58 return; 59 return;
59 60
60 update_after_tick = current_tick + HZ; 61 update_after_tick = current_tick + HZ;
@@ -72,10 +73,9 @@ static void battery_status_update(void)
72#endif 73#endif
73 74
74 if (charging) { 75 if (charging) {
75 battery_millivolts += BATT_CHARGE_STEP; 76 batt_millivolts += BATT_CHARGE_STEP;
76 if (battery_millivolts >= BATT_MAXMVOLT) { 77 if (batt_millivolts >= BATT_MAXMVOLT) {
77 charging = false; 78 charging = false;
78 battery_percent = 100;
79#if CONFIG_CHARGING >= CHARGING_MONITOR 79#if CONFIG_CHARGING >= CHARGING_MONITOR
80 /* Keep external power until tick */ 80 /* Keep external power until tick */
81 ext_power_until_tick = current_tick + POWER_AFTER_CHARGE_TICKS; 81 ext_power_until_tick = current_tick + POWER_AFTER_CHARGE_TICKS;
@@ -83,23 +83,20 @@ static void battery_status_update(void)
83 /* Pretend the charger was disconnected */ 83 /* Pretend the charger was disconnected */
84 charger_input_state = CHARGER_UNPLUGGED; 84 charger_input_state = CHARGER_UNPLUGGED;
85#endif 85#endif
86 return;
87 } 86 }
88 } else { 87 } else {
89 battery_millivolts -= BATT_DISCHARGE_STEP; 88 batt_millivolts -= BATT_DISCHARGE_STEP;
90 if (battery_millivolts <= BATT_MINMVOLT) { 89 if (batt_millivolts <= BATT_MINMVOLT) {
91 charging = true; 90 charging = true;
92 battery_percent = 0;
93#if CONFIG_CHARGING 91#if CONFIG_CHARGING
94 /* Pretend the charger was connected */ 92 /* Pretend the charger was connected */
95 charger_input_state = CHARGER_PLUGGED; 93 charger_input_state = CHARGER_PLUGGED;
96#endif 94#endif
97 return;
98 } 95 }
99 } 96 }
100 97
101 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) / 98 batt_percent = (batt_millivolts - BATT_MINMVOLT) / (BATT_MAXMVOLT - BATT_MINMVOLT);
102 (BATT_MAXMVOLT - BATT_MINMVOLT); 99 batt_runtime = batt_percent * BATT_MAXRUNTIME;
103} 100}
104 101
105const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { 3200 }; 102const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { 3200 };
@@ -111,15 +108,28 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
111const unsigned short percent_to_volt_charge[11] = 108const unsigned short percent_to_volt_charge[11] =
112{ 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 }; 109{ 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 };
113 110
111#if CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE
114int _battery_voltage(void) 112int _battery_voltage(void)
115{ 113{
116 battery_status_update(); 114 battery_status_update();
117 return battery_millivolts; 115 return batt_millivolts;
118} 116}
117#endif
118
119#if CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE
120int _battery_level(void)
121{
122 battery_status_update();
123 return batt_percent;
124}
125#endif
119 126
120#if (CONFIG_BATTERY_MEASURE & TIME_MEASURE) 127#if (CONFIG_BATTERY_MEASURE & TIME_MEASURE)
121static int powermgmt_est_runningtime_min; 128int _battery_time(void)
122int _battery_time(void) { return powermgmt_est_runningtime_min; } 129{
130 battery_status_update();
131 return batt_runtime;
132}
123#endif 133#endif
124 134
125#if CONFIG_CHARGING 135#if CONFIG_CHARGING
@@ -169,6 +179,7 @@ unsigned int input_millivolts(void)
169 /* Just return a safe value if battery isn't connected */ 179 /* Just return a safe value if battery isn't connected */
170 return 4050; 180 return 4050;
171 } 181 }
172 return battery_voltage();; 182
183 return battery_voltage();
173} 184}
174#endif 185#endif