From 924b6a1e843e2282d4885ff7940465a712137f8e Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Fri, 31 Jul 2020 01:52:57 +0200 Subject: [PATCH] switch in progress --- include/Class/LineParsing.h | 8 ++++++- include/Class/Switch.h | 43 +++++++++++++++++++++++++++++++++++++ src/Cmd.cpp | 5 +++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 include/Class/Switch.h diff --git a/include/Class/LineParsing.h b/include/Class/LineParsing.h index aabdd3ec..7c124915 100644 --- a/include/Class/LineParsing.h +++ b/include/Class/LineParsing.h @@ -18,6 +18,7 @@ class LineParsing { String _c; String _inv; String _state; + String _db; public: LineParsing() : @@ -33,7 +34,8 @@ class LineParsing { _map{""}, _c{""}, _inv{""}, - _state{""} + _state{""}, + _db{""} {}; @@ -61,6 +63,9 @@ class LineParsing { if (arg.indexOf("st[") != -1) { _state = extractInner(arg); } + if (arg.indexOf("db[") != -1) { + _db = extractInner(arg); + } } } createWidgetClass(_descr, _page, _order, _file, _key); @@ -107,6 +112,7 @@ class LineParsing { _c = ""; _inv = ""; _state = ""; + _db = ""; } String extractInnerDigit(String str) { diff --git a/include/Class/Switch.h b/include/Class/Switch.h new file mode 100644 index 00000000..12d133aa --- /dev/null +++ b/include/Class/Switch.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include "Class/LineParsing.h" +#include "Global.h" + +class Switch : public LineParsing { + public: + Switch() : LineParsing(){}; + + void switchModeSet() { + if (_pin != "") { + pinMode(_pin.toInt(), INPUT); + } + } + + void switchStateSetDefault() { + if (_inv == "" && _state != "") { + switchChange(_key, _pin, _state, true); + } + } + + void switchStateSetInvDefault() { + if (_inv != "" && _state != "") { + switchChange(_key, _pin, _state, false); + } + } + + void switchChange(String key, String pin, String state, bool rev) { + int pinInt = pin.toInt(); + int stateInt; + if (rev) { + digitalWrite(pinInt, state.toInt()); + } else { + digitalWrite(pinInt, !state.toInt()); + } + eventGen(key, ""); + jsonWriteInt(configLiveJson, key, state.toInt()); + MqttClient::publishStatus(key, state); + } +}; + +extern Switch* mySwitch; \ No newline at end of file diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 1ab0e642..d54aef4d 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -156,8 +156,9 @@ void pwmSet() { myPwm->pwmChange(key, pin, state); } -//================================================================================================================== -//==========================================Модуль физической кнопки================================================ +//==========================================Модуль физических кнопок======================================== +//switch in switch1 toggle Кнопки Свет 1 pin[2] inv[1] db[20] +//========================================================================================================== void switch_() { int number = String(sCmd.next()).toInt(); int pin = String(sCmd.next()).toInt();