Skip to content

Commit

Permalink
Fixed Str2F conversion error
Browse files Browse the repository at this point in the history
  • Loading branch information
tauchner committed Jun 30, 2022
1 parent 02d6001 commit 41d847a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion airrohr-firmware/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 41d847a

Please sign in to comment.