switch in progress

This commit is contained in:
Dmitry Borisenko
2020-07-31 01:52:57 +02:00
parent f4a5bc0218
commit 924b6a1e84
3 changed files with 53 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ class LineParsing {
String _c; String _c;
String _inv; String _inv;
String _state; String _state;
String _db;
public: public:
LineParsing() : LineParsing() :
@@ -33,7 +34,8 @@ class LineParsing {
_map{""}, _map{""},
_c{""}, _c{""},
_inv{""}, _inv{""},
_state{""} _state{""},
_db{""}
{}; {};
@@ -61,6 +63,9 @@ class LineParsing {
if (arg.indexOf("st[") != -1) { if (arg.indexOf("st[") != -1) {
_state = extractInner(arg); _state = extractInner(arg);
} }
if (arg.indexOf("db[") != -1) {
_db = extractInner(arg);
}
} }
} }
createWidgetClass(_descr, _page, _order, _file, _key); createWidgetClass(_descr, _page, _order, _file, _key);
@@ -107,6 +112,7 @@ class LineParsing {
_c = ""; _c = "";
_inv = ""; _inv = "";
_state = ""; _state = "";
_db = "";
} }
String extractInnerDigit(String str) { String extractInnerDigit(String str) {

43
include/Class/Switch.h Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include <Arduino.h>
#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;

View File

@@ -156,8 +156,9 @@ void pwmSet() {
myPwm->pwmChange(key, pin, state); myPwm->pwmChange(key, pin, state);
} }
//================================================================================================================== //==========================================Модуль физических кнопок========================================
//==========================================Модуль физической кнопки================================================ //switch in switch1 toggle Кнопки Свет 1 pin[2] inv[1] db[20]
//==========================================================================================================
void switch_() { void switch_() {
int number = String(sCmd.next()).toInt(); int number = String(sCmd.next()).toInt();
int pin = String(sCmd.next()).toInt(); int pin = String(sCmd.next()).toInt();