Charger: Fix state machine startup behavior

If the device starts up with the battery voltage > bat_conf->voltage_recharge,
the charger state machine did not leave CHG_STATE_IDLE. However, the PWM solar
input still started charging the battery and stayed at bulk charging voltage
all the time.

Now we don't check the recharge limits if the CHG_STATE_IDLE was reached for
the first time, so that the state machine goes into CHG_STATE_BULK properly.

Also fixing some formatting and moving the state enum before Charger class.
This commit is contained in:
Martin Jäger
2021-06-01 17:44:10 +02:00
parent 359942f3fe
commit 9765798944
2 changed files with 136 additions and 130 deletions
+9 -4
View File
@@ -453,7 +453,8 @@ void Charger::charge_control(BatConf *bat_conf)
}
if (dev_stat.has_error(ERR_BAT_OVERVOLTAGE) &&
port->bus->voltage < (bat_conf->voltage_absolute_max - 0.5F) * port->bus->series_multiplier)
port->bus->voltage < (bat_conf->voltage_absolute_max - 0.5F) *
port->bus->series_multiplier)
{
dev_stat.clear_error(ERR_BAT_OVERVOLTAGE);
}
@@ -461,9 +462,13 @@ void Charger::charge_control(BatConf *bat_conf)
// state machine
switch (state) {
case CHG_STATE_IDLE: {
if (port->bus->voltage < port->bus->sink_control_voltage(bat_conf->voltage_recharge)
&& port->bus->voltage > port->bus->sink_control_voltage(bat_conf->voltage_absolute_min) // ToDo set error flag otherwise
&& (uptime() - time_state_changed) > bat_conf->time_limit_recharge
if ((time_state_changed == CHARGER_TIME_NEVER ||
((uptime() - time_state_changed) > bat_conf->time_limit_recharge &&
port->bus->voltage < port->bus->sink_control_voltage(
bat_conf->voltage_recharge))
)
&& port->bus->voltage > port->bus->sink_control_voltage(
bat_conf->voltage_absolute_min) // ToDo set error flag otherwise
&& bat_temperature < bat_conf->charge_temp_max - 1
&& bat_temperature > bat_conf->charge_temp_min + 1)
{