Добавляем инверсию в кнопку подключенную к пину.

This commit is contained in:
2023-02-19 19:11:15 +03:00
parent bd4244bef3
commit f53a7341d8
5 changed files with 148 additions and 90 deletions

View File

@@ -257,7 +257,7 @@
"name": "17. BME280 Температура",
"type": "Reading",
"subtype": "Bme280t",
"id": "tmp3",
"id": "Tmp3",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
@@ -296,7 +296,21 @@
},
{
"global": 0,
"name": "20. BMP280 Температура",
"name": "20. BME280 Tочка росы",
"type": "Reading",
"subtype": "Bme280dp",
"id": "Dew3",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Точка росы",
"int": 15,
"addr": "0x77",
"round": 1,
"num": 20
},
{
"global": 0,
"name": "21. BMP280 Температура",
"type": "Reading",
"subtype": "Bmp280t",
"id": "tmp3",
@@ -306,11 +320,11 @@
"int": 15,
"addr": "0x77",
"round": 1,
"num": 20
"num": 21
},
{
"global": 0,
"name": "21. BMP280 Давление",
"name": "22. BMP280 Давление",
"type": "Reading",
"subtype": "Bmp280p",
"id": "Press3",
@@ -320,11 +334,11 @@
"int": 15,
"addr": "0x77",
"round": 1,
"num": 21
"num": 22
},
{
"global": 0,
"name": "22. DHT11 Температура",
"name": "23. DHT11 Температура",
"type": "Reading",
"subtype": "Dht1122t",
"id": "tmp3",
@@ -334,11 +348,11 @@
"int": 15,
"pin": 0,
"senstype": "dht11",
"num": 22
"num": 23
},
{
"global": 0,
"name": "23. DHT11 Влажность",
"name": "24. DHT11 Влажность",
"type": "Reading",
"subtype": "Dht1122h",
"id": "Hum3",
@@ -348,11 +362,11 @@
"int": 15,
"pin": 0,
"senstype": "dht11",
"num": 23
"num": 24
},
{
"global": 0,
"name": "24. DS18B20 Температура",
"name": "25. DS18B20 Температура",
"type": "Reading",
"subtype": "Ds18b20",
"id": "dstmp",
@@ -364,11 +378,11 @@
"index": 0,
"addr": "",
"round": 1,
"num": 24
"num": 25
},
{
"global": 0,
"name": "25. PZEM 004t Напряжение",
"name": "26. PZEM 004t Напряжение",
"type": "Reading",
"subtype": "Pzem004v",
"id": "v",
@@ -378,11 +392,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 25
"num": 26
},
{
"global": 0,
"name": "26. PZEM 004t Сила тока",
"name": "27. PZEM 004t Сила тока",
"type": "Reading",
"subtype": "Pzem004a",
"id": "a",
@@ -392,11 +406,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 26
"num": 27
},
{
"global": 0,
"name": "27. PZEM 004t Мощность",
"name": "28. PZEM 004t Мощность",
"type": "Reading",
"subtype": "Pzem004w",
"id": "w",
@@ -406,11 +420,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 27
"num": 28
},
{
"global": 0,
"name": "28. PZEM 004t Энергия",
"name": "29. PZEM 004t Энергия",
"type": "Reading",
"subtype": "Pzem004wh",
"id": "wh",
@@ -420,11 +434,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 28
"num": 29
},
{
"global": 0,
"name": "29. PZEM 004t Частота",
"name": "30. PZEM 004t Частота",
"type": "Reading",
"subtype": "Pzem004hz",
"id": "hz",
@@ -434,11 +448,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 29
"num": 30
},
{
"global": 0,
"name": "30. PZEM 004t Косинус",
"name": "31. PZEM 004t Косинус",
"type": "Reading",
"subtype": "Pzem004pf",
"id": "pf",
@@ -448,11 +462,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 30
"num": 31
},
{
"global": 0,
"name": "31. PZEM настройка",
"name": "32. PZEM настройка",
"type": "Reading",
"subtype": "Pzem004cmd",
"id": "set",
@@ -464,11 +478,31 @@
"changeaddr": 0,
"setaddr": "0x01",
"reset": 0,
"num": 31
"num": 32
},
{
"global": 0,
"name": "32. Sht20 Температура",
"name": "33. Часы реального времени",
"type": "Reading",
"subtype": "RTC",
"id": "rtc",
"widget": "anydataDef",
"page": "Таймеры",
"descr": "Время RTC",
"chipCode": 1,
"timeFormat": "d-m-Y H:i:s",
"RST": -1,
"CLK": -1,
"DAT": -1,
"ticker": 0,
"int": 5,
"btn-setUTime": "0",
"btn-setSysTime": "nil",
"num": 33
},
{
"global": 0,
"name": "34. Sht20 Температура",
"type": "Reading",
"subtype": "Sht20t",
"id": "tmp2",
@@ -477,11 +511,11 @@
"descr": "Температура",
"int": 15,
"round": 1,
"num": 32
"num": 34
},
{
"global": 0,
"name": "33. Sht20 Влажность",
"name": "35. Sht20 Влажность",
"type": "Reading",
"subtype": "Sht20h",
"id": "Hum2",
@@ -490,11 +524,11 @@
"descr": "Влажность",
"int": 15,
"round": 1,
"num": 33
"num": 35
},
{
"global": 0,
"name": "34. Sht30 Температура",
"name": "36. Sht30 Температура",
"type": "Reading",
"subtype": "Sht30t",
"id": "tmp30",
@@ -503,11 +537,11 @@
"descr": "SHT30 Температура",
"int": 15,
"round": 1,
"num": 34
"num": 36
},
{
"global": 0,
"name": "35. Sht30 Влажность",
"name": "37. Sht30 Влажность",
"type": "Reading",
"subtype": "Sht30h",
"id": "Hum30",
@@ -516,12 +550,12 @@
"descr": "SHT30 Влажность",
"int": 15,
"round": 1,
"num": 35
"num": 37
},
{
"global": 0,
"name": "36. HC-SR04 Ультразвуковой дальномер",
"num": 36,
"name": "38. HC-SR04 Ультразвуковой дальномер",
"num": 38,
"type": "Reading",
"subtype": "Sonar",
"id": "sonar",
@@ -533,7 +567,7 @@
"int": 5
},
{
"name": "37. UART",
"name": "39. UART",
"type": "Reading",
"subtype": "UART",
"page": "",
@@ -545,14 +579,14 @@
"line": 2,
"speed": 9600,
"eventFormat": 0,
"num": 37
"num": 39
},
{
"header": "Исполнительные устройства"
},
{
"global": 0,
"name": "38. Кнопка подключенная к пину",
"name": "40. Кнопка подключенная к пину",
"type": "Writing",
"subtype": "ButtonIn",
"id": "btn",
@@ -566,11 +600,12 @@
"pinMode": "INPUT",
"debounceDelay": 50,
"fixState": 0,
"num": 38
"inv": 0,
"num": 40
},
{
"global": 0,
"name": "39. Управление пином",
"name": "41. Управление пином",
"type": "Writing",
"subtype": "ButtonOut",
"needSave": 0,
@@ -581,11 +616,11 @@
"int": 0,
"inv": 0,
"pin": 2,
"num": 39
"num": 41
},
{
"global": 0,
"name": "40. Сервопривод",
"name": "42. Сервопривод",
"type": "Writing",
"subtype": "IoTServo",
"id": "servo",
@@ -596,11 +631,11 @@
"pin": 12,
"apin": -1,
"amap": "0, 4096, 0, 180",
"num": 40
"num": 42
},
{
"global": 0,
"name": "41. Расширитель портов Mcp23017",
"name": "43. Расширитель портов Mcp23017",
"type": "Reading",
"subtype": "Mcp23017",
"id": "Mcp",
@@ -610,11 +645,11 @@
"int": "0",
"addr": "0x20",
"index": 1,
"num": 41
"num": 43
},
{
"global": 0,
"name": "42. MP3 плеер",
"name": "44. MP3 плеер",
"type": "Reading",
"subtype": "Mp3",
"id": "mp3",
@@ -624,11 +659,11 @@
"int": 1,
"pins": "14,12",
"volume": 20,
"num": 42
"num": 44
},
{
"global": 0,
"name": "43. Сенсорная кнопка",
"name": "45. Сенсорная кнопка",
"type": "Writing",
"subtype": "Multitouch",
"id": "impulse",
@@ -642,11 +677,11 @@
"pinMode": "INPUT",
"debounceDelay": 50,
"PWMDelay": 500,
"num": 43
"num": 45
},
{
"global": 0,
"name": "44. Расширитель портов Pcf8574",
"name": "46. Расширитель портов Pcf8574",
"type": "Reading",
"subtype": "Pcf8574",
"id": "Pcf",
@@ -656,11 +691,11 @@
"int": "0",
"addr": "0x20",
"index": 1,
"num": 44
"num": 46
},
{
"global": 0,
"name": "45. PWM ESP8266",
"name": "47. PWM ESP8266",
"type": "Writing",
"subtype": "Pwm8266",
"id": "pwm",
@@ -672,11 +707,11 @@
"freq": 5000,
"val": 0,
"apin": -1,
"num": 45
"num": 47
},
{
"global": 0,
"name": "46. Телеграм-Лайт",
"name": "48. Телеграм-Лайт",
"type": "Writing",
"subtype": "TelegramLT",
"id": "tg",
@@ -685,14 +720,30 @@
"descr": "",
"token": "",
"chatID": "",
"num": 46
"num": 48
},
{
"header": "Экраны"
},
{
"global": 0,
"name": "47. LCD экран 2004",
"name": "49. LCD Dwin экран",
"type": "Reading",
"subtype": "DwinI",
"id": "dwin",
"widget": "",
"page": "",
"descr": "",
"int": 15,
"TX": 17,
"RX": 16,
"line": 2,
"speed": 115200,
"num": 49
},
{
"global": 0,
"name": "50. LCD экран 2004",
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -704,10 +755,10 @@
"size": "20,4",
"coord": "0,0",
"id2show": "id датчика",
"num": 47
"num": 50
},
{
"name": "48. LCD экран 1602",
"name": "51. LCD экран 1602",
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -719,6 +770,6 @@
"size": "16,2",
"coord": "0,0",
"id2show": "id датчика",
"num": 48
"num": 51
}
]

View File

@@ -249,7 +249,8 @@ lib_deps =
adafruit/Adafruit BME280 Library
adafruit/Adafruit BMP280 Library
beegee-tokyo/DHT sensor library for ESPx
milesburton/DallasTemperature@^3.9.1
https://github.com/milesburton/Arduino-Temperature-Control-Library
https://github.com/tremaru/iarduino_RTC
robtillaart/SHT2x@^0.1.1
WEMOS SHT3x@1.0.0
plerup/espsoftwareserial
@@ -274,6 +275,7 @@ build_src_filter =
+<modules/sensors/Dht1122>
+<modules/sensors/Ds18b20>
+<modules/sensors/Pzem004t>
+<modules/sensors/RTC>
+<modules/sensors/Sht20>
+<modules/sensors/Sht30>
+<modules/sensors/Sonar>
@@ -287,6 +289,7 @@ build_src_filter =
+<modules/exec/Pcf8574>
+<modules/exec/Pwm8266>
+<modules/exec/TelegramLT>
+<modules/display/DwinI>
+<modules/display/Lcd2004>
[env:esp32_4mb_fromitems]
@@ -295,7 +298,8 @@ lib_deps =
adafruit/Adafruit BME280 Library
adafruit/Adafruit BMP280 Library
beegee-tokyo/DHT sensor library for ESPx
milesburton/DallasTemperature@^3.9.1
https://github.com/milesburton/Arduino-Temperature-Control-Library
https://github.com/tremaru/iarduino_RTC
robtillaart/SHT2x@^0.1.1
WEMOS SHT3x@1.0.0
plerup/espsoftwareserial
@@ -311,6 +315,7 @@ build_src_filter =
+<modules/virtual/LogingDaily>
+<modules/virtual/Timer>
+<modules/virtual/Variable>
+<modules/virtual/VariableColor>
+<modules/virtual/VButton>
+<modules/sensors/Acs712>
+<modules/sensors/AhtXX>
@@ -320,6 +325,7 @@ build_src_filter =
+<modules/sensors/Dht1122>
+<modules/sensors/Ds18b20>
+<modules/sensors/Pzem004t>
+<modules/sensors/RTC>
+<modules/sensors/Sht20>
+<modules/sensors/Sht30>
+<modules/sensors/Sonar>
@@ -330,9 +336,9 @@ build_src_filter =
+<modules/exec/Mcp23017>
+<modules/exec/Mp3>
+<modules/exec/Multitouch>
+<modules/exec/MySensors>
+<modules/exec/Pcf8574>
+<modules/exec/Pwm32>
+<modules/exec/TelegramLT>
+<modules/display/DwinI>
+<modules/display/Lcd2004>

View File

@@ -15,6 +15,7 @@ void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(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);
void* getAPI_Sht30(String subtype, String params);
void* getAPI_Sonar(String subtype, String params);
@@ -28,6 +29,7 @@ void* getAPI_Multitouch(String subtype, String params);
void* getAPI_Pcf8574(String subtype, String params);
void* getAPI_Pwm8266(String subtype, String params);
void* getAPI_TelegramLT(String subtype, String params);
void* getAPI_DwinI(String subtype, String params);
void* getAPI_Lcd2004(String subtype, String params);
void* getAPI(String subtype, String params) {
@@ -47,6 +49,7 @@ 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_Pzem004(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_RTC(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI;
@@ -60,6 +63,7 @@ if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_DwinI(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
return nullptr;
}

View File

@@ -7,30 +7,29 @@ extern IoTGpio IoTgpio;
class ButtonIn : public IoTItem {
private:
int _pin;
bool _execLevel;
int _fixState;
String _pinMode;
int _lastButtonState = LOW;
bool _execLevel, _fixState, _inv, _buttonState, _reading;
bool _lastButtonState = LOW;
unsigned long _lastDebounceTime = 0;
long _debounceDelay = 50;
int _buttonState;
int _reading;
int _debounceDelay = 50;
public:
ButtonIn(String parameters): IoTItem(parameters) {
jsonRead(parameters, "pin", _pin);
jsonRead(parameters, "execLevel", _execLevel);
jsonRead(parameters, "pinMode", _pinMode);
jsonRead(parameters, "debounceDelay", _debounceDelay);
jsonRead(parameters, "fixState", _fixState);
_round = 0;
//Serial.printf("vvvvvvvvvvvvvvvv =%d \n", _fixState);
if (_pinMode == "INPUT") IoTgpio.pinMode(_pin, INPUT);
else if (_pinMode == "INPUT_PULLDOWN") {IoTgpio.pinMode(_pin, INPUT); IoTgpio.digitalWrite(_pin, LOW);}
else if (_pinMode == "INPUT_PULLUP") IoTgpio.pinMode(_pin, INPUT_PULLUP);
String _pinMode;
jsonRead(parameters, F("inv"), _inv);
jsonRead(parameters, F("pin"), _pin);
jsonRead(parameters, F("execLevel"), _execLevel);
jsonRead(parameters, F("pinMode"), _pinMode);
jsonRead(parameters, F("debounceDelay"), _debounceDelay);
jsonRead(parameters, F("fixState"), _fixState);
_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);
if (_inv) value.valD = _buttonState = !_buttonState; // инвертируем, если нужно показания
// сообщаем всем о стартовом статусе без генерации события
regEvent(_buttonState, "", false, false);
}
@@ -48,17 +47,13 @@ class ButtonIn : public IoTItem {
if (_fixState == 1 && _buttonState == _execLevel) {
value.valD = !value.valD;
regEvent(value.valD, "ButtonIn");
}
if (_fixState == 2) {
value.valD = !value.valD;
regEvent(value.valD, "ButtonIn");
regEvent(value.valD, F("ButtonIn"));
}
if (_fixState == 0) {
value.valD = _buttonState;
regEvent(value.valD, "ButtonIn");
if (_inv) value.valD = !_buttonState; // инвертируем, если нужно показания
regEvent(value.valD, F("ButtonIn"));
}
}
}
@@ -68,7 +63,7 @@ class ButtonIn : public IoTItem {
void setValue(const IoTValue& Value, bool genEvent = true) {
value = Value;
regEvent((String)(int)value.valD, "ButtonIn", false, genEvent);
regEvent((String)(int)value.valD, F("ButtonIn"), false, genEvent);
}
String getValue() {

View File

@@ -16,7 +16,8 @@
"execLevel": "1",
"pinMode": "INPUT",
"debounceDelay": 50,
"fixState": 0
"fixState": 0,
"inv": 0
}
],
"about": {
@@ -38,7 +39,8 @@
"execLevel": "Высокий 1 или низкий 0 уровень переключения состояния в режиме fixState = 1",
"pinMode": "Может быть INPUT_PULLUP INPUT_PULLDOWN INPUT",
"debounceDelay": "Время обработки дребезга",
"fixState": "Поведение входа, срабатывание на переходе или на фиксации уровня (триггерный режим)"
"fixState": "Поведение кнопки. При fixState = 0 - нет фиксации и значение кнопки повторяет уровень сигнала на входе. fixState = 1 - кнопка работает как переключатель и переключение происходит по высокому или низкому уровню сигнала (execLevel).",
"inv": "Инвертировать снимаемые показания на последнем этапе."
}
},
"defActive": true,