diff --git a/data_svelte/items.json b/data_svelte/items.json index c5190460..9e0e2f57 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -382,7 +382,23 @@ }, { "global": 0, - "name": "26. PZEM 004t Напряжение", + "name": "26. Аналоговый счетчик импульсов", + "type": "Writing", + "subtype": "Impulse", + "id": "impulse", + "widget": "anydataDef", + "page": "Счетчики", + "descr": "Импульсов", + "needSave": 0, + "int": 1, + "pin": 16, + "pinMode": "INPUT", + "debounceDelay": 3, + "num": 26 + }, + { + "global": 0, + "name": "27. PZEM 004t Напряжение", "type": "Reading", "subtype": "Pzem004v", "id": "v", @@ -392,11 +408,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 26 + "num": 27 }, { "global": 0, - "name": "27. PZEM 004t Сила тока", + "name": "28. PZEM 004t Сила тока", "type": "Reading", "subtype": "Pzem004a", "id": "a", @@ -406,11 +422,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 27 + "num": 28 }, { "global": 0, - "name": "28. PZEM 004t Мощность", + "name": "29. PZEM 004t Мощность", "type": "Reading", "subtype": "Pzem004w", "id": "w", @@ -420,11 +436,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 28 + "num": 29 }, { "global": 0, - "name": "29. PZEM 004t Энергия", + "name": "30. PZEM 004t Энергия", "type": "Reading", "subtype": "Pzem004wh", "id": "wh", @@ -434,11 +450,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 29 + "num": 30 }, { "global": 0, - "name": "30. PZEM 004t Частота", + "name": "31. PZEM 004t Частота", "type": "Reading", "subtype": "Pzem004hz", "id": "hz", @@ -448,11 +464,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 30 + "num": 31 }, { "global": 0, - "name": "31. PZEM 004t Косинус", + "name": "32. PZEM 004t Косинус", "type": "Reading", "subtype": "Pzem004pf", "id": "pf", @@ -462,11 +478,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 31 + "num": 32 }, { "global": 0, - "name": "32. PZEM настройка", + "name": "33. PZEM настройка", "type": "Reading", "subtype": "Pzem004cmd", "id": "set", @@ -478,11 +494,11 @@ "changeaddr": 0, "setaddr": "0x01", "reset": 0, - "num": 32 + "num": 33 }, { "global": 0, - "name": "33. Часы реального времени", + "name": "34. Часы реального времени", "type": "Reading", "subtype": "RTC", "id": "rtc", @@ -498,11 +514,11 @@ "int": 5, "btn-setUTime": "0", "btn-setSysTime": "nil", - "num": 33 + "num": 34 }, { "global": 0, - "name": "34. Sht20 Температура", + "name": "35. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -511,11 +527,11 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 34 + "num": 35 }, { "global": 0, - "name": "35. Sht20 Влажность", + "name": "36. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -524,11 +540,11 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 35 + "num": 36 }, { "global": 0, - "name": "36. Sht30 Температура", + "name": "37. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -537,11 +553,11 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 36 + "num": 37 }, { "global": 0, - "name": "37. Sht30 Влажность", + "name": "38. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -550,12 +566,12 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 37 + "num": 38 }, { "global": 0, - "name": "38. HC-SR04 Ультразвуковой дальномер", - "num": 38, + "name": "39. HC-SR04 Ультразвуковой дальномер", + "num": 39, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -567,7 +583,7 @@ "int": 5 }, { - "name": "39. UART", + "name": "40. UART", "type": "Reading", "subtype": "UART", "page": "", @@ -579,14 +595,14 @@ "line": 2, "speed": 9600, "eventFormat": 0, - "num": 39 + "num": 40 }, { "header": "Исполнительные устройства" }, { "global": 0, - "name": "40. Кнопка подключенная к пину", + "name": "41. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -601,11 +617,11 @@ "debounceDelay": 50, "fixState": 0, "inv": 0, - "num": 40 + "num": 41 }, { "global": 0, - "name": "41. Управление пином", + "name": "42. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -616,11 +632,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 41 + "num": 42 }, { "global": 0, - "name": "42. Сервопривод", + "name": "43. Сервопривод", "type": "Writing", "subtype": "IoTServo", "id": "servo", @@ -631,11 +647,11 @@ "pin": 12, "apin": -1, "amap": "0, 4096, 0, 180", - "num": 42 + "num": 43 }, { "global": 0, - "name": "43. Расширитель портов Mcp23017", + "name": "44. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -645,11 +661,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 43 + "num": 44 }, { "global": 0, - "name": "44. MP3 плеер", + "name": "45. MP3 плеер", "type": "Reading", "subtype": "Mp3", "id": "mp3", @@ -659,11 +675,11 @@ "int": 1, "pins": "14,12", "volume": 20, - "num": 44 + "num": 45 }, { "global": 0, - "name": "45. Сенсорная кнопка", + "name": "46. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -677,11 +693,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 45 + "num": 46 }, { "global": 0, - "name": "46. Расширитель портов Pcf8574", + "name": "47. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -691,11 +707,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 46 + "num": 47 }, { "global": 0, - "name": "47. PWM ESP8266", + "name": "48. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -707,11 +723,11 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 47 + "num": 48 }, { "global": 0, - "name": "48. Телеграм-Лайт", + "name": "49. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -720,14 +736,14 @@ "descr": "", "token": "", "chatID": "", - "num": 48 + "num": 49 }, { "header": "Экраны" }, { "global": 0, - "name": "49. LCD экран 2004", + "name": "50. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -739,10 +755,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 49 + "num": 50 }, { - "name": "50. LCD экран 1602", + "name": "51. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -754,6 +770,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 50 + "num": 51 } ] \ No newline at end of file diff --git a/data_svelte/widgets.json b/data_svelte/widgets.json index 4c681bff..8522af99 100644 --- a/data_svelte/widgets.json +++ b/data_svelte/widgets.json @@ -41,7 +41,25 @@ "label": "Ватты", "widget": "anydata", "after": "Wt", - "icon": "speedometer" + "icon": "speedometer", + "color": [ + { + "level": 0, + "value": "" + }, + { + "level": 200, + "value": "#009933" + }, + { + "level": 2000, + "value": "#FF9900" + }, + { + "level": 4000, + "value": "red" + } + ] }, { "name": "anydataWth", @@ -62,7 +80,42 @@ "label": "Температура", "widget": "anydata", "after": "°С", - "icon": "thermometer" + "icon": "thermometer", + "font": "OCR A Std", + "color": [ + { + "level": -20, + "value": "#0000CC" + }, + { + "level": -10, + "value": "#0000CC" + }, + { + "level": 0, + "value": "#0000CC" + }, + { + "level": 12, + "value": "#3366FF" + }, + { + "level": 16, + "value": "#33CCFF" + }, + { + "level": 18, + "value": "#009933" + }, + { + "level": 30, + "value": "#FF9900" + }, + { + "level": 40, + "value": "red" + } + ] }, { "name": "anydataMm", @@ -225,7 +278,7 @@ }, { "name": "anydatamWt", - "label": "миллиВатты", + "label": "миллиВатты", "widget": "anydata", "after": "mWt", "icon": "speedometer" diff --git a/myProfile.json b/myProfile.json index 8bfe873d..17ee601d 100644 --- a/myProfile.json +++ b/myProfile.json @@ -136,6 +136,10 @@ "path": "src/modules/sensors/Hx711", "active": false }, + { + "path": "src/modules/sensors/Impulse", + "active": true + }, { "path": "src/modules/sensors/Ina219", "active": false diff --git a/platformio.ini b/platformio.ini index 7ba76a98..fcc0ec51 100644 --- a/platformio.ini +++ b/platformio.ini @@ -332,6 +332,7 @@ build_src_filter = + + + + + + + + diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 4de43be5..12480f10 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -14,6 +14,7 @@ void* getAPI_Bme280(String subtype, String params); void* getAPI_Bmp280(String subtype, String params); void* getAPI_Dht1122(String subtype, String params); void* getAPI_Ds18b20(String subtype, String params); +void* getAPI_Impulse(String subtype, String params); void* getAPI_Pzem004(String subtype, String params); void* getAPI_RTC(String subtype, String params); void* getAPI_Sht20(String subtype, String params); @@ -47,6 +48,7 @@ if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Impulse(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pzem004(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_RTC(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI; diff --git a/src/modules/exec/Multitouch/Multitouch.cpp b/src/modules/exec/Multitouch/Multitouch.cpp index 9e6b30ba..383d5be4 100644 --- a/src/modules/exec/Multitouch/Multitouch.cpp +++ b/src/modules/exec/Multitouch/Multitouch.cpp @@ -6,23 +6,22 @@ extern IoTGpio IoTgpio; class Multitouch : public IoTItem { private: - int _pin; int _int; - int _inv; - String _pinMode; - int _lastButtonState = LOW; - unsigned long _lastDebounceTime = 0; unsigned long timing; - long _debounceDelay = 50; long _PWMDelay = 500; - int _buttonState; - int _reading; int _count = 0; int duration = 0; + int _pin; + bool _execLevel, _fixState, _inv, _buttonState, _reading; + bool _lastButtonState = LOW; + unsigned long _lastDebounceTime = 0; + int _debounceDelay = 50; + public: Multitouch(String parameters) : IoTItem(parameters) { + String _pinMode; jsonRead(parameters, "pin", _pin); jsonRead(parameters, "pinMode", _pinMode); jsonRead(parameters, "debounceDelay", _debounceDelay); @@ -31,15 +30,20 @@ public: jsonRead(parameters, "inv", _inv); _round = 0; - IoTgpio.pinMode(_pin, INPUT); - if (_pinMode == "INPUT_PULLUP") - IoTgpio.digitalWrite(_pin, HIGH); - else if (_pinMode == "INPUT_PULLDOWN") + if (_pinMode == F("INPUT")) + IoTgpio.pinMode(_pin, INPUT); + else if (_pinMode == F("INPUT_PULLUP")) + IoTgpio.pinMode(_pin, INPUT_PULLUP); + else if (_pinMode == F("INPUT_PULLDOWN")) + { + IoTgpio.pinMode(_pin, INPUT); IoTgpio.digitalWrite(_pin, LOW); + } value.valD = _buttonState = IoTgpio.digitalRead(_pin); // сообщаем всем о стартовом статусе без генерации события regEvent(_buttonState, "", false, false); + SerialPrint("I", F("Multitouch"), "_buttonState " + String(_buttonState)); } void loop() @@ -49,35 +53,34 @@ public: { _lastDebounceTime = millis(); } - if ((millis() - _lastDebounceTime) > _debounceDelay) { - if (millis() - timing > _int && _reading == _inv && millis() - _lastDebounceTime > _PWMDelay) - { - timing = millis(); - duration = millis() - _lastDebounceTime - _PWMDelay; - value.valD = duration / 50; - regEvent(value.valD, "Multitouch"); - _count = -1; - } - if (_reading != _buttonState) { - _buttonState = _reading; _count++; duration = 0; + _buttonState = _reading; } - if (1 < _count && millis() > _lastDebounceTime + _PWMDelay) { value.valD = _count / 2; - regEvent(value.valD, "Multitouch"); + regEvent(value.valD, F("Multitouch")); _count = 0; } + + if (millis() - timing > _int && _reading == _inv && millis() - _lastDebounceTime > _PWMDelay) + { + SerialPrint("I", F("Multitouch"), "Считаем задержку"); + timing = millis(); + duration = millis() - _lastDebounceTime - _PWMDelay; + value.valD = duration / _int + 1; + regEvent(value.valD, F("Multitouch")); + _count = -1; + } } + _lastButtonState = _reading; } - ~Multitouch(){}; }; diff --git a/src/modules/exec/Multitouch/modinfo.json b/src/modules/exec/Multitouch/modinfo.json index b83a1f9e..d596113e 100644 --- a/src/modules/exec/Multitouch/modinfo.json +++ b/src/modules/exec/Multitouch/modinfo.json @@ -25,7 +25,7 @@ "authorGit": "https://github.com/avaksru", "specialThanks": "", "moduleName": "Multitouch", - "moduleVersion": "1.0", + "moduleVersion": "2.0", "usedRam": { "esp32_4mb": 15, "esp8266_4mb": 15 @@ -48,8 +48,6 @@ "esp8266_1mb": [], "esp8266_1mb_ota": [], "esp8285_1mb": [], - "esp8285_1mb_ota": [], - "esp8266_2mb": [], - "esp8266_2mb_ota": [] + "esp8285_1mb_ota": [] } } diff --git a/src/modules/sensors/Impulse/Impulse.cpp b/src/modules/sensors/Impulse/Impulse.cpp new file mode 100644 index 00000000..e84a1123 --- /dev/null +++ b/src/modules/sensors/Impulse/Impulse.cpp @@ -0,0 +1,87 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +extern IoTGpio IoTgpio; + +class Impulse : public IoTItem +{ +private: + int _int; + int _pin; + bool _buttonState, _reading; + bool _lastButtonState = LOW; + unsigned long _lastDebounceTime = 0; + int _debounceDelay = 50; + int _count = 0; + unsigned long timing; + +public: + Impulse(String parameters) : IoTItem(parameters) + { + String _pinMode; + jsonRead(parameters, F("pin"), _pin); + jsonRead(parameters, F("pinMode"), _pinMode); + jsonRead(parameters, F("debounceDelay"), _debounceDelay); + jsonRead(parameters, "int", _int); + _round = 0; + + if (_pinMode == F("INPUT")) + IoTgpio.pinMode(_pin, INPUT); + else if (_pinMode == F("INPUT_PULLUP")) + IoTgpio.pinMode(_pin, INPUT_PULLUP); + else if (_pinMode == F("INPUT_PULLDOWN")) + { + IoTgpio.pinMode(_pin, INPUT); + IoTgpio.digitalWrite(_pin, LOW); + } + + value.valD = _buttonState = IoTgpio.digitalRead(_pin); + regEvent(_buttonState, "", false, false); + } + + void loop() + { + _reading = IoTgpio.digitalRead(_pin); + if (_reading != _lastButtonState) + { + + _lastDebounceTime = millis(); + } + + if ((millis() - _lastDebounceTime) > _debounceDelay) + { + if (_reading != _buttonState) + { + _buttonState = _reading; + _count++; + } + if (_count == 1) + { + timing = millis(); + } + if (millis() - timing > _int * 1000 && _count > 1) + { + timing = millis(); + value.valD = _count; + regEvent(value.valD, F("Impulse")); + _count = 0; + } + } + + _lastButtonState = _reading; + } + + ~Impulse(){}; +}; + +void *getAPI_Impulse(String subtype, String param) +{ + if (subtype == F("Impulse")) + { + return new Impulse(param); + } + else + { + return nullptr; + } +} diff --git a/src/modules/sensors/Impulse/modinfo.json b/src/modules/sensors/Impulse/modinfo.json new file mode 100644 index 00000000..e35ecf29 --- /dev/null +++ b/src/modules/sensors/Impulse/modinfo.json @@ -0,0 +1,50 @@ +{ + "menuSection": "Сенсоры", + "configItem": [ + { + "global": 0, + "name": "Аналоговый счетчик импульсов", + "type": "Writing", + "subtype": "Impulse", + "id": "impulse", + "widget": "anydataDef", + "page": "Счетчики", + "descr": "Импульсов", + "needSave": 0, + "int": 1, + "pin": 16, + "pinMode": "INPUT", + "debounceDelay": 3, + "multiply": 1 + } + ], + "about": { + "authorName": "AVAKS", + "authorContact": "https://t.me/@avaks_dev", + "authorGit": "https://github.com/avaksru", + "specialThanks": "", + "moduleName": "Impulse", + "moduleVersion": "2.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Аналоговый счетчик импульсов. Датчик Холла ", + "moduleDesc": "Считает количество импульсов за период времени", + "propInfo": { + "int": "Период сбора импульсов в секундах", + "pin": "Укажите GPIO номер пина для чтения импульсов", + "pinMode": "Может быть INPUT_PULLUP INPUT_PULLDOWN INPUT", + "debounceDelay": "Время обработки дребезга (миллисекунд)" + } + }, + "defActive": true, + "usedLibs": { + "esp32_4mb": [], + "esp8266_4mb": [], + "esp8266_1mb": [], + "esp8266_1mb_ota": [], + "esp8285_1mb": [], + "esp8285_1mb_ota": [] + } +} \ No newline at end of file