diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/powermgmt.c | 18 | ||||
-rw-r--r-- | firmware/powermgmt.h | 2 |
2 files changed, 13 insertions, 7 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 7f89434198..a05c54f8a3 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -79,12 +79,18 @@ int powermgmt_last_cycle_level = 0; /* which level had the batteries at | |||
79 | bool trickle_charge_enabled = true; | 79 | bool trickle_charge_enabled = true; |
80 | int trickle_sec = 0; /* how many seconds should the charger be enabled per minute for trickle charging? */ | 80 | int trickle_sec = 0; /* how many seconds should the charger be enabled per minute for trickle charging? */ |
81 | int charge_state = 0; /* at the beginning, the charger does nothing */ | 81 | int charge_state = 0; /* at the beginning, the charger does nothing */ |
82 | int battery_capacity = 1800; /* only a default value */ | ||
82 | 83 | ||
83 | static int percent_to_volt_charge[11] = /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ | 84 | static int percent_to_volt_charge[11] = /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ |
84 | { | 85 | { |
85 | 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 | 86 | 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 |
86 | }; | 87 | }; |
87 | 88 | ||
89 | void set_battery_capacity(int capacity) | ||
90 | { | ||
91 | battery_capacity = capacity; | ||
92 | } | ||
93 | |||
88 | void enable_trickle_charge(bool on) | 94 | void enable_trickle_charge(bool on) |
89 | { | 95 | { |
90 | trickle_charge_enabled = on; | 96 | trickle_charge_enabled = on; |
@@ -345,22 +351,22 @@ static void power_thread(void) | |||
345 | /* so consider it because there's the battery lazyness inside the the battery_level */ | 351 | /* so consider it because there's the battery lazyness inside the the battery_level */ |
346 | if (powermgmt_last_cycle_startstop_min < 20) { | 352 | if (powermgmt_last_cycle_startstop_min < 20) { |
347 | i = (100 - battery_lazyness[powermgmt_last_cycle_startstop_min]) * 30 / 100 ; /* 0..30 */ | 353 | i = (100 - battery_lazyness[powermgmt_last_cycle_startstop_min]) * 30 / 100 ; /* 0..30 */ |
348 | powermgmt_est_runningtime_min = (100 - battery_level()) * BATTERY_CAPACITY / 100 * (100 + i) / 100 * 60 / CURRENT_CHARGING; | 354 | powermgmt_est_runningtime_min = (100 - battery_level()) * battery_capacity / 100 * (100 + i) / 100 * 60 / CURRENT_CHARGING; |
349 | } else { | 355 | } else { |
350 | powermgmt_est_runningtime_min = (100 - battery_level()) * BATTERY_CAPACITY / 100 * 60 / CURRENT_CHARGING; | 356 | powermgmt_est_runningtime_min = (100 - battery_level()) * battery_capacity / 100 * 60 / CURRENT_CHARGING; |
351 | } | 357 | } |
352 | else { | 358 | else { |
353 | current = CURRENT_NORMAL; | 359 | current = CURRENT_NORMAL; |
354 | if ((backlight_get_timeout() == 1) || (charger_inserted() && backlight_get_on_when_charging())) | 360 | if ((backlight_get_timeout() == 1) || (charger_inserted() && backlight_get_on_when_charging())) |
355 | /* LED always on or LED on when charger connected */ | 361 | /* LED always on or LED on when charger connected */ |
356 | current += CURRENT_BACKLIGHT; | 362 | current += CURRENT_BACKLIGHT; |
357 | powermgmt_est_runningtime_min = battery_level() * BATTERY_CAPACITY / 100 * 60 / current; | 363 | powermgmt_est_runningtime_min = battery_level() * battery_capacity / 100 * 60 / current; |
358 | } | 364 | } |
359 | #else | 365 | #else |
360 | current = CURRENT_NORMAL; | 366 | current = CURRENT_NORMAL; |
361 | if (backlight_get_timeout() == 1) /* LED always on */ | 367 | if (backlight_get_timeout() == 1) /* LED always on */ |
362 | current += CURRENT_BACKLIGHT; | 368 | current += CURRENT_BACKLIGHT; |
363 | powermgmt_est_runningtime_min = battery_level() * BATTERY_CAPACITY / 100 * 60 / current; | 369 | powermgmt_est_runningtime_min = battery_level() * battery_capacity / 100 * 60 / current; |
364 | #endif | 370 | #endif |
365 | 371 | ||
366 | #ifdef HAVE_CHARGE_CTRL | 372 | #ifdef HAVE_CHARGE_CTRL |
@@ -479,7 +485,7 @@ static void power_thread(void) | |||
479 | } else { | 485 | } else { |
480 | /* calculate max charge time depending on current battery level */ | 486 | /* calculate max charge time depending on current battery level */ |
481 | /* take 35% more because battery level is not linear */ | 487 | /* take 35% more because battery level is not linear */ |
482 | i = CHARGE_MAX_TIME_1500 * BATTERY_CAPACITY / 1500; | 488 | i = CHARGE_MAX_TIME_1500 * battery_capacity / 1500; |
483 | charge_max_time_now = i * (100 + 35 - battery_level()) / 100; | 489 | charge_max_time_now = i * (100 + 35 - battery_level()) / 100; |
484 | if (charge_max_time_now > i) { | 490 | if (charge_max_time_now > i) { |
485 | charge_max_time_now = i; | 491 | charge_max_time_now = i; |
@@ -542,7 +548,7 @@ void power_init(void) | |||
542 | flickering during the first minute of execution */ | 548 | flickering during the first minute of execution */ |
543 | power_history[POWER_HISTORY_LEN-1] = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | 549 | power_history[POWER_HISTORY_LEN-1] = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; |
544 | /* calculate the remaining time to that the info screen displays something useful */ | 550 | /* calculate the remaining time to that the info screen displays something useful */ |
545 | powermgmt_est_runningtime_min = battery_level() * BATTERY_CAPACITY / 100 * 60 / CURRENT_NORMAL; | 551 | powermgmt_est_runningtime_min = battery_level() * battery_capacity / 100 * 60 / CURRENT_NORMAL; |
546 | 552 | ||
547 | #ifdef HAVE_CHARGE_CTRL | 553 | #ifdef HAVE_CHARGE_CTRL |
548 | snprintf(power_message, POWER_MESSAGE_LEN, "Powermgmt started"); | 554 | snprintf(power_message, POWER_MESSAGE_LEN, "Powermgmt started"); |
diff --git a/firmware/powermgmt.h b/firmware/powermgmt.h index dbecc12d44..ee2c513181 100644 --- a/firmware/powermgmt.h +++ b/firmware/powermgmt.h | |||
@@ -59,12 +59,12 @@ extern int powermgmt_last_cycle_level; /* which level had the batteries | |||
59 | 59 | ||
60 | extern int battery_lazyness[20]; /* how does the battery react when plugging in/out the charger */ | 60 | extern int battery_lazyness[20]; /* how does the battery react when plugging in/out the charger */ |
61 | void enable_trickle_charge(bool on); | 61 | void enable_trickle_charge(bool on); |
62 | void set_battery_capacity(int capacity); /* set local battery capacity value */ | ||
62 | extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ | 63 | extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ |
63 | extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | 64 | extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ |
64 | 65 | ||
65 | #endif /* HAVE_CHARGE_CTRL */ | 66 | #endif /* HAVE_CHARGE_CTRL */ |
66 | 67 | ||
67 | #define BATTERY_CAPACITY 1800 /* battery capacity in mAh for runtime estimation */ | ||
68 | #define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */ | 68 | #define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */ |
69 | #define CURRENT_BACKLIGHT 30 /* additional current when backlight is always on */ | 69 | #define CURRENT_BACKLIGHT 30 /* additional current when backlight is always on */ |
70 | #define CURRENT_CHARGING 300 /* charging current */ | 70 | #define CURRENT_CHARGING 300 /* charging current */ |