From 41d847a94907c973ac2888347ee533ef7fb6f9e0 Mon Sep 17 00:00:00 2001 From: tauchner <7229@htl.rennweg.at> Date: Thu, 30 Jun 2022 13:06:28 +0200 Subject: [PATCH] Fixed Str2F conversion error --- airrohr-firmware/utils.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/airrohr-firmware/utils.cpp b/airrohr-firmware/utils.cpp index 20bfbcd1..ec51f7f3 100644 --- a/airrohr-firmware/utils.cpp +++ b/airrohr-firmware/utils.cpp @@ -243,9 +243,16 @@ void add_Value2Json(String& res, const __FlashStringHelper* type, const __FlashS float readCorrectionOffset(const char* correction) { char* pEnd = nullptr; // Avoiding atof() here as this adds a lot (~ 9kb) of code size + // which btw is really bad, because now we have a lot more work for everyone + // TODO: fix this mess to use fixed point float r = float(strtol(correction, &pEnd, 10)); if (pEnd && pEnd[0] == '.' && pEnd[1] >= '0' && pEnd[1] <= '9') { - r += (r >= 0.0f ? 1.0f : -1.0f) * ((pEnd[1] - '0') / 10.0f); + bool isNegative = correction[0] == '-'; + for (int i = 0; correction[i] == ' '; i++) { + isNegative = correction[i + 1] == '-'; + } + + r += (isNegative ? -1.0f : 1.0f) * ((pEnd[1] - '0') / 10.0f); } return r; }