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

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

@@ -74,12 +74,25 @@
"inv": 0,
"pin": 2
},
{
"name": "6. Таймер",
"num": 6,
"type": "Writing",
"subtype": "Timer",
"id": "timer",
"widget": "",
"page": "",
"descr": "",
"int": 1,
"countDown": 15,
"ticker": 0
},
{
"header": "Сенсоры"
},
{
"name": "6. Датчик напряжения ADS1115",
"num": 6,
"name": "7. Датчик напряжения ADS1115",
"num": 7,
"type": "Reading",
"subtype": "Ads1115",
"id": "Ads3",
@@ -95,8 +108,8 @@
"int": 10
},
{
"name": "7. Cенсор температуры AHT20",
"num": 7,
"name": "8. Cенсор температуры AHT20",
"num": 8,
"type": "Reading",
"subtype": "Aht20t",
"id": "Temp20",
@@ -108,8 +121,8 @@
"round": 1
},
{
"name": "8. Cенсор влажности AHT20",
"num": 8,
"name": "9. Cенсор влажности AHT20",
"num": 9,
"type": "Reading",
"subtype": "Aht20h",
"id": "Hum20",
@@ -121,8 +134,8 @@
"round": 1
},
{
"name": "9. Аналоговый сенсор",
"num": 9,
"name": "10. Аналоговый сенсор",
"num": 10,
"type": "Reading",
"subtype": "AnalogAdc",
"id": "t",
@@ -137,8 +150,8 @@
"int": 15
},
{
"name": "10. Cенсор температуры Bme280",
"num": 10,
"name": "11. Cенсор температуры Bme280",
"num": 11,
"type": "Reading",
"subtype": "Bme280t",
"id": "tmp3",
@@ -150,8 +163,8 @@
"round": 1
},
{
"name": "11. Cенсор давления Bme280",
"num": 11,
"name": "12. Cенсор давления Bme280",
"num": 12,
"type": "Reading",
"subtype": "Bme280p",
"id": "Press3",
@@ -163,8 +176,8 @@
"round": 1
},
{
"name": "12. Cенсор влажности Bme280",
"num": 12,
"name": "13. Cенсор влажности Bme280",
"num": 13,
"type": "Reading",
"subtype": "Bme280h",
"id": "Hum3",
@@ -176,8 +189,8 @@
"round": 1
},
{
"name": "13. Cенсор температуры Bmp280",
"num": 13,
"name": "14. Cенсор температуры Bmp280",
"num": 14,
"type": "Reading",
"subtype": "Bmp280t",
"id": "tmp3",
@@ -189,8 +202,8 @@
"round": 1
},
{
"name": "14. Cенсор давления Bmp280",
"num": 14,
"name": "15. Cенсор давления Bmp280",
"num": 15,
"type": "Reading",
"subtype": "Bmp280p",
"id": "Press3",
@@ -202,8 +215,8 @@
"round": 1
},
{
"name": "15. Cенсор температуры dht11",
"num": 15,
"name": "16. Cенсор температуры dht11",
"num": 16,
"type": "Reading",
"subtype": "Dht1122t",
"id": "tmp3",
@@ -215,8 +228,8 @@
"senstype": "dht11"
},
{
"name": "16. Cенсор влажности dht11",
"num": 16,
"name": "17. Cенсор влажности dht11",
"num": 17,
"type": "Reading",
"subtype": "Dht1122h",
"id": "Hum3",
@@ -228,8 +241,8 @@
"senstype": "dht11"
},
{
"name": "17. Cенсор температуры ds18b20",
"num": 17,
"name": "18. Cенсор температуры ds18b20",
"num": 18,
"type": "Reading",
"subtype": "Ds18b20",
"id": "dstmp",
@@ -243,8 +256,8 @@
"round": 1
},
{
"name": "18. Cенсор температуры GY21",
"num": 18,
"name": "19. Cенсор температуры GY21",
"num": 19,
"type": "Reading",
"subtype": "GY21t",
"id": "tmp4",
@@ -255,8 +268,8 @@
"int": 15
},
{
"name": "19. Cенсор влажности GY21",
"num": 19,
"name": "20. Cенсор влажности GY21",
"num": 20,
"type": "Reading",
"subtype": "GY21h",
"id": "Hum4",
@@ -267,8 +280,8 @@
"int": 15
},
{
"name": "20. Cенсор температуры HDC1080",
"num": 20,
"name": "21. Cенсор температуры HDC1080",
"num": 21,
"type": "Reading",
"subtype": "Hdc1080t",
"id": "Temp1080",
@@ -280,8 +293,8 @@
"round": 1
},
{
"name": "21. Cенсор влажности HDC1080",
"num": 21,
"name": "22. Cенсор влажности HDC1080",
"num": 22,
"type": "Reading",
"subtype": "Hdc1080h",
"id": "Hum1080",
@@ -293,8 +306,8 @@
"round": 1
},
{
"name": "22. Cенсор температуры MAX6675",
"num": 22,
"name": "23. Cенсор температуры MAX6675",
"num": 23,
"type": "Reading",
"subtype": "Max6675t",
"id": "maxtmp",
@@ -307,8 +320,8 @@
"CLK": 14
},
{
"name": "23. Датчик CO2 MHZ-19 UART",
"num": 23,
"name": "24. Датчик CO2 MHZ-19 UART",
"num": 24,
"type": "Reading",
"subtype": "Mhz19uart",
"id": "co2uart",
@@ -326,8 +339,8 @@
"ABC": 1
},
{
"name": "24. Датчик CO2 MHZ-19 PWM",
"num": 24,
"name": "25. Датчик CO2 MHZ-19 PWM",
"num": 25,
"type": "Reading",
"subtype": "Mhz19pwm",
"id": "co2pwm",
@@ -341,8 +354,8 @@
"int": 300
},
{
"name": "25. Cенсор температуры от MHZ-19 UART",
"num": 25,
"name": "26. Cенсор температуры от MHZ-19 UART",
"num": 26,
"type": "Reading",
"subtype": "Mhz19temp",
"id": "Mhz19temp",
@@ -358,8 +371,8 @@
"int": 30
},
{
"name": "26. Рабочий диапазон от MHZ-19 UART",
"num": 26,
"name": "27. Рабочий диапазон от MHZ-19 UART",
"num": 27,
"type": "Reading",
"subtype": "Mhz19range",
"id": "Mhz19range",
@@ -376,8 +389,8 @@
"int": 30
},
{
"name": "27. Автокалибровка от MHZ-19 UART",
"num": 27,
"name": "28. Автокалибровка от MHZ-19 UART",
"num": 28,
"type": "Reading",
"subtype": "Mhz19ABC",
"id": "Mhz19ABC",
@@ -391,8 +404,8 @@
"int": 30
},
{
"name": "28. Датчик пыли SDS011 PM25",
"num": 28,
"name": "29. Датчик пыли SDS011 PM25",
"num": 29,
"type": "Reading",
"subtype": "Sds011_25",
"id": "pmuart25",
@@ -409,8 +422,8 @@
"period": 300
},
{
"name": "29. Датчик пыли SDS011 PM10",
"num": 29,
"name": "30. Датчик пыли SDS011 PM10",
"num": 30,
"type": "Reading",
"subtype": "Sds011_10",
"id": "pmuart10",
@@ -427,8 +440,8 @@
"period": 300
},
{
"name": "30. Cенсор температуры Sht20",
"num": 30,
"name": "31. Cенсор температуры Sht20",
"num": 31,
"type": "Reading",
"subtype": "Sht20t",
"id": "tmp2",
@@ -439,8 +452,8 @@
"round": 1
},
{
"name": "31. Cенсор влажности Sht20",
"num": 31,
"name": "32. Cенсор влажности Sht20",
"num": 32,
"type": "Reading",
"subtype": "Sht20h",
"id": "Hum2",
@@ -454,8 +467,8 @@
"header": "Экраны"
},
{
"name": "32. LCD экран 2004",
"num": 32,
"name": "33. LCD экран 2004",
"num": 33,
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -469,8 +482,8 @@
"id2show": "id датчика"
},
{
"name": "33. LCD экран 1602",
"num": 33,
"name": "34. LCD экран 1602",
"num": 34,
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",

View File

@@ -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;

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
}
]