Merge pull request #152 from biveraxe/ver4dev

Добавляем кнопку физическую
This commit is contained in:
IoT Manager
2022-03-10 17:02:49 +01:00
committed by GitHub
6 changed files with 171 additions and 57 deletions

View File

@@ -46,9 +46,25 @@
"header": "Модули управления" "header": "Модули управления"
}, },
{ {
"name": "4. Кнопка управляющая пином (Реле с кнопкой)", "name": "4. Кнопка (подключенная физически)",
"num": 4, "num": 4,
"type": "Writing", "type": "Writing",
"subtype": "ButtonIn",
"id": "btn",
"widget": "toggle",
"page": "Кнопки",
"descr": "",
"int": 0,
"pin": 16,
"execLevel": "1",
"pinMode": "INPUT",
"debounceDelay": 50,
"fixState": 1
},
{
"name": "5. Кнопка управляющая пином (Реле с кнопкой)",
"num": 5,
"type": "Writing",
"subtype": "ButtonOut", "subtype": "ButtonOut",
"id": "btn", "id": "btn",
"widget": "toggle", "widget": "toggle",
@@ -62,8 +78,8 @@
"header": "Сенсоры" "header": "Сенсоры"
}, },
{ {
"name": "5. Датчик напряжения ADS1115", "name": "6. Датчик напряжения ADS1115",
"num": 5, "num": 6,
"type": "Reading", "type": "Reading",
"subtype": "Ads1115", "subtype": "Ads1115",
"id": "Ads3", "id": "Ads3",
@@ -79,8 +95,8 @@
"int": 10 "int": 10
}, },
{ {
"name": "6. Cенсор температуры AHT20", "name": "7. Cенсор температуры AHT20",
"num": 6, "num": 7,
"type": "Reading", "type": "Reading",
"subtype": "Aht20t", "subtype": "Aht20t",
"id": "Temp20", "id": "Temp20",
@@ -92,8 +108,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "7. Cенсор влажности AHT20", "name": "8. Cенсор влажности AHT20",
"num": 7, "num": 8,
"type": "Reading", "type": "Reading",
"subtype": "Aht20h", "subtype": "Aht20h",
"id": "Hum20", "id": "Hum20",
@@ -105,8 +121,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "8. Аналоговый сенсор", "name": "9. Аналоговый сенсор",
"num": 8, "num": 9,
"type": "Reading", "type": "Reading",
"subtype": "AnalogAdc", "subtype": "AnalogAdc",
"id": "t", "id": "t",
@@ -121,8 +137,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "9. Cенсор температуры Bme280", "name": "10. Cенсор температуры Bme280",
"num": 9, "num": 10,
"type": "Reading", "type": "Reading",
"subtype": "Bme280t", "subtype": "Bme280t",
"id": "tmp3", "id": "tmp3",
@@ -134,8 +150,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "10. Cенсор давления Bme280", "name": "11. Cенсор давления Bme280",
"num": 10, "num": 11,
"type": "Reading", "type": "Reading",
"subtype": "Bme280p", "subtype": "Bme280p",
"id": "Press3", "id": "Press3",
@@ -147,8 +163,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "11. Cенсор влажности Bme280", "name": "12. Cенсор влажности Bme280",
"num": 11, "num": 12,
"type": "Reading", "type": "Reading",
"subtype": "Bme280h", "subtype": "Bme280h",
"id": "Hum3", "id": "Hum3",
@@ -160,8 +176,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "12. Cенсор температуры Bmp280", "name": "13. Cенсор температуры Bmp280",
"num": 12, "num": 13,
"type": "Reading", "type": "Reading",
"subtype": "Bmp280t", "subtype": "Bmp280t",
"id": "tmp3", "id": "tmp3",
@@ -173,8 +189,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "13. Cенсор давления Bmp280", "name": "14. Cенсор давления Bmp280",
"num": 13, "num": 14,
"type": "Reading", "type": "Reading",
"subtype": "Bmp280p", "subtype": "Bmp280p",
"id": "Press3", "id": "Press3",
@@ -186,8 +202,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "14. Cенсор температуры dht11", "name": "15. Cенсор температуры dht11",
"num": 14, "num": 15,
"type": "Reading", "type": "Reading",
"subtype": "Dht1122t", "subtype": "Dht1122t",
"id": "tmp3", "id": "tmp3",
@@ -199,8 +215,8 @@
"senstype": "dht11" "senstype": "dht11"
}, },
{ {
"name": "15. Cенсор влажности dht11", "name": "16. Cенсор влажности dht11",
"num": 15, "num": 16,
"type": "Reading", "type": "Reading",
"subtype": "Dht1122h", "subtype": "Dht1122h",
"id": "Hum3", "id": "Hum3",
@@ -212,8 +228,8 @@
"senstype": "dht11" "senstype": "dht11"
}, },
{ {
"name": "16. Cенсор температуры ds18b20", "name": "17. Cенсор температуры ds18b20",
"num": 16, "num": 17,
"type": "Reading", "type": "Reading",
"subtype": "Ds18b20", "subtype": "Ds18b20",
"id": "dstmp", "id": "dstmp",
@@ -227,8 +243,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "17. Cенсор температуры GY21", "name": "18. Cенсор температуры GY21",
"num": 17, "num": 18,
"type": "Reading", "type": "Reading",
"subtype": "GY21t", "subtype": "GY21t",
"id": "tmp4", "id": "tmp4",
@@ -239,8 +255,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "18. Cенсор влажности GY21", "name": "19. Cенсор влажности GY21",
"num": 18, "num": 19,
"type": "Reading", "type": "Reading",
"subtype": "GY21h", "subtype": "GY21h",
"id": "Hum4", "id": "Hum4",
@@ -251,8 +267,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "19. Cенсор температуры HDC1080", "name": "20. Cенсор температуры HDC1080",
"num": 19, "num": 20,
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080t", "subtype": "Hdc1080t",
"id": "Temp1080", "id": "Temp1080",
@@ -264,8 +280,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "20. Cенсор влажности HDC1080", "name": "21. Cенсор влажности HDC1080",
"num": 20, "num": 21,
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080h", "subtype": "Hdc1080h",
"id": "Hum1080", "id": "Hum1080",
@@ -277,8 +293,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "21. Датчик CO2 MHZ-19 UART", "name": "22. Датчик CO2 MHZ-19 UART",
"num": 21, "num": 22,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19uart", "subtype": "Mhz19uart",
"id": "co2uart", "id": "co2uart",
@@ -296,8 +312,8 @@
"ABC": 1 "ABC": 1
}, },
{ {
"name": "22. Датчик CO2 MHZ-19 PWM", "name": "23. Датчик CO2 MHZ-19 PWM",
"num": 22, "num": 23,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19pwm", "subtype": "Mhz19pwm",
"id": "co2pwm", "id": "co2pwm",
@@ -311,8 +327,8 @@
"int": 300 "int": 300
}, },
{ {
"name": "23. Cенсор температуры от MHZ-19 UART", "name": "24. Cенсор температуры от MHZ-19 UART",
"num": 23, "num": 24,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19temp", "subtype": "Mhz19temp",
"id": "Mhz19temp", "id": "Mhz19temp",
@@ -328,8 +344,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "24. Рабочий диапазон от MHZ-19 UART", "name": "25. Рабочий диапазон от MHZ-19 UART",
"num": 24, "num": 25,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19range", "subtype": "Mhz19range",
"id": "Mhz19range", "id": "Mhz19range",
@@ -346,8 +362,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "25. Автокалибровка от MHZ-19 UART", "name": "26. Автокалибровка от MHZ-19 UART",
"num": 25, "num": 26,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19ABC", "subtype": "Mhz19ABC",
"id": "Mhz19ABC", "id": "Mhz19ABC",
@@ -361,8 +377,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "26. Датчик пыли SDS011 PM25", "name": "27. Датчик пыли SDS011 PM25",
"num": 26, "num": 27,
"type": "Reading", "type": "Reading",
"subtype": "Sds011_25", "subtype": "Sds011_25",
"id": "pmuart25", "id": "pmuart25",
@@ -379,8 +395,8 @@
"period": 300 "period": 300
}, },
{ {
"name": "27. Датчик пыли SDS011 PM10", "name": "28. Датчик пыли SDS011 PM10",
"num": 27, "num": 28,
"type": "Reading", "type": "Reading",
"subtype": "Sds011_10", "subtype": "Sds011_10",
"id": "pmuart10", "id": "pmuart10",
@@ -397,8 +413,8 @@
"period": 300 "period": 300
}, },
{ {
"name": "28. Cенсор температуры Sht20", "name": "29. Cенсор температуры Sht20",
"num": 28, "num": 29,
"type": "Reading", "type": "Reading",
"subtype": "Sht20t", "subtype": "Sht20t",
"id": "tmp2", "id": "tmp2",
@@ -409,8 +425,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "29. Cенсор влажности Sht20", "name": "30. Cенсор влажности Sht20",
"num": 29, "num": 30,
"type": "Reading", "type": "Reading",
"subtype": "Sht20h", "subtype": "Sht20h",
"id": "Hum2", "id": "Hum2",
@@ -424,8 +440,8 @@
"header": "Экраны" "header": "Экраны"
}, },
{ {
"name": "30. LCD экран 2004", "name": "31. LCD экран 2004",
"num": 30, "num": 31,
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -439,8 +455,8 @@
"id2show": "id датчика" "id2show": "id датчика"
}, },
{ {
"name": "31. LCD экран 1602", "name": "32. LCD экран 1602",
"num": 31, "num": 32,
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",

View File

@@ -11,7 +11,7 @@ class IoTItem {
public: public:
IoTItem(String parameters); IoTItem(String parameters);
virtual ~IoTItem() {} virtual ~IoTItem() {}
void loop(); virtual void loop();
virtual void doByInterval(); virtual void doByInterval();
virtual IoTValue execute(String command, std::vector<IoTValue> &param); virtual IoTValue execute(String command, std::vector<IoTValue> &param);

View File

@@ -3,6 +3,7 @@
void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params);
void* getAPI_SysExt(String subtype, String params); void* getAPI_SysExt(String subtype, String params);
void* getAPI_Variable(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_ButtonOut(String subtype, String params);
void* getAPI_Ads1115(String subtype, String params); void* getAPI_Ads1115(String subtype, String params);
void* getAPI_Aht20(String subtype, String params); void* getAPI_Aht20(String subtype, String params);
@@ -23,6 +24,7 @@ void* tmpAPI;
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Variable(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_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ads1115(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_Aht20(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -0,0 +1,77 @@
#include "Global.h"
#include "classes/IoTItem.h"
extern IoTGpio IoTgpio;
class ButtonIn : public IoTItem {
private:
int _pin;
bool _execLevel;
int _fixState;
String _pinMode;
int _lastButtonState = LOW;
unsigned long _lastDebounceTime = 0;
unsigned long _debounceDelay = 50;
int _buttonState;
int _reading;
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);
//Serial.printf("vvvvvvvvvvvvvvvv =%d \n", _fixState);
IoTgpio.pinMode(_pin, INPUT);
if (_pinMode == "INPUT_PULLUP") IoTgpio.digitalWrite(_pin, HIGH);
else if (_pinMode == "INPUT_PULLDOWN") IoTgpio.digitalWrite(_pin, LOW);
// TODO: загрузить значение из памяти иначе пока просто считываем значение текущего состояния PIN
_lastButtonState = _buttonState = IoTgpio.digitalRead(_pin);
}
void loop() {
_reading = IoTgpio.digitalRead(_pin);
if (_reading != _lastButtonState) {
// reset the debouncing timer
_lastDebounceTime = millis();
}
if ((millis() - _lastDebounceTime) > _debounceDelay) {
if (_reading != _buttonState) {
_buttonState = _reading;
if (_fixState == 1 && _buttonState == _execLevel) {
value.valD = !value.valD;
regEvent(value.valD, "ButtonIn");
}
if (_fixState == 2) {
value.valD = !value.valD;
regEvent(value.valD, "ButtonIn");
}
if (_fixState == 0) {
value.valD = _buttonState;
regEvent(value.valD, "ButtonIn");
}
}
}
_lastButtonState = _reading;
}
~ButtonIn() {};
};
void* getAPI_ButtonIn(String subtype, String param) {
if (subtype == F("ButtonIn")) {
return new ButtonIn(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,19 @@
[
{
"name": "Кнопка (подключенная физически)",
"num": 31,
"type": "Writing",
"subtype": "ButtonIn",
"id": "btn",
"widget": "toggle",
"page": "Кнопки",
"descr": "",
"int": 0,
"pin": 16,
"execLevel": "1",
"pinMode": "INPUT",
"debounceDelay": 50,
"fixState": 1
}
]

View File

@@ -91,7 +91,7 @@ bool jsonRead(String& json, String key, bool& value, bool e) {
} }
ret = false; ret = false;
} }
value = doc[key].as<bool>(); value = doc[key].as<int>();
return ret; return ret;
} }