mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
@@ -304,7 +304,25 @@
|
|||||||
"page": "",
|
"page": "",
|
||||||
"descr": "",
|
"descr": "",
|
||||||
|
|
||||||
|
"int": "0",
|
||||||
"addr": "0x20",
|
"addr": "0x20",
|
||||||
"index": 1
|
"index": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"header": "Исполнительные устройства"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "23. Кнопка управляющая пином (Реле с кнопкой)",
|
||||||
|
"num": 23,
|
||||||
|
"type": "Writing",
|
||||||
|
"subtype": "ButtonOut",
|
||||||
|
"id": "btn",
|
||||||
|
"widget": "button",
|
||||||
|
"page": "Кнопки",
|
||||||
|
"descr": "",
|
||||||
|
"int": 0,
|
||||||
|
|
||||||
|
"inv": 0,
|
||||||
|
"pin": 2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -29,6 +29,7 @@ class IoTItem {
|
|||||||
IoTValue value; // хранение основного значения, котрое обновляется из сценария, execute(), loop() или doByInterval()
|
IoTValue value; // хранение основного значения, котрое обновляется из сценария, execute(), loop() или doByInterval()
|
||||||
|
|
||||||
virtual IoTGpio* getGpioDriver();
|
virtual IoTGpio* getGpioDriver();
|
||||||
|
virtual void setValue(IoTValue Value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String _subtype;
|
String _subtype;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void IoTGpio::analogWrite(uint8_t pin, int val) {
|
|||||||
if (_drivers[pinH]) _drivers[pinH]->analogWrite(pin - pinH*100, val);
|
if (_drivers[pinH]) _drivers[pinH]->analogWrite(pin - pinH*100, val);
|
||||||
else {
|
else {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
// todo: написать для esp32 аналог функции analogWrite
|
// TODO: написать для esp32 аналог функции analogWrite
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
::analogWrite(pin, val);
|
::analogWrite(pin, val);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ void IoTItem::regEvent(float value, String consoleInfo = "") {
|
|||||||
value = value / _round;
|
value = value / _round;
|
||||||
}
|
}
|
||||||
|
|
||||||
// value = (float)value / (_round ? pow(10, (int)_round) : 1); // todo: решить как указывать округление, количество знаков после запятой или десятые сотые ...
|
// value = (float)value / (_round ? pow(10, (int)_round) : 1); // TODO: решить как указывать округление, количество знаков после запятой или десятые сотые ...
|
||||||
}
|
}
|
||||||
if (_map1 != _map2) value = map(value, _map1, _map2, _map3, _map4);
|
if (_map1 != _map2) value = map(value, _map1, _map2, _map3, _map4);
|
||||||
|
|
||||||
@@ -90,4 +90,10 @@ IoTItem* myIoTItem;
|
|||||||
|
|
||||||
IoTGpio* IoTItem::getGpioDriver() {
|
IoTGpio* IoTItem::getGpioDriver() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IoTItem::setValue(IoTValue Value) {
|
||||||
|
value = Value;
|
||||||
|
if (value.isDecimal) regEvent(value.valD, "");
|
||||||
|
else regEvent(value.valS, "");
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,10 @@ public:
|
|||||||
VariableExprAST(const String &name, IoTItem* item) : Name(name), Item(item) {}
|
VariableExprAST(const String &name, IoTItem* item) : Name(name), Item(item) {}
|
||||||
|
|
||||||
int setValue(IoTValue *val) {
|
int setValue(IoTValue *val) {
|
||||||
Item->value = *val; // устанавливаем значение в связанном Item модуля напрямую
|
if (Item) {
|
||||||
|
//Item->value = *val; // устанавливаем значение в связанном Item модуля напрямую
|
||||||
|
Item->setValue(*val);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ void* getAPI_Lcd2004(String subtype, String params);
|
|||||||
void* getAPI_SysExt(String subtype, String params);
|
void* getAPI_SysExt(String subtype, String params);
|
||||||
void* getAPI_Ads1115(String subtype, String params);
|
void* getAPI_Ads1115(String subtype, String params);
|
||||||
void* getAPI_Mcp23017(String subtype, String params);
|
void* getAPI_Mcp23017(String subtype, String params);
|
||||||
|
void* getAPI_ButtonOut(String subtype, String params);
|
||||||
//============================================================================================
|
//============================================================================================
|
||||||
|
|
||||||
void* getAPI(String subtype, String params) {
|
void* getAPI(String subtype, String params) {
|
||||||
@@ -34,6 +35,7 @@ void* getAPI(String subtype, String params) {
|
|||||||
if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_SysExt(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_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||||
|
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
||||||
//================================================================================================================
|
//================================================================================================================
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Aht20t : public IoTItem {
|
|||||||
|
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
value.valD = temp.temperature;
|
value.valD = temp.temperature;
|
||||||
if (value.valD != -200) regEvent(value.valD, "Aht20t"); // todo: найти способ понимания ошибки получения данных
|
if (value.valD != -200) regEvent(value.valD, "Aht20t"); // TODO: найти способ понимания ошибки получения данных
|
||||||
else SerialPrint("E", "Sensor AHTt", "Error");
|
else SerialPrint("E", "Sensor AHTt", "Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class Aht20h : public IoTItem {
|
|||||||
|
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
value.valD = humidity.relative_humidity;
|
value.valD = humidity.relative_humidity;
|
||||||
if (value.valD != -200) regEvent(value.valD, "Aht20h"); // todo: найти способ понимания ошибки получения данных
|
if (value.valD != -200) regEvent(value.valD, "Aht20h"); // TODO: найти способ понимания ошибки получения данных
|
||||||
else SerialPrint("E", "Sensor AHTt", "Error");
|
else SerialPrint("E", "Sensor AHTt", "Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,21 +73,24 @@ class Bme280p : public IoTItem {
|
|||||||
~Bme280p();
|
~Bme280p();
|
||||||
};
|
};
|
||||||
|
|
||||||
void* getAPI_Bme280(String subtype, String param) {
|
|
||||||
String addr;
|
|
||||||
jsonRead(param, "addr", addr);
|
|
||||||
|
|
||||||
if (bmes.find(addr) == bmes.end()) {
|
void* getAPI_Bme280(String subtype, String param) {
|
||||||
bmes[addr] = new Adafruit_BME280();
|
if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) {
|
||||||
bmes[addr]->begin(hexStringToUint8(addr));
|
String addr;
|
||||||
}
|
jsonRead(param, "addr", addr);
|
||||||
|
|
||||||
if (subtype == F("Bme280t")) {
|
if (bmes.find(addr) == bmes.end()) {
|
||||||
return new Bme280t(bmes[addr], param);
|
bmes[addr] = new Adafruit_BME280();
|
||||||
} else if (subtype == F("Bme280h")) {
|
bmes[addr]->begin(hexStringToUint8(addr));
|
||||||
return new Bme280h(bmes[addr], param);
|
}
|
||||||
} else if (subtype == F("Bme280p")) {
|
|
||||||
return new Bme280p(bmes[addr], param);
|
if (subtype == F("Bme280t")) {
|
||||||
|
return new Bme280t(bmes[addr], param);
|
||||||
|
} else if (subtype == F("Bme280h")) {
|
||||||
|
return new Bme280h(bmes[addr], param);
|
||||||
|
} else if (subtype == F("Bme280p")) {
|
||||||
|
return new Bme280p(bmes[addr], param);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,18 +55,20 @@ class Bmp280p : public IoTItem {
|
|||||||
|
|
||||||
|
|
||||||
void* getAPI_Bmp280(String subtype, String param) {
|
void* getAPI_Bmp280(String subtype, String param) {
|
||||||
String addr;
|
if (subtype == F("Bmp280t") || subtype == F("Bmp280p")) {
|
||||||
jsonRead(param, "addr", addr);
|
String addr;
|
||||||
|
jsonRead(param, "addr", addr);
|
||||||
|
|
||||||
if (bmps.find(addr) == bmps.end()) {
|
if (bmps.find(addr) == bmps.end()) {
|
||||||
bmps[addr] = new Adafruit_BMP280();
|
bmps[addr] = new Adafruit_BMP280();
|
||||||
bmps[addr]->begin(hexStringToUint8(addr));
|
bmps[addr]->begin(hexStringToUint8(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtype == F("Bmp280t")) {
|
if (subtype == F("Bmp280t")) {
|
||||||
return new Bmp280t(bmps[addr], param);
|
return new Bmp280t(bmps[addr], param);
|
||||||
} else if (subtype == F("Bmp280p")) {
|
} else if (subtype == F("Bmp280p")) {
|
||||||
return new Bmp280p(bmps[addr], param);
|
return new Bmp280p(bmps[addr], param);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
58
src/modules/ButtonOut.cpp
Normal file
58
src/modules/ButtonOut.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "Global.h"
|
||||||
|
#include "classes/IoTItem.h"
|
||||||
|
|
||||||
|
extern IoTGpio IoTgpio;
|
||||||
|
|
||||||
|
|
||||||
|
class ButtonOut : public IoTItem {
|
||||||
|
private:
|
||||||
|
int _pin, _inv;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ButtonOut(String parameters): IoTItem(parameters) {
|
||||||
|
jsonRead(parameters, "pin", _pin);
|
||||||
|
jsonRead(parameters, "inv", _inv);
|
||||||
|
|
||||||
|
IoTgpio.pinMode(_pin, OUTPUT);
|
||||||
|
//TODO: прочитать состояние из памяти
|
||||||
|
IoTgpio.digitalWrite(_pin, LOW); // пока нет памяти, устанавливаем значение в ноль
|
||||||
|
value.valD = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void doByInterval() {
|
||||||
|
//value.valD = IoTgpio.analogRead(_pin);
|
||||||
|
|
||||||
|
//regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один
|
||||||
|
}
|
||||||
|
|
||||||
|
IoTValue execute(String command, std::vector<IoTValue> ¶m) {
|
||||||
|
// реакция на вызов команды модуля из сценария
|
||||||
|
// String command - имя команды после ID. (ID.Команда())
|
||||||
|
// param - вектор ("массив") значений параметров переданных вместе с командой: ID.Команда("пар1", 22, 33) -> param[0].ValS = "пар1", param[1].ValD = 22
|
||||||
|
|
||||||
|
if (command == "change") { // выполняем код при вызове спец команды из сценария: ID.reboot();
|
||||||
|
value.valD = !IoTgpio.digitalRead(_pin);
|
||||||
|
IoTgpio.digitalWrite(_pin, value.valD);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
|
||||||
|
}
|
||||||
|
|
||||||
|
void setValue(IoTValue Value) {
|
||||||
|
value = Value;
|
||||||
|
IoTgpio.digitalWrite(_pin, value.valD);
|
||||||
|
if (value.isDecimal) regEvent(value.valD, "ButtonOut");
|
||||||
|
else regEvent(value.valS, "ButtonOut");
|
||||||
|
}
|
||||||
|
//=======================================================================================================
|
||||||
|
|
||||||
|
~ButtonOut();
|
||||||
|
};
|
||||||
|
|
||||||
|
void* getAPI_ButtonOut(String subtype, String param) {
|
||||||
|
if (subtype == F("ButtonOut")) {
|
||||||
|
return new ButtonOut(param);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,25 +53,27 @@ class Dht1122h : public IoTItem {
|
|||||||
|
|
||||||
|
|
||||||
void* getAPI_Dht1122(String subtype, String param) {
|
void* getAPI_Dht1122(String subtype, String param) {
|
||||||
int pin;
|
if (subtype == F("Dht1122t") || subtype == F("Dht1122h")) {
|
||||||
String senstype;
|
int pin;
|
||||||
jsonRead(param, "pin", pin);
|
String senstype;
|
||||||
jsonRead(param, "senstype", senstype);
|
jsonRead(param, "pin", pin);
|
||||||
|
jsonRead(param, "senstype", senstype);
|
||||||
|
|
||||||
if (dhts.find(pin) == dhts.end()) {
|
if (dhts.find(pin) == dhts.end()) {
|
||||||
dhts[pin] = new DHTesp();
|
dhts[pin] = new DHTesp();
|
||||||
|
|
||||||
if (senstype == "dht11") {
|
if (senstype == "dht11") {
|
||||||
dhts[pin]->setup(pin, DHTesp::DHT11);
|
dhts[pin]->setup(pin, DHTesp::DHT11);
|
||||||
} else if (senstype == "dht22") {
|
} else if (senstype == "dht22") {
|
||||||
dhts[pin]->setup(pin, DHTesp::DHT22);
|
dhts[pin]->setup(pin, DHTesp::DHT22);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (subtype == F("Dht1122t")) {
|
if (subtype == F("Dht1122t")) {
|
||||||
return new Dht1122t(dhts[pin], param);
|
return new Dht1122t(dhts[pin], param);
|
||||||
} else if (subtype == F("Dht1122h")) {
|
} else if (subtype == F("Dht1122h")) {
|
||||||
return new Dht1122h(dhts[pin], param);
|
return new Dht1122h(dhts[pin], param);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class GY21t : public IoTItem {
|
|||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
//wire->read();
|
//wire->read();
|
||||||
value.valD = sensor->GY21_Temperature();
|
value.valD = sensor->GY21_Temperature();
|
||||||
if (value.valD < 300) regEvent(value.valD, "GY21"); // todo: найти способ понимания ошибки получения данных
|
if (value.valD < 300) regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных
|
||||||
else SerialPrint("E", "Sensor GY21t", "Error");
|
else SerialPrint("E", "Sensor GY21t", "Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ class GY21h : public IoTItem {
|
|||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
//sht->read();
|
//sht->read();
|
||||||
value.valD = sensor->GY21_Humidity();
|
value.valD = sensor->GY21_Humidity();
|
||||||
if (value.valD != 0) regEvent(value.valD, "GY21h"); // todo: найти способ понимания ошибки получения данных
|
if (value.valD != 0) regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных
|
||||||
else SerialPrint("E", "Sensor GY21h", "Error");
|
else SerialPrint("E", "Sensor GY21h", "Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,16 +42,18 @@ class GY21h : public IoTItem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void* getAPI_GY21(String subtype, String param) {
|
void* getAPI_GY21(String subtype, String param) {
|
||||||
|
if (subtype == F("GY21t") || subtype == F("GY21h")) {
|
||||||
if (!sensor) {
|
if (!sensor) {
|
||||||
sensor = new GY21;
|
sensor = new GY21;
|
||||||
if (sensor) Wire.begin(SDA, SCL);
|
if (sensor) Wire.begin(SDA, SCL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtype == F("GY21t")) {
|
if (subtype == F("GY21t")) {
|
||||||
return new GY21t(param);
|
return new GY21t(param);
|
||||||
} else if (subtype == F("GY21h")) {
|
} else if (subtype == F("GY21h")) {
|
||||||
return new GY21h(param);
|
return new GY21h(param);
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,6 @@ class Mcp23017 : public IoTItem, IoTGpio {
|
|||||||
void* getAPI_Mcp23017(String subtype, String param) {
|
void* getAPI_Mcp23017(String subtype, String param) {
|
||||||
if (subtype == F("Mcp23017")) {
|
if (subtype == F("Mcp23017")) {
|
||||||
String addr;
|
String addr;
|
||||||
uint8_t deviceAddress[1];
|
|
||||||
jsonRead(param, "addr", addr);
|
jsonRead(param, "addr", addr);
|
||||||
Serial.printf("deviceAddress %s = %02x \n", addr.c_str(), hexStringToUint8(addr));
|
Serial.printf("deviceAddress %s = %02x \n", addr.c_str(), hexStringToUint8(addr));
|
||||||
|
|
||||||
|
|||||||
@@ -37,16 +37,18 @@ class Sht20h : public IoTItem {
|
|||||||
|
|
||||||
|
|
||||||
void* getAPI_Sht20(String subtype, String param) {
|
void* getAPI_Sht20(String subtype, String param) {
|
||||||
|
if (subtype == F("Sht20t") || subtype == F("Sht20h")) {
|
||||||
if (!sht) {
|
if (!sht) {
|
||||||
sht = new SHT2x;
|
sht = new SHT2x;
|
||||||
if (sht) sht->begin();
|
if (sht) sht->begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtype == F("Sht20t")) {
|
if (subtype == F("Sht20t")) {
|
||||||
return new Sht20t(param);
|
return new Sht20t(param);
|
||||||
} else if (subtype == F("Sht20h")) {
|
} else if (subtype == F("Sht20h")) {
|
||||||
return new Sht20h(param);
|
return new Sht20h(param);
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user