Добавляем таймер

This commit is contained in:
2022-03-26 20:58:15 +03:00
parent 185a949a80
commit cf6fd585c3
4 changed files with 124 additions and 56 deletions

View File

@@ -0,0 +1,37 @@
#include "Global.h"
#include "classes/IoTItem.h"
extern IoTGpio IoTgpio;
class Timer : public IoTItem {
private:
bool _unfin = false;
bool _ticker = false;
public:
Timer(String parameters): IoTItem(parameters) {
jsonRead(parameters, "countDown", value.valD);
jsonRead(parameters, "ticker", _ticker);
_unfin = !value.valD;
}
void doByInterval() {
if (!_unfin && value.valD) {
value.valD--;
if (value.valD == 0) regEvent(value.valD, "Time's up");
}
if (_ticker) regEvent(value.valD, "Timer tick");
}
~Timer() {};
};
void* getAPI_Timer(String subtype, String param) {
if (subtype == F("Timer")) {
return new Timer(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,16 @@
[
{
"name": "Таймер",
"num": 31,
"type": "Writing",
"subtype": "Timer",
"id": "timer",
"widget": "",
"page": "",
"descr": "",
"int": 1,
"countDown": 15,
"ticker": 0
}
]