mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +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) {
|
} else if (strncmp(p, "hex", 3) == 0) {
|
||||||
p += 2;
|
p += 2;
|
||||||
tokens.emplace_back(Token::Type::Unary, "h", 5);
|
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)) {
|
} else if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) {
|
||||||
const auto * b = p;
|
const auto * b = p;
|
||||||
while ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) {
|
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':
|
case 'x':
|
||||||
stack.push_back(to_hex(static_cast<int>(rhd)));
|
stack.push_back(to_hex(static_cast<int>(rhd)));
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
stack.push_back(to_string(rhd * esp_random() / UINT32_MAX));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case Token::Type::Compare: {
|
case Token::Type::Compare: {
|
||||||
|
|||||||
Reference in New Issue
Block a user