MCPcopy Create free account
hub / github.com/FastLED/FastLED / parseInt

Method parseInt

src/fl/system/serial.cpp.hpp:225–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225long SerialPort::parseInt() {
226 bool negative = false;
227 long value = 0;
228 bool foundDigit = false;
229 u32 startTime = fl::millis();
230
231 // Skip non-numeric characters
232 while (fl::millis() - startTime < mTimeoutMs) {
233 if (available() > 0) {
234 int c = peek();
235 if (c == -1) {
236 continue;
237 }
238
239 // Check for sign
240 if (c == '-') {
241 negative = true;
242 read(); // Consume the sign
243 break;
244 } else if (c == '+') {
245 read(); // Consume the sign
246 break;
247 } else if (c >= '0' && c <= '9') {
248 break; // Found a digit
249 } else {
250 read(); // Skip non-numeric character
251 startTime = fl::millis(); // Reset timeout
252 }
253 }
254 }
255
256 // Parse digits
257 startTime = fl::millis();
258 while (fl::millis() - startTime < mTimeoutMs) {
259 if (available() > 0) {
260 int c = peek();
261 if (c == -1) {
262 continue;
263 }
264
265 if (c >= '0' && c <= '9') {
266 value = value * 10 + (c - '0');
267 read(); // Consume the digit
268 foundDigit = true;
269 startTime = fl::millis(); // Reset timeout
270 } else {
271 break; // Non-digit, stop parsing
272 }
273 }
274 }
275
276 return foundDigit ? (negative ? -value : value) : 0;
277}
278
279float SerialPort::parseFloat() {
280 bool negative = false;

Callers

nothing calls this directly

Calls 4

millisFunction · 0.50
availableFunction · 0.50
peekFunction · 0.50
readFunction · 0.50

Tested by

no test coverage detected