From 1df87f8986c4389155d681438762ec208b272104 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sun, 20 Dec 2020 17:08:16 +0100 Subject: [PATCH] =?UTF-8?q?=D1=83=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=82=D0=B5=D0=BB=D0=B5=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=B0,=20=D0=B1=D0=B0=D0=B3=20=D1=81=D1=86?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B5=D0=B2....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/presets/presets.c.txt | 4 +-- data/presets/presets.s.txt | 10 +++---- include/Class/LineParsing.h | 59 +++++++++++++++++++------------------ include/Tests.h | 3 ++ src/Init.cpp | 2 +- src/ItemsList.cpp | 33 +++++++++++---------- src/Telegram.cpp | 42 ++++++++++++-------------- src/Tests.cpp | 12 ++++++++ src/main.cpp | 5 +++- 9 files changed, 93 insertions(+), 77 deletions(-) create mode 100644 include/Tests.h create mode 100644 src/Tests.cpp diff --git a/data/presets/presets.c.txt b/data/presets/presets.c.txt index 5db609f9..cd7fde4a 100644 --- a/data/presets/presets.c.txt +++ b/data/presets/presets.c.txt @@ -3,10 +3,10 @@ 0;inoutput;tUp1;inputDigit;Термостат1;Верхний#порог;3 0;inoutput;tLow1;inputDigit;Термостат1;Нижний#порог;4 0;button-out;btn1;toggle;Термостат1;Нагрев;5;pin[12]* -0;dallas-temp;t2;anydataTemp;Термостат2;Температура;1;pin[2];index[0];int[60] +0;dallas-temp;t2;anydataTemp;Термостат2;Температура;1;pin[2];index[0];int[10] 0;logging;log2;chart;Термостат2;История;2;val[t2];int[10];cnt[100] 0;inoutput;threshold;inputDigitTemp;Термостат2;Заданная#температура;3 -0;button-out;heater2;toggle;Термостат2;Нагреватель;7;pin[12] +0;button-out;heater2;toggle;Термостат2;Нагреватель;7;pin[5] 0;inoutput;time21;inputTimeClock;Расписание2;Утренний#период;8 0;inoutput;threshold1;inputDigitTemp;Расписание2;Температура;9 0;inoutput;time22;inputTimeClock;Расписание2;Дневной#период;10 diff --git a/data/presets/presets.s.txt b/data/presets/presets.s.txt index 0e36c7c1..d0ebb9fb 100644 --- a/data/presets/presets.s.txt +++ b/data/presets/presets.s.txt @@ -1,10 +1,10 @@ t1 > tUp1 btn1 0 -telegram нагрев#выключен 1 +telegram Гостинная нагрев#выключен end t1 < tLow1 btn1 1 -telegram нагрев#включен 1 +telegram Гостинная нагрев#включен end* t2 > threshold+-2 heater2 0 @@ -26,11 +26,11 @@ threshold threshold4 end* h3 > hUp3 hUp3 0 -telegram полив#выключен 1 +telegram Теплица полив#выключен end h3 < hLow3 hUp3 1 -telegram полив#включен 1 +telegram Теплица полив#включен end* timenow = time41 btn41 1 @@ -65,7 +65,7 @@ end* sensor = 1 text обнаружено time %date% -telegram text обнаружено#движение 1 +telegram often Обнаружено#движение end reset = 1 text не#обнаружено diff --git a/include/Class/LineParsing.h b/include/Class/LineParsing.h index 3edad798..f3553ad4 100644 --- a/include/Class/LineParsing.h +++ b/include/Class/LineParsing.h @@ -1,12 +1,13 @@ #pragma once #include -#include "ItemsList.h" + #include "Global.h" +#include "ItemsList.h" #include "Utils/JsonUtils.h" class LineParsing { -protected: + protected: String _key; String _file; String _page; @@ -28,31 +29,31 @@ protected: int pinErrors; -public: + public: LineParsing() : - _key{ "" }, - _file{ "" }, - _page{ "" }, - _descr{ "" }, - _order{ "" }, - _addr{ "" }, - _reg{ "" }, - _pin{ "" }, - _map{ "" }, - _c{ "" }, - _inv{ "" }, - _state{ "" }, - _db{ "" }, - _type{ "" }, - _int{ "" }, - _cnt{ "" }, - _val{ "" }, - _index{ "" }, + _key{""}, + _file{""}, + _page{""}, + _descr{""}, + _order{""}, + _addr{""}, + _reg{""}, + _pin{""}, + _map{""}, + _c{""}, + _inv{""}, + _state{""}, + _db{""}, + _type{""}, + _int{""}, + _cnt{""}, + _val{""}, + _index{""}, - pinErrors{ 0 } + pinErrors{0} - {}; + {}; void update() { //String order = sCmd.order(); @@ -110,9 +111,12 @@ public: } } - if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) { - pinErrors++; - _pin = ""; + if (_pin != "") { + if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) { + pinErrors++; + Serial.println("'" + _pin + "'"); + _pin = ""; + } } _page.replace("#", " "); @@ -123,7 +127,6 @@ public: createWidget(_descr, _page, _order, _file, _key); } - String gkey() { return _key; } @@ -176,7 +179,6 @@ public: return _index; } - int getPinErrors() { return pinErrors; } @@ -185,7 +187,6 @@ public: pinErrors = 0; } - void clear() { _key = ""; _file = ""; diff --git a/include/Tests.h b/include/Tests.h new file mode 100644 index 00000000..cfec2e53 --- /dev/null +++ b/include/Tests.h @@ -0,0 +1,3 @@ +#pragma once + +extern void testsPerform(); \ No newline at end of file diff --git a/src/Init.cpp b/src/Init.cpp index cf1c4248..3a17ef50 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -106,7 +106,7 @@ void deviceInit() { int errors = myLineParsing.getPinErrors(); - if (errors != 0) { + if (errors > 0) { jsonWriteStr(configSetupJson, F("warning3"), F("

Обнаружен неверный номер пина

")); } else { diff --git a/src/ItemsList.cpp b/src/ItemsList.cpp index a2f99028..aa046e99 100644 --- a/src/ItemsList.cpp +++ b/src/ItemsList.cpp @@ -1,7 +1,7 @@ #include "ItemsList.h" -#include "FileSystem.h" #include "Class/NotAsync.h" +#include "FileSystem.h" #include "Init.h" #include "Utils/StringUtils.h" @@ -20,7 +20,6 @@ void itemsListInit() { }, nullptr); - SerialPrint("I", F("Items"), F("Items Init")); } @@ -61,7 +60,6 @@ void addItem2(String param) { Serial.println(seachingLine); } - void addPreset2(int num) { File configFile = FileFS.open("/presets/presets.c.txt", "r"); if (!configFile) { @@ -76,8 +74,7 @@ void addPreset2(int num) { if (i1 == num) { if (i1 == 1) { config = "\n" + item; - } - else { + } else { config = item; } break; @@ -85,7 +82,7 @@ void addPreset2(int num) { } configFile.close(); addFile(DEVICE_CONFIG_FILE, config); - + //=========================================================================== File scenFile = FileFS.open("/presets/presets.s.txt", "r"); if (!scenFile) { return; @@ -97,18 +94,24 @@ void addPreset2(int num) { i2++; String item = scenFile.readStringUntil('*'); if (i2 == num) { - scen = item; + if (i1 == 1) { + scen = "\n" + item; + } else { + scen = item; + } break; } } scenFile.close(); if (readFile(String(DEVICE_SCENARIO_FILE), 2048) == "//") { removeFile(DEVICE_SCENARIO_FILE); + scen = deleteBeforeDelimiter(scen, "\n"); + addFile(DEVICE_SCENARIO_FILE, scen); + } else { + addFile(DEVICE_SCENARIO_FILE, scen); } - addFile(DEVICE_SCENARIO_FILE, scen); } - void delAllItems() { removeFile(DEVICE_CONFIG_FILE); addFile(DEVICE_CONFIG_FILE, String(firstLine)); @@ -129,24 +132,23 @@ uint8_t getNewElementNumber(String file) { uint8_t getFreePinAll() { #ifdef ESP8266 - uint8_t pins[] = { 0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5 }; + uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5}; #endif #ifdef ESP32 - uint8_t pins[] = { 0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5 }; + uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5}; #endif uint8_t array_sz = sizeof(pins) / sizeof(pins[0]); uint8_t i = getNewElementNumber("pins.txt"); if (i < array_sz) { return pins[i]; - } - else { + } else { return 0; } } bool isPinExist(unsigned int num) { bool ret = false; - unsigned int pins[] = { 0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16 }; + unsigned int pins[] = {0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16}; uint8_t array_sz = sizeof(pins) / sizeof(pins[0]); for (uint8_t i = 0; i < array_sz; i++) { if (pins[i] == num) ret = true; @@ -172,8 +174,7 @@ void delChoosingItems() { String item = configFile.readStringUntil('\n'); if (firstLine) { finalConf += item; - } - else { + } else { int checkbox = selectToMarker(item, ";").toInt(); if (checkbox == 0) { finalConf += "\n" + item; diff --git a/src/Telegram.cpp b/src/Telegram.cpp index af81e785..49b45e7d 100644 --- a/src/Telegram.cpp +++ b/src/Telegram.cpp @@ -1,13 +1,13 @@ #include "Consts.h" #ifdef telegramEnable -#include "Telegram.h" #include "BufferExecute.h" -CTBot* myBot{ nullptr }; +#include "Telegram.h" +CTBot* myBot{nullptr}; void telegramInit() { if (isTelegramEnabled()) { telegramInitBeen = true; - sCmd.addCommand("telegramEnable", sendTelegramMsg); + sCmd.addCommand("telegram", sendTelegramMsg); String token = jsonReadStr(configSetupJson, "telegramApi"); if (!myBot) { myBot = new CTBot(); @@ -16,8 +16,7 @@ void telegramInit() { myBot->enableUTF8Encoding(true); if (myBot->testConnection()) { SerialPrint("I", "Telegram", "Connected"); - } - else { + } else { SerialPrint("E", "Telegram", "Not connected"); } SerialPrint("I", F("Telegram"), F("Telegram Init")); @@ -53,36 +52,34 @@ void telegramMsgParse(String msg) { loopCmdAdd(String(msg) + ","); myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "order done"); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg)); - } - else if (msg.indexOf("get") != -1) { + } else if (msg.indexOf("get") != -1) { msg = deleteBeforeDelimiter(msg, "_"); - myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), getValue(msg)); //jsonReadStr(configLiveJson , msg)); + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), getValue(msg)); //jsonReadStr(configLiveJson , msg)); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg)); - } - else if (msg.indexOf("all") != -1) { + } else if (msg.indexOf("all") != -1) { String list = returnListOfParams(); myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), list); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + "\n" + list); - } - else { + } else { myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), F("Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value")); } } void sendTelegramMsg() { - String id = sCmd.next(); + String sabject = sCmd.next(); String msg = sCmd.next(); - msg.replace("#", " "); - if (id == "often") { + if (sabject == "often") { + msg.replace("#", " "); myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg); - } - else { - String prevMsg = jsonReadStr(telegramMsgJson, id); + } else { + String prevMsg = jsonReadStr(telegramMsgJson, sabject); if (prevMsg != msg) { - jsonWriteStr(telegramMsgJson, id, msg); - myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg); - SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg); + jsonWriteStr(telegramMsgJson, sabject, msg); + msg.replace("#", " "); + sabject.replace("#", " "); + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), sabject + " " + msg); + SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + sabject + " " + msg); } } } @@ -95,7 +92,6 @@ bool isTelegramInputOn() { return jsonReadBool(configSetupJson, "teleginput"); } - String returnListOfParams() { String cmdStr = readFile(DEVICE_CONFIG_FILE, 4096); cmdStr += "\r\n"; @@ -108,7 +104,7 @@ String returnListOfParams() { count++; if (count > 1) { String id = selectFromMarkerToMarker(buf, ";", 2); - String value = getValue(id); //jsonReadStr(configLiveJson , id); + String value = getValue(id); //jsonReadStr(configLiveJson , id); String page = selectFromMarkerToMarker(buf, ";", 4); page.replace("#", " "); String name = selectFromMarkerToMarker(buf, ";", 5); diff --git a/src/Tests.cpp b/src/Tests.cpp new file mode 100644 index 00000000..f64fe70e --- /dev/null +++ b/src/Tests.cpp @@ -0,0 +1,12 @@ +#include "Tests.h" + +#include "Global.h" +#include "ItemsList.h" + +void testsPerform() { + Serial.println("====some tests section===="); + + + + Serial.println("==========end============"); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index aeabdbd2..c4113bbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #include "Telegram.h" #include "SoftUART.h" #include "FileSystem.h" +#include "Tests.h" void not_async_actions(); @@ -67,7 +68,9 @@ void setup() { SsdpInit(); #endif getFSInfo(); - //esp_log_level_set("esp_littlefs", ESP_LOG_NONE); + + testsPerform(); + just_load = false; initialized = true; }