From b75d340bb47f7a0065be63163a97152c82a99ffe Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Sat, 8 Jun 2019 18:47:25 +1000 Subject: [PATCH] Fix negative gvars precision (#6321) Fix negative gvars precision --- radio/src/gvars.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/radio/src/gvars.cpp b/radio/src/gvars.cpp index ee9c1a939..303dc6207 100644 --- a/radio/src/gvars.cpp +++ b/radio/src/gvars.cpp @@ -73,18 +73,12 @@ int16_t getGVarValue(int8_t gv, int8_t fm) int32_t getGVarValuePrec1(int8_t gv, int8_t fm) { - int8_t mul; - uint8_t prec = g_model.gvars[abs((int)gv)].prec; // explicit cast to `int` needed, othervise gv is promoted to double! - if (prec == 0) - mul = 10; - else - mul = 1; - + int8_t idx = (gv >= 0 ? gv : -gv - 1); + int8_t mul = (g_model.gvars[idx].prec == 0 ? 10 : 1); // explicit cast to `int` needed, othervise gv is promoted to double! if (gv < 0) { - gv = -1-gv; mul = -mul; } - return GVAR_VALUE(gv, getGVarFlightMode(fm, gv)) * mul; + return GVAR_VALUE(idx, getGVarFlightMode(fm, idx)) * mul; } void setGVarValue(uint8_t gv, int16_t value, int8_t fm) -- 2.11.4.GIT