From 7d71c78170ab39c08b9070409359b2d18970fdea Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 27 Apr 2022 14:17:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=83=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=20=D0=BF=D0=BE=20=D1=83?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B9=D0=BC=D0=B5=D1=80=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/Timer/Timer.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/modules/exec/Timer/Timer.cpp b/src/modules/exec/Timer/Timer.cpp index 269c8023..5a961934 100644 --- a/src/modules/exec/Timer/Timer.cpp +++ b/src/modules/exec/Timer/Timer.cpp @@ -10,30 +10,48 @@ class Timer : public IoTItem { bool _ticker = false; bool _repeat = false; bool _needSave = false; + bool _pause = false; + int _initValue; public: Timer(String parameters): IoTItem(parameters) { - float valDtmp; - jsonRead(parameters, "countDown", valDtmp); - if (value.valD == 0) value.valD = valDtmp; + jsonRead(parameters, "countDown", _initValue); + value.valD = _initValue; + jsonRead(parameters, "ticker", _ticker); jsonRead(parameters, "repeat", _repeat); - if (_repeat) _repeat = valDtmp; // если в параметрах просят повторить, то запоминаем настроечное значение отчета _unfin = !value.valD; jsonRead(parameters, "needSave", _needSave); // нужно сохранять счетчик в постоянную память } void doByInterval() { - if (!_unfin && value.valD) { + if (!_unfin && value.valD && !_pause) { value.valD--; if (_needSave) needSave = true; if (value.valD == 0) { regEvent(value.valD, "Time's up"); - if (_repeat) value.valD = _repeat; + if (_repeat) value.valD = _initValue; } } - if (_ticker) regEvent(value.valD, "Timer tick"); + if (_ticker && !_pause) regEvent(value.valD, "Timer tick"); + } + + IoTValue execute(String command, std::vector ¶m) { + if (command == "stop") { + _pause = true; + } else if (command == "reset") { + _pause = false; + value.valD = _initValue; + } else if (command == "continue") { + _pause = false; + } else if (command == "int") { + if (param.size()) { + setInterval(param[0].valD); + } + } + + return {}; } ~Timer() {};