From 5862b5bba5346408cb63525e34705b46e437d594 Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Sat, 28 Sep 2024 18:32:16 +0200 Subject: [PATCH 1/2] Fix default value for discharge current limit If the default type is an int, setting to a fractional value is not possible. Presumably this is because in `target.DischargeCurrentLimit = source["discharge_current_limit"] | BATTERY_DISCHARGE_CURRENT_LIMIT;` the JSON library uses the default to force the expected type and on type mismatch the default is used. As per https://arduinojson.org/v7/api/jsonvariant/or/: `defaultValue: the value to return if the JsonVariant is null or incompatible with the requested type.` --- include/defaults.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/defaults.h b/include/defaults.h index 67b1d122e..2ab8ec9e8 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -155,7 +155,7 @@ #define BATTERY_JKBMS_INTERFACE 0 #define BATTERY_JKBMS_POLLING_INTERVAL 5 #define BATTERY_ENABLE_DISCHARGE_CURRENT_LIMIT false -#define BATTERY_DISCHARGE_CURRENT_LIMIT 0 +#define BATTERY_DISCHARGE_CURRENT_LIMIT 0.0 #define BATTERY_USE_BATTERY_REPORTED_DISCHARGE_CURRENT_LIMIT false #define HUAWEI_ENABLED false From 878d1fd26f1def5edcde893ec5cb8df105a19845 Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Sat, 28 Sep 2024 21:41:34 +0200 Subject: [PATCH 2/2] Fix typo in Battery.cpp When the limit is valid, use the actual configured limit, not the bool value :) --- src/Battery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Battery.cpp b/src/Battery.cpp index e10abb1fa..7483c1de4 100644 --- a/src/Battery.cpp +++ b/src/Battery.cpp @@ -108,7 +108,7 @@ float BatteryClass::getDischargeCurrentLimit() } if (dischargeCurrentValid) { - return dischargeCurrentValid; + return dischargeCurrentLimit; } return FLT_MAX;