From 823a5ea3adf78c71daa2765bb8ced7d849d1fd9e Mon Sep 17 00:00:00 2001 From: Zeiberstein Date: Tue, 6 Jul 2021 00:55:27 +0200 Subject: [PATCH] Update table.ino (#585) Simplify interpolation for table2D data. --- speeduino/table.ino | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/speeduino/table.ino b/speeduino/table.ino index 8c6cfeba..e03c7849 100644 --- a/speeduino/table.ino +++ b/speeduino/table.ino @@ -160,19 +160,13 @@ int table2D_getValue(struct table2D *fromTable, int X_in) int16_t yMax = table2D_getRawValue(fromTable, xMax); int16_t yMin = table2D_getRawValue(fromTable, xMin); - //Float version - /* - int yVal = (m / n) * (abs(yMax - yMin)); + /* Float version (if m, yMax, yMin and n were float's) + int yVal = (m * (yMax - yMin)) / n; */ - + //Non-Float version - int16_t yVal = ((long)(m << 6) / n) * (abs(yMax - yMin)); - yVal = (yVal >> 6); - - if (yMax > yMin) { yVal = yMin + yVal; } - else { yVal = yMin - yVal; } - - returnValue = yVal; + int16_t yVal = ( ((int32_t) m) * (yMax-yMin) ) / n; + returnValue = yMin + yVal; } fromTable->lastInput = X_in;