mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Добавляем таймер
This commit is contained in:
@@ -5,6 +5,7 @@ void* getAPI_SysExt(String subtype, String params);
|
||||
void* getAPI_Variable(String subtype, String params);
|
||||
void* getAPI_ButtonIn(String subtype, String params);
|
||||
void* getAPI_ButtonOut(String subtype, String params);
|
||||
void* getAPI_Timer(String subtype, String params);
|
||||
void* getAPI_Ads1115(String subtype, String params);
|
||||
void* getAPI_Aht20(String subtype, String params);
|
||||
void* getAPI_AnalogAdc(String subtype, String params);
|
||||
@@ -27,6 +28,7 @@ if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;
|
||||
|
||||
37
src/modules/exec/Timer/Timer.cpp
Normal file
37
src/modules/exec/Timer/Timer.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
16
src/modules/exec/Timer/items.json
Normal file
16
src/modules/exec/Timer/items.json
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"name": "Таймер",
|
||||
"num": 31,
|
||||
"type": "Writing",
|
||||
"subtype": "Timer",
|
||||
"id": "timer",
|
||||
"widget": "",
|
||||
"page": "",
|
||||
"descr": "",
|
||||
|
||||
"int": 1,
|
||||
"countDown": 15,
|
||||
"ticker": 0
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user