2020-11-15 01:44:25 +03:00
|
|
|
#include "items/vButtonOut.h"
|
2020-11-13 17:13:50 +03:00
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
#include "Class/LineParsing.h"
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "BufferExecute.h"
|
|
|
|
|
|
|
|
|
|
ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) {
|
|
|
|
|
_pin = pin;
|
|
|
|
|
_inv = inv;
|
|
|
|
|
_key = key;
|
|
|
|
|
pinMode(_pin, OUTPUT);
|
2020-11-15 01:44:25 +03:00
|
|
|
int state = jsonReadInt(configLiveJson, key);
|
|
|
|
|
this->execute(String(state));
|
2020-11-13 17:13:50 +03:00
|
|
|
}
|
2020-11-15 01:44:25 +03:00
|
|
|
ButtonOut::~ButtonOut() {}
|
2020-11-13 17:13:50 +03:00
|
|
|
|
|
|
|
|
void ButtonOut::execute(String state) {
|
2020-11-15 01:44:25 +03:00
|
|
|
if (state == "change") {
|
|
|
|
|
state = String(!digitalRead(_pin));
|
|
|
|
|
digitalWrite(_pin, state.toInt());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (_inv) {
|
|
|
|
|
digitalWrite(_pin, !state.toInt());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
digitalWrite(_pin, state.toInt());
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-13 17:13:50 +03:00
|
|
|
eventGen2(_key, state);
|
|
|
|
|
jsonWriteInt(configLiveJson, _key, state.toInt());
|
2020-11-15 01:44:25 +03:00
|
|
|
saveLive();
|
2020-11-13 17:13:50 +03:00
|
|
|
publishStatus(_key, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyButtonOutVector* myButtonOut = nullptr;
|
|
|
|
|
|
|
|
|
|
void buttonOut() {
|
|
|
|
|
myLineParsing.update();
|
|
|
|
|
String key = myLineParsing.gkey();
|
|
|
|
|
String pin = myLineParsing.gpin();
|
|
|
|
|
String inv = myLineParsing.ginv();
|
2020-11-15 01:44:25 +03:00
|
|
|
|
|
|
|
|
bool invb = false;
|
|
|
|
|
if (inv.toInt() == 1) invb = true;
|
|
|
|
|
|
2020-11-13 17:13:50 +03:00
|
|
|
myLineParsing.clear();
|
|
|
|
|
|
|
|
|
|
buttonOut_EnterCounter++;
|
|
|
|
|
addKey(key, buttonOut_KeyList, buttonOut_EnterCounter);
|
|
|
|
|
|
|
|
|
|
static bool firstTime = true;
|
|
|
|
|
if (firstTime) myButtonOut = new MyButtonOutVector();
|
|
|
|
|
firstTime = false;
|
2020-11-15 01:44:25 +03:00
|
|
|
myButtonOut->push_back(ButtonOut(pin.toInt(), invb, key));
|
2020-11-13 17:13:50 +03:00
|
|
|
|
|
|
|
|
sCmd.addCommand(key.c_str(), buttonOutExecute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buttonOutExecute() {
|
|
|
|
|
String key = sCmd.order();
|
|
|
|
|
String state = sCmd.next();
|
|
|
|
|
|
|
|
|
|
int number = getKeyNum(key, buttonOut_KeyList);
|
|
|
|
|
|
|
|
|
|
if (myButtonOut != nullptr) {
|
|
|
|
|
if (number != -1) {
|
|
|
|
|
myButtonOut->at(number).execute(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|