Arduino-CommandParser
Arduino-CommandParser copied to clipboard
Negative Values for int64 not working
When I register the example
parser.registerCommand("test", "sdiu", &cmd_test);
and parse the following Message:
test "Hello World" 13.23 -45 85
I get 45 for the interger instead of -45
Serial.print("int64: "); Serial.println(args[2].asInt64);
gives
int64: 45
It seems that the negative value is parsed, because when i submit a negative value for uint64
test "Hallo Welt" 13.23 -45 -85
then i get the Error;
parse error: invalid uint64_t for arg 4
Same problem.
I fixed it substituing the end of strToInt function
return digit == -1 ? 0 : position; // ensure that there is at least one digit
with
if (digit == -1) {
return 0;
}
if (isNegative) {
*value = -*value;
}
return position; // ensure that there is at least one digit
I have the same issue. Would it be possible to merge #7 which, I believe, fixes this. Meanwhile, I jerry-rigged the code with the suggestion from @m-marini (thanks for that!).
Thank you!