bug with virtual button fixed

This commit is contained in:
Dmitry Borisenko
2020-12-10 02:11:47 +03:00
parent 253a9a5ae5
commit 81866043bc
3 changed files with 22 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ typedef std::vector<ButtonOut> MyButtonOutVector;
class ButtonOut {
public:
ButtonOut(unsigned int pin, boolean inv, String key);
ButtonOut(String pin, boolean inv, String key);
~ButtonOut();
@@ -18,7 +18,7 @@ class ButtonOut {
private:
unsigned int _pin;
String _pin;
boolean _inv;
String _key;

View File

@@ -5,27 +5,31 @@
#include <Arduino.h>
//this class save data to flash
ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) {
ButtonOut::ButtonOut(String pin, boolean inv, String key) {
_pin = pin;
_inv = inv;
_key = key;
pinMode(_pin, OUTPUT);
if (_pin != "") {
pinMode(_pin.toInt(), OUTPUT);
}
int state = jsonReadInt(configStoreJson, key);
this->execute(String(state));
}
ButtonOut::~ButtonOut() {}
void ButtonOut::execute(String state) {
if (state == "change") {
state = String(!digitalRead(_pin));
digitalWrite(_pin, state.toInt());
}
else {
if (_inv) {
digitalWrite(_pin, !state.toInt());
if (state != "" && _pin != "") {
if (state == "change") {
state = String(!digitalRead(_pin.toInt()));
digitalWrite(_pin.toInt(), state.toInt());
}
else {
digitalWrite(_pin, state.toInt());
if (_inv) {
digitalWrite(_pin.toInt(), !state.toInt());
}
else {
digitalWrite(_pin.toInt(), state.toInt());
}
}
}
eventGen2(_key, state);
@@ -53,7 +57,7 @@ void buttonOut() {
static bool firstTime = true;
if (firstTime) myButtonOut = new MyButtonOutVector();
firstTime = false;
myButtonOut->push_back(ButtonOut(pin.toInt(), invb, key));
myButtonOut->push_back(ButtonOut(pin, invb, key));
sCmd.addCommand(key.c_str(), buttonOutExecute);
}

View File

@@ -53,10 +53,13 @@ void inOutputExecute() {
String key = sCmd.order();
String value = sCmd.next();
if (!isDigitStr(value)) { //если значение - текст
if (value.indexOf(":") == -1) { //если этот текст не время
value = getValue(value);
String tmp = getValue(value);
if(tmp != "no value") {
value = tmp;
value.replace("#"," ");
}
}
}