Добавляем параметр повторения для таймера

This commit is contained in:
2022-03-26 21:35:51 +03:00
parent cf6fd585c3
commit 613d60256a
2 changed files with 11 additions and 2 deletions

View File

@@ -8,18 +8,26 @@ class Timer : public IoTItem {
private:
bool _unfin = false;
bool _ticker = false;
bool _repeat = false;
public:
Timer(String parameters): IoTItem(parameters) {
jsonRead(parameters, "countDown", value.valD);
jsonRead(parameters, "ticker", _ticker);
jsonRead(parameters, "repeat", _repeat);
if (_repeat) _repeat = value.valD; // если в параметрах просят повторить, то запоминаем настроечное значение отчета
_unfin = !value.valD;
}
void doByInterval() {
if (!_unfin && value.valD) {
value.valD--;
if (value.valD == 0) regEvent(value.valD, "Time's up");
if (value.valD == 0) {
regEvent(value.valD, "Time's up");
if (_repeat) value.valD = _repeat;
}
}
if (_ticker) regEvent(value.valD, "Timer tick");

View File

@@ -11,6 +11,7 @@
"int": 1,
"countDown": 15,
"ticker": 0
"ticker": 0,
"repeat": 0
}
]