2020-11-15 01:44:25 +03:00
|
|
|
#include "items/vInput.h"
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
#include "Class/LineParsing.h"
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "BufferExecute.h"
|
|
|
|
|
|
2020-11-15 02:46:27 +03:00
|
|
|
Input::Input(String key, String widget) {
|
2020-11-15 01:44:25 +03:00
|
|
|
_key = key;
|
|
|
|
|
String value = jsonReadStr(configLiveJson, 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);
|
|
|
|
|
}
|
|
|
|
|
Input::~Input() {}
|
|
|
|
|
|
2020-11-15 02:46:27 +03:00
|
|
|
void Input::execute(String value) {
|
|
|
|
|
eventGen2(_key, value);
|
|
|
|
|
jsonWriteStr(configLiveJson, _key, value);
|
2020-11-15 01:44:25 +03:00
|
|
|
saveLive();
|
2020-11-15 02:46:27 +03:00
|
|
|
publishStatus(_key, value);
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyInputVector* myInput = nullptr;
|
|
|
|
|
|
|
|
|
|
void input() {
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
input_EnterCounter++;
|
|
|
|
|
addKey(key, input_KeyList, input_EnterCounter);
|
|
|
|
|
|
|
|
|
|
static bool firstTime = true;
|
|
|
|
|
if (firstTime) myInput = new MyInputVector();
|
|
|
|
|
firstTime = false;
|
2020-11-15 02:46:27 +03:00
|
|
|
myInput->push_back(Input(key, widget));
|
2020-11-15 01:44:25 +03:00
|
|
|
|
|
|
|
|
sCmd.addCommand(key.c_str(), inputExecute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void inputExecute() {
|
|
|
|
|
String key = sCmd.order();
|
2020-11-15 02:46:27 +03:00
|
|
|
String value = sCmd.next();
|
2020-11-15 01:44:25 +03:00
|
|
|
|
|
|
|
|
int number = getKeyNum(key, input_KeyList);
|
|
|
|
|
|
|
|
|
|
if (myInput != nullptr) {
|
|
|
|
|
if (number != -1) {
|
2020-11-15 02:46:27 +03:00
|
|
|
myInput->at(number).execute(value);
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|