diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 26759b647d..08f0be7d5f 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -89,20 +89,21 @@ static const int poweroff_idle_timeout_value[15] = | |||
89 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 | 89 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static const int percent_to_volt_decharge[11] = | 92 | static const short percent_to_volt_decharge[BATTERY_TYPES_COUNT][11] = |
93 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */ | 93 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */ |
94 | { | 94 | { |
95 | #if CONFIG_BATTERY == BATT_LIION2200 | 95 | #if CONFIG_BATTERY == BATT_LIION2200 |
96 | /* measured values */ | 96 | /* measured values */ |
97 | 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 | 97 | { 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 } |
98 | #elif CONFIG_BATTERY == BATT_3AAA_ALKALINE | 98 | #elif CONFIG_BATTERY == BATT_3AAA |
99 | /* taken from a textbook alkaline discharge graph, not measured */ | 99 | /* measured values */ |
100 | 270, 303, 324, 336, 348, 357, 366, 378, 390, 408, 450 | 100 | { 280, 325, 341, 353, 364, 374, 385, 395, 409, 427, 475 }, /* alkaline */ |
101 | { 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */ | ||
101 | #else /* NiMH */ | 102 | #else /* NiMH */ |
102 | /* original values were taken directly after charging, but it should show | 103 | /* original values were taken directly after charging, but it should show |
103 | 100% after turning off the device for some hours, too */ | 104 | 100% after turning off the device for some hours, too */ |
104 | 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 /* orig. values: | 105 | { 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 } |
105 | ...,528,560 */ | 106 | /* orig. values: ...,528,560 */ |
106 | #endif | 107 | #endif |
107 | }; | 108 | }; |
108 | 109 | ||
@@ -115,6 +116,16 @@ void set_battery_capacity(int capacity) | |||
115 | battery_capacity = BATTERY_CAPACITY_MIN; | 116 | battery_capacity = BATTERY_CAPACITY_MIN; |
116 | } | 117 | } |
117 | 118 | ||
119 | #if BATTERY_TYPES_COUNT > 1 | ||
120 | static int battery_type = 0; | ||
121 | |||
122 | void set_battery_type(int type) | ||
123 | { | ||
124 | battery_type = type; | ||
125 | battery_level_cached = -1; /* reset on type change */ | ||
126 | } | ||
127 | #endif | ||
128 | |||
118 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 | 129 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 |
119 | int charge_state = 0; /* at the beginning, the | 130 | int charge_state = 0; /* at the beginning, the |
120 | charger does nothing */ | 131 | charger does nothing */ |
@@ -136,7 +147,7 @@ int trickle_sec = 0; /* how many seconds should the | |||
136 | charger be enabled per | 147 | charger be enabled per |
137 | minute for trickle | 148 | minute for trickle |
138 | charging? */ | 149 | charging? */ |
139 | static const int percent_to_volt_charge[11] = | 150 | static const short percent_to_volt_charge[11] = |
140 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ | 151 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ |
141 | { | 152 | { |
142 | /* values guessed, see | 153 | /* values guessed, see |
@@ -170,7 +181,7 @@ int battery_time(void) | |||
170 | 181 | ||
171 | /* look into the percent_to_volt_* table and get a realistic battery level | 182 | /* look into the percent_to_volt_* table and get a realistic battery level |
172 | percentage */ | 183 | percentage */ |
173 | int voltage_to_percent(int voltage, const int* table) | 184 | int voltage_to_percent(int voltage, const short* table) |
174 | { | 185 | { |
175 | if (voltage <= table[0]) | 186 | if (voltage <= table[0]) |
176 | return 0; | 187 | return 0; |
@@ -195,6 +206,9 @@ void battery_level_update(void) | |||
195 | int level = 0; | 206 | int level = 0; |
196 | int c = 0; | 207 | int c = 0; |
197 | int i; | 208 | int i; |
209 | #if BATTERY_TYPES_COUNT == 1 /* single type */ | ||
210 | const int battery_type = 0; | ||
211 | #endif | ||
198 | 212 | ||
199 | /* calculate maximum over last 3 minutes (skip empty samples) */ | 213 | /* calculate maximum over last 3 minutes (skip empty samples) */ |
200 | for (i = 0; i < 3; i++) | 214 | for (i = 0; i < 3; i++) |
@@ -214,7 +228,8 @@ void battery_level_update(void) | |||
214 | 228 | ||
215 | #ifdef HAVE_CHARGE_CTRL | 229 | #ifdef HAVE_CHARGE_CTRL |
216 | if (charge_state == 0) { /* decharge */ | 230 | if (charge_state == 0) { /* decharge */ |
217 | level = voltage_to_percent(level, percent_to_volt_decharge); | 231 | level = voltage_to_percent(level, |
232 | percent_to_volt_decharge[battery_type]); | ||
218 | } | 233 | } |
219 | else if (charge_state == 1) { /* charge */ | 234 | else if (charge_state == 1) { /* charge */ |
220 | level = voltage_to_percent(level, percent_to_volt_charge); | 235 | level = voltage_to_percent(level, percent_to_volt_charge); |
@@ -223,7 +238,8 @@ void battery_level_update(void) | |||
223 | battery_level_cached = level = 100; | 238 | battery_level_cached = level = 100; |
224 | } | 239 | } |
225 | #else | 240 | #else |
226 | level = voltage_to_percent(level, percent_to_volt_decharge); | 241 | level = voltage_to_percent(level, |
242 | percent_to_volt_decharge[battery_type]); | ||
227 | /* always use the decharge table */ | 243 | /* always use the decharge table */ |
228 | #endif | 244 | #endif |
229 | 245 | ||