mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-24 07:28:34 +00:00
fix(core): fix soc limit during battery initialization
[no changelog]
This commit is contained in:
parent
e33d1938e6
commit
d6e0a02ac7
@ -41,6 +41,8 @@ void fuel_gauge_reset(fuel_gauge_state_t* state) {
|
||||
}
|
||||
|
||||
void fuel_gauge_set_soc(fuel_gauge_state_t* state, float soc, float P) {
|
||||
soc = fmaxf(0.0f, fminf(soc, 1.0f)); // Clamp SOC to [0, 1]
|
||||
|
||||
// Set SOC directly
|
||||
state->soc = soc;
|
||||
state->soc_latched = soc;
|
||||
@ -55,8 +57,9 @@ void fuel_gauge_initial_guess(fuel_gauge_state_t* state, float voltage_V,
|
||||
// Calculate OCV from terminal voltage and current
|
||||
float ocv = battery_meas_to_ocv(voltage_V, current_mA, temperature);
|
||||
|
||||
// Get SOC from OCV using lookup
|
||||
// Extract SoC from battery model
|
||||
state->soc = battery_soc(ocv, temperature, discharging_mode);
|
||||
state->soc = fmaxf(0.0f, fminf(state->soc, 1.0f)); // Clamp SOC to [0, 1]
|
||||
state->soc_latched = state->soc;
|
||||
}
|
||||
|
||||
|
@ -99,10 +99,7 @@ void pm_monitor_power_sources(void) {
|
||||
}
|
||||
|
||||
// Ceil the float soc to user-friendly integer
|
||||
uint8_t soc_ceiled_temp = (int)(drv->fuel_gauge.soc_latched * 100 + 0.999f);
|
||||
if (soc_ceiled_temp != drv->soc_ceiled) {
|
||||
drv->soc_ceiled = soc_ceiled_temp;
|
||||
}
|
||||
drv->soc_ceiled = (uint8_t)(drv->fuel_gauge.soc_latched * 100 + 0.999f);
|
||||
|
||||
// Check battery voltage for low threshold
|
||||
if (drv->soc_ceiled <= PM_BATTERY_LOW_THRESHOLD_SOC && !drv->battery_low) {
|
||||
|
Loading…
Reference in New Issue
Block a user