diff --git a/data_svelte/items.json b/data_svelte/items.json index e4f24006..d712b55c 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -307,5 +307,22 @@ "int": "0", "addr": "0x20", "index": 1 + }, + { + "header": "Исполнительные устройства" + }, + { + "name": "23. Доп. функции системы", + "num": 23, + "type": "Writing", + "subtype": "ButtonOut", + "id": "btn", + "widget": "", + "page": "", + "descr": "", + "int": 0, + + "inv": 0, + "pin": 2 } ] \ No newline at end of file diff --git a/src/modules/API.cpp b/src/modules/API.cpp index e15fad73..3ee9b279 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -15,6 +15,7 @@ void* getAPI_Lcd2004(String subtype, String params); void* getAPI_SysExt(String subtype, String params); void* getAPI_Ads1115(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params); +void* getAPI_ButtonOut(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_Ads1115(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; diff --git a/src/modules/ButtonOut.cpp b/src/modules/ButtonOut.cpp new file mode 100644 index 00000000..d76e563a --- /dev/null +++ b/src/modules/ButtonOut.cpp @@ -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 ¶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; + } +}