From dbd234ef815ff813b0172d8aa0040b974ef57aea Mon Sep 17 00:00:00 2001 From: Laurent <44267323+laurentdong@users.noreply.github.com> Date: Fri, 27 Sep 2019 21:58:32 -0400 Subject: [PATCH] Accept negative number Expression should support negative number --- sonoff/xdrv_10_rules.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 10f733f56..c23b13279 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -919,6 +919,10 @@ bool findNextNumber(char * &pNumber, float &value) { bool bSucceed = false; String sNumber = ""; + if (*pNumber == '-') { + sNumber = "-"; + pNumber++; + } while (*pNumber) { if (isdigit(*pNumber) || (*pNumber == '.')) { sNumber += *pNumber; @@ -996,7 +1000,7 @@ bool findNextVariableValue(char * &pVarname, float &value) /* * Find next object in expression and evaluate it * An object could be: - * - A float number start with a digit, like 0.787 + * - A float number start with a digit or minus, like 0.787, -3 * - A variable name, like VAR1, MEM3 * - An expression enclosed with a pair of round brackets, (.....) * Input: @@ -1018,7 +1022,7 @@ bool findNextObjectValue(char * &pointer, float &value) pointer++; continue; } - if (isdigit(*pointer)) { //This object is a number + if (isdigit(*pointer) || (*pointer) == '-') { //This object is a number bSucceed = findNextNumber(pointer, value); break; } else if (isalpha(*pointer)) { //Should be a variable like VAR12, MEM1