From c64ad25109427cdc22ca6f7c4c82a5aebe1ecf26 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:17:12 +0100 Subject: [PATCH 1/4] Remove blocking delay from batteryUpdate initialization --- src/main/sensors/battery.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index a29fa2e07cf..6af2e886061 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -351,16 +351,24 @@ static void checkBatteryCapacityState(void) void batteryUpdate(timeUs_t timeDelta) { + static timeUs_t batteryConnectedTime = 0; /* battery has just been connected*/ if (batteryState == BATTERY_NOT_PRESENT && vbat > VBATT_PRESENT_THRESHOLD) { + if(batteryConnectedTime == 0) { + batteryConnectedTime = micros(); + return; + } - /* Actual battery state is calculated below, this is really BATTERY_PRESENT */ - batteryState = BATTERY_OK; /* wait for VBatt to stabilise then we can calc number of cells (using the filtered value takes a long time to ramp up) We only do this on the ground so don't care if we do block, not worse than original code anyway*/ - delay(VBATT_STABLE_DELAY); + if((micros() - batteryConnectedTime) < VBATT_STABLE_DELAY) { + return; + } + + /* Actual battery state is calculated below, this is really BATTERY_PRESENT */ + batteryState = BATTERY_OK; updateBatteryVoltage(timeDelta, true); int8_t detectedProfileIndex = -1; From fbd1ed5be6ff7a616a5c504917d85b11aeaa184f Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sat, 18 Jan 2025 14:03:56 +0100 Subject: [PATCH 2/4] Cover scenario when battery is unplugged, but fc is still powered. --- src/main/sensors/battery.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 6af2e886061..e6b07fe8732 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -404,6 +404,7 @@ void batteryUpdate(timeUs_t timeDelta) /* battery has been disconnected - can take a while for filter cap to disharge so we use a threshold of VBATT_PRESENT_THRESHOLD */ if (batteryState != BATTERY_NOT_PRESENT && vbat <= VBATT_PRESENT_THRESHOLD) { batteryState = BATTERY_NOT_PRESENT; + batteryConnectedTime = 0; batteryCellCount = 0; batteryWarningVoltage = 0; batteryCriticalVoltage = 0; From 62efa65b4f35087f3124a8fc57fc5782499063e6 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sat, 18 Jan 2025 08:11:08 -0500 Subject: [PATCH 3/4] Update battery.c --- src/main/sensors/battery.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index e6b07fe8732..fdf10920e7d 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -361,8 +361,7 @@ void batteryUpdate(timeUs_t timeDelta) /* wait for VBatt to stabilise then we can calc number of cells (using the filtered value takes a long time to ramp up) - We only do this on the ground so don't care if we do block, not - worse than original code anyway*/ + Blocking can cause issues with som ESCs */ if((micros() - batteryConnectedTime) < VBATT_STABLE_DELAY) { return; } From 6e0674248c28d074384217f31b3540678b1bd8ea Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sat, 18 Jan 2025 08:12:19 -0500 Subject: [PATCH 4/4] Update battery.c --- src/main/sensors/battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index fdf10920e7d..e9167e09120 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -361,7 +361,7 @@ void batteryUpdate(timeUs_t timeDelta) /* wait for VBatt to stabilise then we can calc number of cells (using the filtered value takes a long time to ramp up) - Blocking can cause issues with som ESCs */ + Blocking can cause issues with some ESCs */ if((micros() - batteryConnectedTime) < VBATT_STABLE_DELAY) { return; }