mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
multiple onChange and check one ? : sequence
This commit is contained in:
@@ -368,7 +368,8 @@ bool WebSchedulerService::command(const char * cmd, const char * data) {
|
|||||||
|
|
||||||
bool WebSchedulerService::onChange(const char * cmd) {
|
bool WebSchedulerService::onChange(const char * cmd) {
|
||||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||||
if (scheduleItem.active && scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_ONCHANGE && Helpers::toLower(scheduleItem.time) == Helpers::toLower(cmd)) {
|
if (scheduleItem.active && scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_ONCHANGE
|
||||||
|
&& Helpers::toLower(scheduleItem.time).find(Helpers::toLower(cmd)) != std::string::npos) {
|
||||||
#ifdef EMESESP_DEBUG
|
#ifdef EMESESP_DEBUG
|
||||||
// emsesp::EMSESP::logger().debug(scheduleItem.cmd.c_str());
|
// emsesp::EMSESP::logger().debug(scheduleItem.cmd.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -371,16 +371,20 @@ int to_logic(const std::string & s) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// number to string
|
// number to string, remove trailing zeros
|
||||||
std::string to_string(double d) {
|
std::string to_string(double d) {
|
||||||
if (d == static_cast<int>(d)) {
|
std::string s = std::to_string(d);
|
||||||
return std::to_string(static_cast<int>(d));
|
while (!s.empty() && s.back() == '0') {
|
||||||
|
s.pop_back();
|
||||||
}
|
}
|
||||||
return std::to_string(d);
|
if (!s.empty() && s.back() == '.') {
|
||||||
|
s.pop_back();
|
||||||
|
}
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPN calculator
|
// RPN calculator
|
||||||
std::string compute(const std::string & expr) {
|
std::string calculate(const std::string & expr) {
|
||||||
auto expr_new = emsesp::Helpers::toLower(expr);
|
auto expr_new = emsesp::Helpers::toLower(expr);
|
||||||
// emsesp::EMSESP::logger().info("calculate: %s", expr_new.c_str());
|
// emsesp::EMSESP::logger().info("calculate: %s", expr_new.c_str());
|
||||||
commands(expr_new);
|
commands(expr_new);
|
||||||
@@ -554,3 +558,16 @@ std::string compute(const std::string & expr) {
|
|||||||
}
|
}
|
||||||
return stack.back();
|
return stack.back();
|
||||||
}
|
}
|
||||||
|
// check for <expr> ? <expr1> : <expr2>
|
||||||
|
std::string compute(const std::string & expr) {
|
||||||
|
auto q = expr.find_first_of("?");
|
||||||
|
auto p = expr.find_first_of(":", q);
|
||||||
|
if (p != std::string::npos && q != std::string::npos) {
|
||||||
|
if (calculate(expr.substr(0, q))[0] == '1') {
|
||||||
|
return calculate(expr.substr(q + 1, p - q - 1));
|
||||||
|
} else {
|
||||||
|
return calculate(expr.substr(p + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return calculate(expr);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user