diff options
-rwxr-xr-x | board/winky/battery.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/board/winky/battery.c b/board/winky/battery.c index 1c21042f93..a8a2b30ff7 100755 --- a/board/winky/battery.c +++ b/board/winky/battery.c @@ -70,6 +70,7 @@ DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff, static int oem_battery_state; #define OEM_BATTERY_STATE_DEFAULT 0x00 #define OEM_BATTERY_STATE_ERROR 0x01 +#define OEM_BATTERY_STATE_STOP_CHARGE 0x02 inline void board_battery_not_connected(void) { @@ -78,9 +79,26 @@ inline void board_battery_not_connected(void) void battery_override_params(struct batt_params *batt) { + int bat_temp_c = DECI_KELVIN_TO_CELSIUS(batt->temperature); int chstate = charge_get_state(); - if(oem_battery_state == OEM_BATTERY_STATE_DEFAULT) { + /* Check battery temperature */ + if((chstate == PWR_STATE_CHARGE) || + (chstate == PWR_STATE_CHARGE_NEAR_FULL)) { + if((bat_temp_c < info.charging_min_c) || + (bat_temp_c >= info.charging_max_c)) { + oem_battery_state |= OEM_BATTERY_STATE_STOP_CHARGE; + } + } else { + if((bat_temp_c < info.start_charging_min_c) || + (bat_temp_c >= info.start_charging_max_c)) { + oem_battery_state |= OEM_BATTERY_STATE_STOP_CHARGE; + } else { + oem_battery_state &= ~OEM_BATTERY_STATE_STOP_CHARGE; + } + } + + if(!(oem_battery_state & OEM_BATTERY_STATE_ERROR)) { if((chstate == PWR_STATE_CHARGE) || (chstate == PWR_STATE_CHARGE_NEAR_FULL)) { /* Check battery overvoltage */ @@ -95,5 +113,11 @@ void battery_override_params(struct batt_params *batt) batt->desired_voltage = 0; batt->desired_current = 0; } + + if(oem_battery_state & OEM_BATTERY_STATE_STOP_CHARGE) { + batt->flags &= ~BATT_FLAG_WANT_CHARGE; + batt->desired_voltage = 0; + batt->desired_current = 0; + } } #endif /* CONFIG_BATTERY_OVERRIDE_PARAMS */ |