2020-09-02 22:34:49 +03:00
|
|
|
#include "Init.h"
|
2020-11-02 01:21:51 +03:00
|
|
|
#include "BufferExecute.h"
|
2020-11-01 04:48:35 +03:00
|
|
|
#include "Cmd.h"
|
|
|
|
|
#include "Global.h"
|
2020-11-15 01:44:25 +03:00
|
|
|
#include "items/vLogging.h"
|
|
|
|
|
#include "items/vImpulsOut.h"
|
|
|
|
|
#include "items/vButtonOut.h"
|
|
|
|
|
#include "items/vSensorDallas.h"
|
2020-11-17 01:01:42 +03:00
|
|
|
#include "items/vInOutput.h"
|
|
|
|
|
#include "items/vPwmOut.h"
|
2020-11-18 03:25:05 +03:00
|
|
|
#include "items/vCountDown.h"
|
2020-09-02 22:34:49 +03:00
|
|
|
|
|
|
|
|
void loadConfig() {
|
|
|
|
|
configSetupJson = readFile("config.json", 4096);
|
|
|
|
|
configSetupJson.replace("\r\n", "");
|
|
|
|
|
|
2020-11-16 18:47:09 +03:00
|
|
|
configStoreJson = readFile("store.json", 4096);
|
|
|
|
|
configStoreJson.replace("\r\n", "");
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
jsonWriteStr(configSetupJson, "warning1", "");
|
|
|
|
|
jsonWriteStr(configSetupJson, "warning2", "");
|
|
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
jsonWriteStr(configSetupJson, "chipID", chipId);
|
2020-09-17 21:33:54 +03:00
|
|
|
jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION);
|
2020-09-02 22:34:49 +03:00
|
|
|
|
|
|
|
|
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
|
|
|
|
|
|
|
|
|
|
Serial.println(configSetupJson);
|
2020-11-01 02:52:57 +03:00
|
|
|
|
|
|
|
|
serverIP = jsonReadStr(configSetupJson, "serverip");
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void all_init() {
|
|
|
|
|
Device_init();
|
|
|
|
|
loadScenario();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Device_init() {
|
2020-11-02 15:20:04 +03:00
|
|
|
|
2020-11-01 04:48:35 +03:00
|
|
|
sensorReadingMap10sec = "";
|
2020-11-02 15:20:04 +03:00
|
|
|
|
2020-11-03 19:07:22 +03:00
|
|
|
//======clear dallas params======
|
|
|
|
|
if (mySensorDallas2 != nullptr) {
|
|
|
|
|
mySensorDallas2->clear();
|
|
|
|
|
}
|
2020-11-02 15:20:04 +03:00
|
|
|
//======clear logging params======
|
2020-11-01 04:48:35 +03:00
|
|
|
if (myLogging != nullptr) {
|
|
|
|
|
myLogging->clear();
|
|
|
|
|
}
|
2020-11-02 01:21:51 +03:00
|
|
|
loggingKeyList = "";
|
2020-11-02 15:20:04 +03:00
|
|
|
//======clear impuls params=======
|
|
|
|
|
if (myImpulsOut != nullptr) {
|
|
|
|
|
myImpulsOut->clear();
|
|
|
|
|
}
|
2020-11-13 17:13:50 +03:00
|
|
|
impuls_KeyList = "";
|
|
|
|
|
impuls_EnterCounter = -1;
|
|
|
|
|
//======clear buttonOut params=======
|
|
|
|
|
if (myButtonOut != nullptr) {
|
|
|
|
|
myButtonOut->clear();
|
|
|
|
|
}
|
|
|
|
|
buttonOut_KeyList = "";
|
|
|
|
|
buttonOut_EnterCounter = -1;
|
2020-11-15 01:44:25 +03:00
|
|
|
//======clear input params=======
|
2020-11-17 01:01:42 +03:00
|
|
|
if (myInOutput != nullptr) {
|
|
|
|
|
myInOutput->clear();
|
|
|
|
|
}
|
|
|
|
|
inOutput_KeyList = "";
|
|
|
|
|
inOutput_EnterCounter = -1;
|
|
|
|
|
//======clear pwm params=======
|
|
|
|
|
if (myPwmOut != nullptr) {
|
|
|
|
|
myPwmOut->clear();
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
2020-11-17 01:01:42 +03:00
|
|
|
pwmOut_KeyList = "";
|
|
|
|
|
pwmOut_EnterCounter = -1;
|
2020-11-13 17:13:50 +03:00
|
|
|
//===================================
|
2020-11-18 03:25:05 +03:00
|
|
|
if (myCountDown != nullptr) {
|
|
|
|
|
myCountDown->clear();
|
|
|
|
|
}
|
|
|
|
|
countDown_KeyList = "";
|
|
|
|
|
countDown_EnterCounter = -1;
|
|
|
|
|
//===================================
|
2020-11-02 01:21:51 +03:00
|
|
|
|
2020-11-02 15:20:04 +03:00
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
#ifdef LAYOUT_IN_RAM
|
|
|
|
|
all_widgets = "";
|
|
|
|
|
#else
|
|
|
|
|
removeFile(String("layout.txt"));
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-09-04 18:58:03 +03:00
|
|
|
fileCmdExecute(String(DEVICE_CONFIG_FILE));
|
2020-09-02 22:34:49 +03:00
|
|
|
//outcoming_date();
|
|
|
|
|
}
|
|
|
|
|
//-------------------------------сценарии-----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void loadScenario() {
|
|
|
|
|
if (jsonReadStr(configSetupJson, "scen") == "1") {
|
|
|
|
|
scenario = readFile(String(DEVICE_SCENARIO_FILE), 2048);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uptime_init() {
|
|
|
|
|
ts.add(
|
|
|
|
|
UPTIME, 5000, [&](void*) {
|
|
|
|
|
handle_uptime();
|
|
|
|
|
},
|
|
|
|
|
nullptr, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_uptime() {
|
|
|
|
|
jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime());
|
|
|
|
|
}
|
|
|
|
|
|