Optimize RAM usage for Expression

This commit is contained in:
Laurent 2019-02-18 16:12:14 -05:00
parent c527d4dc99
commit 2bc84a9aad

View File

@ -625,7 +625,7 @@ bool findNextNumber(char * &pNumber, double &value)
*/ */
bool findNextVariableValue(char * &pVarname, double &value) bool findNextVariableValue(char * &pVarname, double &value)
{ {
bool succeed = false; bool succeed = true;
value = 0; value = 0;
String sVarName = ""; String sVarName = "";
while (*pVarname) { while (*pVarname) {
@ -637,32 +637,28 @@ bool findNextVariableValue(char * &pVarname, double &value)
} }
} }
sVarName.toUpperCase(); sVarName.toUpperCase();
if (sVarName.startsWith("VAR")) { if (sVarName.startsWith(F("VAR"))) {
int index = sVarName.substring(3).toInt(); int index = sVarName.substring(3).toInt();
if (index > 0 && index <= MAX_RULE_VARS) { if (index > 0 && index <= MAX_RULE_VARS) {
value = CharToDouble(vars[index -1]); value = CharToDouble(vars[index -1]);
succeed = true;
} }
} else if (sVarName.startsWith("MEM")) { } else if (sVarName.startsWith(F("MEM"))) {
int index = sVarName.substring(3).toInt(); int index = sVarName.substring(3).toInt();
if (index > 0 && index <= MAX_RULE_MEMS) { if (index > 0 && index <= MAX_RULE_MEMS) {
value = CharToDouble(Settings.mems[index -1]); value = CharToDouble(Settings.mems[index -1]);
succeed = true;
} }
} else if (sVarName.equals("TIME")) { } else if (sVarName.equals(F("TIME"))) {
value = GetMinutesPastMidnight(); value = GetMinutesPastMidnight();
succeed = true; } else if (sVarName.equals(F("UPTIME"))) {
} else if (sVarName.equals("UPTIME")) {
value = GetMinutesUptime(); value = GetMinutesUptime();
succeed = true;
#if defined(USE_TIMERS) && defined(USE_SUNRISE) #if defined(USE_TIMERS) && defined(USE_SUNRISE)
} else if (sVarName.equals("SUNRISE")) { } else if (sVarName.equals(F("SUNRISE"))) {
value = GetSunMinutes(0); value = GetSunMinutes(0);
succeed = true; } else if (sVarName.equals(F("SUNSET"))) {
} else if (sVarName.equals("SUNSET")) {
value = GetSunMinutes(1); value = GetSunMinutes(1);
succeed = true;
#endif #endif
} else {
succeed = false;
} }
return succeed; return succeed;