Skip to content

Commit

Permalink
Merge pull request opendata-stuttgart#960 from Tiefseetauchner/beta
Browse files Browse the repository at this point in the history
Fixed Str2F conversion error in Offsetcalculation
  • Loading branch information
ricki-z authored Mar 29, 2024
2 parents 315374f + 41d847a commit 3f5a306
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 3f5a306

Please sign in to comment.