Parse floating-point number from serial input.
Skips non-numeric characters until a number is found, then parses it. Stops at first non-numeric character after the number.
279 {
280 bool negative = false;
281 long intPart = 0;
282 long fracPart = 0;
283 int fracDigits = 0;
284 bool foundDigit = false;
285 bool inFraction = false;
287
288
292 if (c == -1) {
293 continue;
294 }
295
296
297 if (c == '-') {
298 negative = true;
300 break;
301 } else if (c == '+') {
303 break;
304 } else if (c >= '0' && c <= '9') {
305 break;
306 } else if (c == '.') {
307 break;
308 } else {
311 }
312 }
313 }
314
315
320 if (c == -1) {
321 continue;
322 }
323
324 if (c == '.' && !inFraction) {
325 inFraction = true;
327 foundDigit = true;
329 } else if (c >= '0' && c <= '9') {
330 if (inFraction) {
331 fracPart = fracPart * 10 + (c - '0');
332 fracDigits++;
333 } else {
334 intPart = intPart * 10 + (c - '0');
335 }
337 foundDigit = true;
339 } else {
340 break;
341 }
342 }
343 }
344
345 if (!foundDigit) {
346 return 0.0f;
347 }
348
349
350 float value =
static_cast<float>(intPart);
351 if (fracDigits > 0) {
352 float divisor = 1.0f;
353 for (int i = 0; i < fracDigits; i++) {
354 divisor *= 10.0f;
355 }
356 value +=
static_cast<float>(fracPart) / divisor;
357 }
358
360}
int peek()
Peek at next byte without removing it from buffer.
int available()
Check how many bytes are available to read.
int read()
Read next byte from serial input.
constexpr int type_rank< T >::value
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.