From 94d93d3be61972bb6c44793466cf2d0276439c45 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sun, 15 Nov 2020 02:46:27 +0300 Subject: [PATCH] Working version --- data/set.device.json | 12 ++++++------ include/Consts.h | 6 +++++- include/Utils/TimeUtils.h | 4 +++- include/items/InputClass.h | 31 ------------------------------- include/items/vInput.h | 8 +++----- include/items/vLogging.h | 2 +- src/BufferExecute.cpp | 5 +---- src/ItemsList.cpp | 2 ++ src/Utils/TimeUtils.cpp | 16 +++++++++++++++- src/Web.cpp | 2 +- src/items/InputDigitClass.cpp | 19 ------------------- src/items/InputTimeClass.cpp | 32 -------------------------------- src/items/vInput.cpp | 27 +++++++++++++++++++-------- src/items/vLogging.cpp | 3 ++- 14 files changed, 58 insertions(+), 111 deletions(-) delete mode 100644 include/items/InputClass.h delete mode 100644 src/items/InputDigitClass.cpp delete mode 100644 src/items/InputTimeClass.cpp diff --git a/data/set.device.json b/data/set.device.json index b9874d8c..16c964c0 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -154,6 +154,12 @@ { "type": "hr" }, + { + "type": "button", + "title": "Очистить графики и сбросить введенные данные", + "action": "/set?cleanlog", + "class": "btn btn-block btn-default" + }, { "type": "link", "title": "Ручная настройка", @@ -166,12 +172,6 @@ "action": "https://github.com/IoTManagerProject/IoTManager/wiki", "class": "btn btn-block btn-default" }, - { - "type": "button", - "title": "Очистить графики и сбросить введенные данные", - "action": "/set?cleanlog", - "class": "btn btn-block btn-default" - }, { "type": "hr" }, diff --git a/include/Consts.h b/include/Consts.h index 31f52549..4e65e5e3 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -113,4 +113,8 @@ enum ConfigType_t { //13.11.2020 (SSDP OFF, UDP OFF) //RAM: [===== ] 46.6% (used 38208 bytes from 81920 bytes) -//Flash: [===== ] 54.2% (used 566388 bytes from 1044464 bytes) \ No newline at end of file +//Flash: [===== ] 54.2% (used 566388 bytes from 1044464 bytes) + +//15.11.2020 (SSDP OFF, UDP OFF) +//RAM: [===== ] 46.1% (used 37780 bytes from 81920 bytes) +//Flash: [===== ] 54.3% (used 566656 bytes from 1044464 bytes) \ No newline at end of file diff --git a/include/Utils/TimeUtils.h b/include/Utils/TimeUtils.h index d20286cf..024d1bc8 100644 --- a/include/Utils/TimeUtils.h +++ b/include/Utils/TimeUtils.h @@ -48,4 +48,6 @@ int getOffsetInMinutes(int timezone); /* * Разбивает время на составляющие */ -void breakEpochToTime(unsigned long epoch, Time_t& tm); \ No newline at end of file +void breakEpochToTime(unsigned long epoch, Time_t& tm); + +void handle_time_init(); \ No newline at end of file diff --git a/include/items/InputClass.h b/include/items/InputClass.h deleted file mode 100644 index ec7bce19..00000000 --- a/include/items/InputClass.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include -#include "Class/LineParsing.h" -#include "Global.h" - -//class InputClass : public LineParsing { -// public: -// InputClass() : LineParsing(){}; -// -// void inputSetDefaultFloat() { -// inputSetFloat(_key, _state); -// } -// -// void inputSetDefaultStr() { -// inputSetStr(_key, _state); -// } -// -// void inputSetFloat(String key, String state) { -// eventGen2(key, state); -// jsonWriteFloat(configLiveJson, key, state.toFloat()); -// publishStatus(key, state); -// } -// -// void inputSetStr(String key, String state) { -// eventGen2(key, state); -// jsonWriteStr(configLiveJson, key, state); -// publishStatus(key, state); -// } -//}; -// -//extern InputClass myInput; \ No newline at end of file diff --git a/include/items/vInput.h b/include/items/vInput.h index 9e465b52..52a6c80b 100644 --- a/include/items/vInput.h +++ b/include/items/vInput.h @@ -10,17 +10,15 @@ typedef std::vector MyInputVector; class Input { public: - Input(String key); - + Input(String key, String widget); ~Input(); - - void execute(String state); + + void execute(String value); private: String _key; - void addNewDelOldData(const String filename, size_t maxPoints, String payload); }; extern MyInputVector* myInput; diff --git a/include/items/vLogging.h b/include/items/vLogging.h index 9f8094c7..1fb3f09c 100644 --- a/include/items/vLogging.h +++ b/include/items/vLogging.h @@ -31,4 +31,4 @@ extern MyLoggingVector* myLogging; extern void choose_log_date_and_send(); extern void sendLogData(String file, String topic); -extern void clean_log_date(); +extern void cleanLogAndData(); diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index 901d9150..dcab1cd6 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -45,12 +45,9 @@ void csvCmdExecute(String& cmdStr) { else if (order == F("button-in")) { sCmd.addCommand(order.c_str(), buttonIn); } - else if (order == F("input-digit")) { + else if (order == F("input")) { sCmd.addCommand(order.c_str(), input); } - else if (order == F("input-time")) { - //sCmd.addCommand(order.c_str(), inputTime); - } else if (order == F("output-text")) { sCmd.addCommand(order.c_str(), textOut); } diff --git a/src/ItemsList.cpp b/src/ItemsList.cpp index d4d1cf8a..926eb313 100644 --- a/src/ItemsList.cpp +++ b/src/ItemsList.cpp @@ -68,6 +68,8 @@ void addPreset(String name) { void delAllItems() { removeFile(DEVICE_CONFIG_FILE); addFile(DEVICE_CONFIG_FILE, String(firstLine)); + removeFile(DEVICE_SCENARIO_FILE); + addFile(DEVICE_SCENARIO_FILE, "//"); removeFile("id.txt"); removeFile("order.txt"); removeFile("pins.txt"); diff --git a/src/Utils/TimeUtils.cpp b/src/Utils/TimeUtils.cpp index 2b313e69..5420b4a1 100644 --- a/src/Utils/TimeUtils.cpp +++ b/src/Utils/TimeUtils.cpp @@ -1,5 +1,5 @@ #include "Utils/TimeUtils.h" - +#include "Global.h" #include "Utils/StringUtils.h" static const uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; @@ -211,3 +211,17 @@ void breakEpochToTime(unsigned long epoch, Time_t& tm) { tm.day_of_month = time + 1; // day of month tm.valid = (epoch > MIN_DATETIME); } + +void handle_time_init() { + ts.add( + TIME, 1000, [&](void*) { + String timenow = timeNow->getTimeWOsec(); + static String prevTime; + if (prevTime != timenow) { + prevTime = timenow; + jsonWriteStr(configLiveJson, "timenow", timenow); + eventGen2("timenow", timenow); + } + }, + nullptr, true); +} diff --git a/src/Web.cpp b/src/Web.cpp index d3926cba..9b2a84e0 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -59,7 +59,7 @@ void web_init() { #ifdef LOGGING_ENABLED if (request->hasArg("cleanlog")) { - clean_log_date(); + cleanLogAndData(); request->send(200); } #endif diff --git a/src/items/InputDigitClass.cpp b/src/items/InputDigitClass.cpp deleted file mode 100644 index d9f1383a..00000000 --- a/src/items/InputDigitClass.cpp +++ /dev/null @@ -1,19 +0,0 @@ -//#include "BufferExecute.h" -//#include "items/InputClass.h" -////==========================================Модуль ввода цифровых значений================================== -////input-digit digit1 inputDigit Ввод Введите.цифру 4 st[60] -////========================================================================================================== -//InputClass myInputDigit; -//void inputDigit() { -// myInputDigit.update(); -// String key = myInputDigit.gkey(); -// sCmd.addCommand(key.c_str(), inputDigitSet); -// myInputDigit.inputSetDefaultFloat(); -// myInputDigit.clear(); -//} -// -//void inputDigitSet() { -// String key = sCmd.order(); -// String state = sCmd.next(); -// myInputDigit.inputSetFloat(key, state); -//} \ No newline at end of file diff --git a/src/items/InputTimeClass.cpp b/src/items/InputTimeClass.cpp deleted file mode 100644 index ae5ce8aa..00000000 --- a/src/items/InputTimeClass.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "BufferExecute.h" -#include "items/InputClass.h" -//==========================================Модуль ввода времени============================================ -//========================================================================================================== -//InputClass myInputTime; -//void inputTime() { -// myInputTime.update(); -// String key = myInputTime.gkey(); -// sCmd.addCommand(key.c_str(), inputTimeSet); -// myInputTime.inputSetDefaultStr(); -// myInputTime.clear(); -//} -// -//void inputTimeSet() { -// String key = sCmd.order(); -// String state = sCmd.next(); -// myInputTime.inputSetStr(key, state); -//} - -void handle_time_init() { - ts.add( - TIME, 1000, [&](void*) { - String timenow = timeNow->getTimeWOsec(); - static String prevTime; - if (prevTime != timenow) { - prevTime = timenow; - jsonWriteStr(configLiveJson, "timenow", timenow); - eventGen2("timenow", timenow); - } - }, - nullptr, true); -} \ No newline at end of file diff --git a/src/items/vInput.cpp b/src/items/vInput.cpp index 7689ff2a..7a71b472 100644 --- a/src/items/vInput.cpp +++ b/src/items/vInput.cpp @@ -6,24 +6,35 @@ #include "Global.h" #include "BufferExecute.h" -Input::Input(String key) { +Input::Input(String key, String widget) { _key = key; String value = jsonReadStr(configLiveJson, key); + + if (value == "") { + if (widget.indexOf("Digit") != -1) { + value = "52"; + } + if (widget.indexOf("Time") != -1) { + value = "12:00"; + } + } + this->execute(value); } Input::~Input() {} -void Input::execute(String state) { - eventGen2(_key, state); - jsonWriteInt(configLiveJson, _key, state.toInt()); +void Input::execute(String value) { + eventGen2(_key, value); + jsonWriteStr(configLiveJson, _key, value); saveLive(); - publishStatus(_key, state); + publishStatus(_key, value); } MyInputVector* myInput = nullptr; void input() { myLineParsing.update(); + String widget = myLineParsing.gfile(); String key = myLineParsing.gkey(); myLineParsing.clear(); @@ -33,20 +44,20 @@ void input() { static bool firstTime = true; if (firstTime) myInput = new MyInputVector(); firstTime = false; - myInput->push_back(Input(key)); + myInput->push_back(Input(key, widget)); sCmd.addCommand(key.c_str(), inputExecute); } void inputExecute() { String key = sCmd.order(); - String state = sCmd.next(); + String value = sCmd.next(); int number = getKeyNum(key, input_KeyList); if (myInput != nullptr) { if (number != -1) { - myInput->at(number).execute(state); + myInput->at(number).execute(value); } } } diff --git a/src/items/vLogging.cpp b/src/items/vLogging.cpp index 7777ef79..473fe5b0 100644 --- a/src/items/vLogging.cpp +++ b/src/items/vLogging.cpp @@ -112,7 +112,7 @@ void sendLogData(String file, String topic) { } } -void clean_log_date() { +void cleanLogAndData() { #ifdef ESP8266 auto dir = LittleFS.openDir("logs"); while (dir.next()) { @@ -121,5 +121,6 @@ void clean_log_date() { removeFile("logs/" + fname); } removeFile("live.json"); + configLiveJson = ""; #endif }