mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
bug with virtual button fixed
This commit is contained in:
@@ -10,7 +10,7 @@ typedef std::vector<ButtonOut> MyButtonOutVector;
|
|||||||
class ButtonOut {
|
class ButtonOut {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ButtonOut(unsigned int pin, boolean inv, String key);
|
ButtonOut(String pin, boolean inv, String key);
|
||||||
|
|
||||||
~ButtonOut();
|
~ButtonOut();
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ class ButtonOut {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
unsigned int _pin;
|
String _pin;
|
||||||
boolean _inv;
|
boolean _inv;
|
||||||
String _key;
|
String _key;
|
||||||
|
|
||||||
|
|||||||
@@ -5,27 +5,31 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
//this class save data to flash
|
//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;
|
_pin = pin;
|
||||||
_inv = inv;
|
_inv = inv;
|
||||||
_key = key;
|
_key = key;
|
||||||
pinMode(_pin, OUTPUT);
|
if (_pin != "") {
|
||||||
|
pinMode(_pin.toInt(), OUTPUT);
|
||||||
|
}
|
||||||
int state = jsonReadInt(configStoreJson, key);
|
int state = jsonReadInt(configStoreJson, key);
|
||||||
this->execute(String(state));
|
this->execute(String(state));
|
||||||
}
|
}
|
||||||
ButtonOut::~ButtonOut() {}
|
ButtonOut::~ButtonOut() {}
|
||||||
|
|
||||||
void ButtonOut::execute(String state) {
|
void ButtonOut::execute(String state) {
|
||||||
|
if (state != "" && _pin != "") {
|
||||||
if (state == "change") {
|
if (state == "change") {
|
||||||
state = String(!digitalRead(_pin));
|
state = String(!digitalRead(_pin.toInt()));
|
||||||
digitalWrite(_pin, state.toInt());
|
digitalWrite(_pin.toInt(), state.toInt());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_inv) {
|
if (_inv) {
|
||||||
digitalWrite(_pin, !state.toInt());
|
digitalWrite(_pin.toInt(), !state.toInt());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
digitalWrite(_pin, state.toInt());
|
digitalWrite(_pin.toInt(), state.toInt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eventGen2(_key, state);
|
eventGen2(_key, state);
|
||||||
@@ -53,7 +57,7 @@ void buttonOut() {
|
|||||||
static bool firstTime = true;
|
static bool firstTime = true;
|
||||||
if (firstTime) myButtonOut = new MyButtonOutVector();
|
if (firstTime) myButtonOut = new MyButtonOutVector();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
myButtonOut->push_back(ButtonOut(pin.toInt(), invb, key));
|
myButtonOut->push_back(ButtonOut(pin, invb, key));
|
||||||
|
|
||||||
sCmd.addCommand(key.c_str(), buttonOutExecute);
|
sCmd.addCommand(key.c_str(), buttonOutExecute);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,13 @@ void inOutputExecute() {
|
|||||||
String key = sCmd.order();
|
String key = sCmd.order();
|
||||||
String value = sCmd.next();
|
String value = sCmd.next();
|
||||||
|
|
||||||
|
|
||||||
if (!isDigitStr(value)) { //если значение - текст
|
if (!isDigitStr(value)) { //если значение - текст
|
||||||
if (value.indexOf(":") == -1) { //если этот текст не время
|
if (value.indexOf(":") == -1) { //если этот текст не время
|
||||||
value = getValue(value);
|
String tmp = getValue(value);
|
||||||
|
if(tmp != "no value") {
|
||||||
|
value = tmp;
|
||||||
|
value.replace("#"," ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user