From b06c58bb81f2476113c0bddc69d065d5ec4a973b Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 28 Apr 2021 21:05:49 +1000 Subject: [PATCH] Fix utils length calc --- source/Core/Drivers/TipThermoModel.cpp | 4 +++- source/Core/Drivers/Utils.cpp | 3 +-- source/Core/Drivers/Utils.h | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp index 57fb5dec..8f91b12e 100644 --- a/source/Core/Drivers/TipThermoModel.cpp +++ b/source/Core/Drivers/TipThermoModel.cpp @@ -216,8 +216,10 @@ const uint16_t uVtoDegC[] = { 38137, 500, // }; #endif +const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uint16_t)); + uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { - return Utils::InterpolateLookupTable(uVtoDegC,tipuVDelta); + return Utils::InterpolateLookupTable(uVtoDegC,uVtoDegCItems,tipuVDelta); } uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); } diff --git a/source/Core/Drivers/Utils.cpp b/source/Core/Drivers/Utils.cpp index 4899750f..654bb566 100644 --- a/source/Core/Drivers/Utils.cpp +++ b/source/Core/Drivers/Utils.cpp @@ -8,9 +8,8 @@ #include int32_t Utils::InterpolateLookupTable(const uint16_t *lookupTable, - const uint16_t value) { + const int noItems, const uint16_t value) { if (value) { - int noItems = sizeof(lookupTable) / (2 * sizeof(uint16_t)); for (int i = 1; i < (noItems - 1); i++) { // If current tip temp is less than current lookup, then this current lookup is the higher point to interpolate if (value < lookupTable[i * 2]) { diff --git a/source/Core/Drivers/Utils.h b/source/Core/Drivers/Utils.h index 1031f080..cc183291 100644 --- a/source/Core/Drivers/Utils.h +++ b/source/Core/Drivers/Utils.h @@ -11,9 +11,9 @@ class Utils { public: static int32_t InterpolateLookupTable(const uint16_t *lookupTable, - const uint16_t value); + const int noItems, const uint16_t value); static int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, - int32_t y2, int32_t x) ; + int32_t y2, int32_t x); };