From 1f8f1a612ada74ef66abafe0a9a1f30e4664eac4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 10 Feb 2018 14:02:48 +0300 Subject: [PATCH] progress #568 --- firmware/controllers/map_averaging.cpp | 26 +++++++++++++++----------- firmware/rusefi.cpp | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index 1d9a9128f6..3e94bffa87 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -180,18 +180,22 @@ static void endAveraging(void *arg) { isAveraging = false; // with locking we would have a consistent state #if EFI_PROD_CODE || defined(__DOXYGEN__) - v_averagedMapValue = adcToVoltsDivided(mapAdcAccumulator / mapMeasurementsCounter); - // todo: move out of locked context? - averagedMapRunningBuffer[averagedMapBufIdx] = getMapByVoltage(v_averagedMapValue); - // increment circular running buffer index - averagedMapBufIdx = (averagedMapBufIdx + 1) % mapMinBufferLength; - // find min. value (only works for pressure values, not raw voltages!) - float minPressure = averagedMapRunningBuffer[0]; - for (int i = 1; i < mapMinBufferLength; i++) { - if (averagedMapRunningBuffer[i] < minPressure) - minPressure = averagedMapRunningBuffer[i]; + if (mapMeasurementsCounter > 0) { + v_averagedMapValue = adcToVoltsDivided(mapAdcAccumulator / mapMeasurementsCounter); + // todo: move out of locked context? + averagedMapRunningBuffer[averagedMapBufIdx] = getMapByVoltage(v_averagedMapValue); + // increment circular running buffer index + averagedMapBufIdx = (averagedMapBufIdx + 1) % mapMinBufferLength; + // find min. value (only works for pressure values, not raw voltages!) + float minPressure = averagedMapRunningBuffer[0]; + for (int i = 1; i < mapMinBufferLength; i++) { + if (averagedMapRunningBuffer[i] < minPressure) + minPressure = averagedMapRunningBuffer[i]; + } + currentPressure = minPressure; + } else { + warning(CUSTOM_ERR_6548, "No MAP values"); } - currentPressure = minPressure; #endif if (!wasLocked) unlockAnyContext(); diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 52189cbea0..4b61b91268 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -276,5 +276,5 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20180207; + return 20180210; }