From d57ab3494dc344aa991e3020515966e390fc5e21 Mon Sep 17 00:00:00 2001 From: Hector Zarate Date: Mon, 14 Apr 2014 13:59:38 +0200 Subject: [PATCH 1/2] Renamed Stream::peekNextDigit to Stream::skipUntilDigit for clarity --- hardware/arduino/cores/arduino/Stream.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/cores/arduino/Stream.cpp b/hardware/arduino/cores/arduino/Stream.cpp index aafb7fcf97d..73add9dedb9 100644 --- a/hardware/arduino/cores/arduino/Stream.cpp +++ b/hardware/arduino/cores/arduino/Stream.cpp @@ -52,7 +52,7 @@ int Stream::timedPeek() // returns peek of the next digit in the stream or -1 if timeout // discards non-numeric characters -int Stream::peekNextDigit() +int Stream::skipUntilDigit() { int c; while (1) { @@ -141,7 +141,7 @@ long Stream::parseInt(char skipChar) long value = 0; int c; - c = peekNextDigit(); + c = skipUntilDigit(); // ignore non numeric leading characters if(c < 0) return 0; // zero returned if timeout @@ -179,7 +179,7 @@ float Stream::parseFloat(char skipChar){ char c; float fraction = 1.0; - c = peekNextDigit(); + c = skipUntilDigit(); // ignore non numeric leading characters if(c < 0) return 0; // zero returned if timeout From 7eeeb82a6392e528e891400f112f3f46358aac58 Mon Sep 17 00:00:00 2001 From: Hector Zarate Date: Mon, 14 Apr 2014 14:08:56 +0200 Subject: [PATCH 2/2] Allow leading decimal separator in Stream::parseFloat. Fixes #1962 : Floating point numbers with a trailing '.' character would be rendered as integers. For example: .032 => will become 32. --- hardware/arduino/cores/arduino/Stream.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/cores/arduino/Stream.cpp b/hardware/arduino/cores/arduino/Stream.cpp index 73add9dedb9..3b0bcfd0730 100644 --- a/hardware/arduino/cores/arduino/Stream.cpp +++ b/hardware/arduino/cores/arduino/Stream.cpp @@ -52,7 +52,7 @@ int Stream::timedPeek() // returns peek of the next digit in the stream or -1 if timeout // discards non-numeric characters -int Stream::skipUntilDigit() +int Stream::skipUntilDigit(bool detectPointChar) { int c; while (1) { @@ -60,6 +60,7 @@ int Stream::skipUntilDigit() if (c < 0) return c; // timeout if (c == '-') return c; if (c >= '0' && c <= '9') return c; + if (detectPointChar == true && c == '.') return c; read(); // discard non-numeric } } @@ -141,7 +142,7 @@ long Stream::parseInt(char skipChar) long value = 0; int c; - c = skipUntilDigit(); + c = skipUntilDigit(false); // ignore non numeric leading characters if(c < 0) return 0; // zero returned if timeout @@ -179,7 +180,7 @@ float Stream::parseFloat(char skipChar){ char c; float fraction = 1.0; - c = skipUntilDigit(); + c = skipUntilDigit(true); // ignore non numeric leading characters if(c < 0) return 0; // zero returned if timeout