Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/bat_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void Charger::discharge_control(BatConf *bat_conf)
}

// simple SOH estimation
soh = usable_capacity / bat_conf->nominal_capacity;
soh = 100.0F * usable_capacity / bat_conf->nominal_capacity;
}
}
else {
Expand Down
15 changes: 15 additions & 0 deletions tests/src/tests_bat_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ void no_soc_below_0()
TEST_ASSERT(0);
}

void battery_health_is_reported_as_percentage()
{
init_structs();
charger.empty = false;
charger.usable_capacity = 0.0F;
charger.discharged_Ah = 80.0F;
load.error_flags = ERR_LOAD_SHEDDING;
charger.discharge_control(&bat_conf);
TEST_ASSERT_EQUAL(80, charger.soh);
load.error_flags = 0;
charger.empty = false;
}

int bat_charger_tests()
{
UNITY_BEGIN();
Expand Down Expand Up @@ -323,6 +336,8 @@ int bat_charger_tests()
// TODO: temperature compensation
// TODO: current compensation

RUN_TEST(battery_health_is_reported_as_percentage);

RUN_TEST(stop_discharge_at_low_voltage);
RUN_TEST(stop_discharge_at_overtemp);
RUN_TEST(stop_discharge_at_undertemp);
Expand Down