2020-11-17 01:01:42 +03:00
|
|
|
#include "items/vInOutput.h"
|
2020-11-15 01:44:25 +03:00
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
#include "Class/LineParsing.h"
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "BufferExecute.h"
|
2020-11-16 18:47:09 +03:00
|
|
|
//this class save date to flash
|
2020-11-17 01:01:42 +03:00
|
|
|
InOutput::InOutput(String key, String widget) {
|
2020-11-15 01:44:25 +03:00
|
|
|
_key = key;
|
2020-11-16 18:47:09 +03:00
|
|
|
String value = jsonReadStr(configStoreJson, key);
|
2020-11-15 02:46:27 +03:00
|
|
|
|
|
|
|
|
if (value == "") {
|
|
|
|
|
if (widget.indexOf("Digit") != -1) {
|
|
|
|
|
value = "52";
|
|
|
|
|
}
|
|
|
|
|
if (widget.indexOf("Time") != -1) {
|
|
|
|
|
value = "12:00";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 01:44:25 +03:00
|
|
|
this->execute(value);
|
|
|
|
|
}
|
2020-11-17 01:01:42 +03:00
|
|
|
InOutput::~InOutput() {}
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
void InOutput::execute(String value) {
|
2020-11-15 02:46:27 +03:00
|
|
|
eventGen2(_key, value);
|
2020-11-16 18:47:09 +03:00
|
|
|
jsonWriteStr(configStoreJson, _key, value);
|
|
|
|
|
saveStore();
|
2020-11-15 02:46:27 +03:00
|
|
|
publishStatus(_key, value);
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
MyInOutputVector* myInOutput = nullptr;
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
void inOutput() {
|
2020-11-15 01:44:25 +03:00
|
|
|
myLineParsing.update();
|
2020-11-15 02:46:27 +03:00
|
|
|
String widget = myLineParsing.gfile();
|
2020-11-15 01:44:25 +03:00
|
|
|
String key = myLineParsing.gkey();
|
|
|
|
|
myLineParsing.clear();
|
|
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
inOutput_EnterCounter++;
|
|
|
|
|
addKey(key, inOutput_KeyList, inOutput_EnterCounter);
|
2020-11-15 01:44:25 +03:00
|
|
|
|
|
|
|
|
static bool firstTime = true;
|
2020-11-17 01:01:42 +03:00
|
|
|
if (firstTime) myInOutput = new MyInOutputVector();
|
2020-11-15 01:44:25 +03:00
|
|
|
firstTime = false;
|
2020-11-17 01:01:42 +03:00
|
|
|
myInOutput->push_back(InOutput(key, widget));
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
sCmd.addCommand(key.c_str(), inOutputExecute);
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
|
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
void inOutputExecute() {
|
2020-11-15 01:44:25 +03:00
|
|
|
String key = sCmd.order();
|
2020-11-15 02:46:27 +03:00
|
|
|
String value = sCmd.next();
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-12-09 04:08:36 +03:00
|
|
|
|
|
|
|
|
if (!isDigitStr(value)) { //если значение - текст
|
|
|
|
|
if (value.indexOf(":") == -1) { //если этот текст не время
|
|
|
|
|
value = getValue(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
int number = getKeyNum(key, inOutput_KeyList);
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
if (myInOutput != nullptr) {
|
2020-11-15 01:44:25 +03:00
|
|
|
if (number != -1) {
|
2020-11-17 01:01:42 +03:00
|
|
|
myInOutput->at(number).execute(value);
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|