From cf6fd585c36a0f1db526f2a8c9b7dc7ee397d1c0 Mon Sep 17 00:00:00 2001 From: biver Date: Sat, 26 Mar 2022 20:58:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 125 +++++++++++++++++------------- src/modules/API.cpp | 2 + src/modules/exec/Timer/Timer.cpp | 37 +++++++++ src/modules/exec/Timer/items.json | 16 ++++ 4 files changed, 124 insertions(+), 56 deletions(-) create mode 100644 src/modules/exec/Timer/Timer.cpp create mode 100644 src/modules/exec/Timer/items.json diff --git a/data_svelte/items.json b/data_svelte/items.json index 45a28d63..9011b065 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -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", diff --git a/src/modules/API.cpp b/src/modules/API.cpp index cdbb5aff..70d73334 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -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; diff --git a/src/modules/exec/Timer/Timer.cpp b/src/modules/exec/Timer/Timer.cpp new file mode 100644 index 00000000..d3a1724b --- /dev/null +++ b/src/modules/exec/Timer/Timer.cpp @@ -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; + } +} diff --git a/src/modules/exec/Timer/items.json b/src/modules/exec/Timer/items.json new file mode 100644 index 00000000..d275696c --- /dev/null +++ b/src/modules/exec/Timer/items.json @@ -0,0 +1,16 @@ +[ + { + "name": "Таймер", + "num": 31, + "type": "Writing", + "subtype": "Timer", + "id": "timer", + "widget": "", + "page": "", + "descr": "", + + "int": 1, + "countDown": 15, + "ticker": 0 + } +] \ No newline at end of file