Skip to content

Commit dd9642b

Browse files
committed
Better scanning of variable input
1 parent d621185 commit dd9642b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,19 @@ bool parseLine(char* str, Settings *settings)
463463
//If settingValue has a mix of letters and numbers, just convert to string
464464
sprintf(settingValue, "%s", str);
465465

466-
//Check if string is mixed
467-
bool isNumber = false;
468-
bool isLetter = false;
469-
bool isOther = false;
466+
//Check if string is mixed: 8a011EF, 192.168.1.1, -102.4, t6-h4$, etc.
467+
bool hasSymbol = false;
468+
int decimalCount = 0;
470469
for (int x = 0 ; x < strlen(settingValue) ; x++)
471470
{
472-
if (isDigit(settingValue[x])) isNumber = true;
473-
else if (isAlpha(settingValue[x])) isLetter = true;
474-
else isOther = true;
471+
if (settingValue[x] == '.') decimalCount++;
472+
else if (x == 0 && settingValue[x] == '-') {;} //Do nothing
473+
else if (isAlpha(settingValue[x])) hasSymbol = true;
474+
else if(isDigit(settingValue[x]) == false) hasSymbol = true;
475475
}
476476

477-
if ( (isLetter && isNumber) || isOther) //See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/274
477+
//See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/274
478+
if (hasSymbol || decimalCount > 1)
478479
{
479480
//It's a mix. Skip strtod.
480481

0 commit comments

Comments
 (0)