mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
add scheduler random function (rnd(x) => random 0..x)
This commit is contained in:
@@ -102,6 +102,9 @@ std::deque<Token> exprToTokens(const std::string & expr) {
|
||||
} else if (strncmp(p, "hex", 3) == 0) {
|
||||
p += 2;
|
||||
tokens.emplace_back(Token::Type::Unary, "h", 5);
|
||||
} else if (strncmp(p, "rnd", 3) == 0) {
|
||||
p += 2;
|
||||
tokens.emplace_back(Token::Type::Unary, "d", 5);
|
||||
} else if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) {
|
||||
const auto * b = p;
|
||||
while ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) {
|
||||
@@ -526,6 +529,9 @@ std::string calculate(const std::string & expr) {
|
||||
case 'x':
|
||||
stack.push_back(to_hex(static_cast<int>(rhd)));
|
||||
break;
|
||||
case 'd':
|
||||
stack.push_back(to_string(rhd * esp_random() / UINT32_MAX));
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
case Token::Type::Compare: {
|
||||
|
||||
Reference in New Issue
Block a user