From d6aab0cf949d0ea196cb376acdd9956e0f9595c4 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sun, 15 Nov 2020 01:44:25 +0300 Subject: [PATCH] Big changes. Compiling version --- data/items/button-out.inv.txt | 2 +- data/items/button-out.npin.txt | 2 +- data/items/button-out.pin.txt | 2 +- data/items/input-digit.txt | 2 +- data/items/input-time.txt | 2 +- data/items/output-text.txt | 2 +- data/items/pwm-out.txt | 2 +- data/presets/alloff.c.txt | 14 ++--- data/presets/dal.c.txt | 6 +-- data/presets/dht.c.txt | 6 +-- data/presets/rel.c.txt | 8 +-- data/set.device.json | 5 +- include/BufferExecute.h | 2 +- include/Consts.h | 1 + include/Global.h | 3 ++ include/Utils/JsonUtils.h | 4 +- include/items/ButtonOutClass.h | 41 -------------- include/items/InputClass.h | 52 +++++++++--------- include/items/{ButtonOut.h => vButtonOut.h} | 1 - .../items/{ImpulsOutClass.h => vImpulsOut.h} | 0 include/items/vInput.h | 29 ++++++++++ include/items/{Logging.h => vLogging.h} | 0 .../items/{SensorDallas.h => vSensorDallas.h} | 0 src/BufferExecute.cpp | 8 +-- src/Global.cpp | 3 ++ src/Init.cpp | 21 ++++++-- src/ItemsCmd.cpp | 4 +- src/MqttClient.cpp | 2 +- src/Utils/JsonUtils.cpp | 6 +++ src/Web.cpp | 2 +- src/items/ButtonOutClass.cpp | 23 -------- src/items/InputDigitClass.cpp | 38 ++++++------- src/items/InputTimeClass.cpp | 28 +++++----- src/items/{ButtonOut.cpp => vButtonOut.cpp} | 34 +++++++----- .../{ImpulsOutClass.cpp => vImpulsOut.cpp} | 2 +- src/items/vInput.cpp | 53 +++++++++++++++++++ src/items/{Logging.cpp => vLogging.cpp} | 3 +- .../{SensorDallas.cpp => vSensorDallas.cpp} | 2 +- src/main.cpp | 6 +-- 39 files changed, 238 insertions(+), 183 deletions(-) delete mode 100644 include/items/ButtonOutClass.h rename include/items/{ButtonOut.h => vButtonOut.h} (96%) rename include/items/{ImpulsOutClass.h => vImpulsOut.h} (100%) create mode 100644 include/items/vInput.h rename include/items/{Logging.h => vLogging.h} (100%) rename include/items/{SensorDallas.h => vSensorDallas.h} (100%) delete mode 100644 src/items/ButtonOutClass.cpp rename src/items/{ButtonOut.cpp => vButtonOut.cpp} (68%) rename src/items/{ImpulsOutClass.cpp => vImpulsOut.cpp} (98%) create mode 100644 src/items/vInput.cpp rename src/items/{Logging.cpp => vLogging.cpp} (98%) rename src/items/{SensorDallas.cpp => vSensorDallas.cpp} (97%) diff --git a/data/items/button-out.inv.txt b/data/items/button-out.inv.txt index fd3bdead..5499a108 100644 --- a/data/items/button-out.inv.txt +++ b/data/items/button-out.inv.txt @@ -1 +1 @@ -0;button-out;id;toggle;Кнопки;Освещение;order;pin;inv[1];st[1] \ No newline at end of file +0;button-out;id;toggle;Кнопки;Освещение;order;pin;inv[1] \ No newline at end of file diff --git a/data/items/button-out.npin.txt b/data/items/button-out.npin.txt index 33bb17da..ecffd881 100644 --- a/data/items/button-out.npin.txt +++ b/data/items/button-out.npin.txt @@ -1 +1 @@ -0;button-out;id;toggle;Кнопки;Освещение;order;st[0] \ No newline at end of file +0;button-out;id;toggle;Кнопки;Освещение;order \ No newline at end of file diff --git a/data/items/button-out.pin.txt b/data/items/button-out.pin.txt index 81310f4e..b0645025 100644 --- a/data/items/button-out.pin.txt +++ b/data/items/button-out.pin.txt @@ -1 +1 @@ -0;button-out;id;toggle;Кнопки;Освещение;order;pin;st[0] \ No newline at end of file +0;button-out;id;toggle;Кнопки;Освещение;order;pin \ No newline at end of file diff --git a/data/items/input-digit.txt b/data/items/input-digit.txt index bfb99882..65c39647 100644 --- a/data/items/input-digit.txt +++ b/data/items/input-digit.txt @@ -1 +1 @@ -0;input-digit;id;inputDigit;Ввод;Введите#цифру;order;st[60] \ No newline at end of file +0;input;id;inputDigit;Ввод;Введите#цифру;order \ No newline at end of file diff --git a/data/items/input-time.txt b/data/items/input-time.txt index 14c29d89..f5e69327 100644 --- a/data/items/input-time.txt +++ b/data/items/input-time.txt @@ -1 +1 @@ -0;input-time;id;inputTime;Ввод;Введите#время;order;st[10:00] \ No newline at end of file +0;input;id;inputTime;Ввод;Введите#время;order \ No newline at end of file diff --git a/data/items/output-text.txt b/data/items/output-text.txt index f96c2e26..900658f7 100644 --- a/data/items/output-text.txt +++ b/data/items/output-text.txt @@ -1 +1 @@ -0;output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено#движение] \ No newline at end of file +0;output-text;id;anydata;Вывод;Сигнализация;order \ No newline at end of file diff --git a/data/items/pwm-out.txt b/data/items/pwm-out.txt index 39a42037..2acbb459 100644 --- a/data/items/pwm-out.txt +++ b/data/items/pwm-out.txt @@ -1 +1 @@ -0;pwm-out;id;range;Ползунки;Яркость;order;pin;st[500] \ No newline at end of file +0;pwm-out;id;range;Ползунки;Яркость;order;pin \ No newline at end of file diff --git a/data/presets/alloff.c.txt b/data/presets/alloff.c.txt index b1327a8e..fe6b26ff 100644 --- a/data/presets/alloff.c.txt +++ b/data/presets/alloff.c.txt @@ -1,7 +1,7 @@ -0;button-out;button-out-1;toggle;Кнопки;Выключить#все;1;st[0] -0;button-out;button-out-2;toggle;Кнопки;Гостинная;2;pin[12];st[0] -0;button-out;button-out-3;toggle;Кнопки;Спальня;3;pin[13];st[0] -0;button-out;button-out-4;toggle;Кнопки;Прихожая;4;pin[14];st[0] -0;pwm-out;pwm-out-5;range;Кнопки;Яркость;5;pin[15];st[500] -0;pwm-out;pwm-out-6;range;Кнопки;Яркость;6;pin[16];st[500] -0;output-text;output-text-7;anydata;Кнопки;Статус;7;st[выключено] \ No newline at end of file +0;button-out;button-out-1;toggle;Кнопки;Выключить#все;1 +0;button-out;button-out-2;toggle;Кнопки;Гостинная;2;pin[12] +0;button-out;button-out-3;toggle;Кнопки;Спальня;3;pin[13] +0;button-out;button-out-4;toggle;Кнопки;Прихожая;4;pin[14] +0;pwm-out;pwm-out-5;range;Кнопки;Яркость;5;pin[15] +0;pwm-out;pwm-out-6;range;Кнопки;Яркость;6;pin[16] +0;output-text;output-text-7;anydata;Кнопки;Статус;7 \ No newline at end of file diff --git a/data/presets/dal.c.txt b/data/presets/dal.c.txt index 7cd73ce5..9433d86e 100644 --- a/data/presets/dal.c.txt +++ b/data/presets/dal.c.txt @@ -1,5 +1,5 @@ 0;dallas-temp;temp;anydataTemp;Термостат;Температура;1;pin[2];index[0];int[10] 0;logging;log;chart;Термостат;История;2;val[temp];int[60];cnt[100] -0;input-digit;inputU;inputDigit;Термостат;Верхний#порог;3;st[30] -0;input-digit;inputL;inputDigit;Термостат;Нижний#порог;4;st[20] -0;button-out;button;toggle;Термостат;Нагрев;5;pin[12];st[0] \ No newline at end of file +0;input;inputU;inputDigit;Термостат;Верхний#порог;3 +0;input;inputL;inputDigit;Термостат;Нижний#порог;4 +0;button-out;button;toggle;Термостат;Нагрев;5;pin[12] \ No newline at end of file diff --git a/data/presets/dht.c.txt b/data/presets/dht.c.txt index 35f8dd19..29195c1c 100644 --- a/data/presets/dht.c.txt +++ b/data/presets/dht.c.txt @@ -1,5 +1,5 @@ 0;dht-hum;hum;anydataHum;Теплица;Влажность;1;pin[2];type[dht11];c[1] 0;logging;log;chart;Теплица;История;2;val[hum];int[60];cnt[100] -0;input-digit;inputU;inputDigit;Теплица;Верхний#порог;3;st[45] -0;input-digit;inputL;inputDigit;Теплица;Нижний#порог;4;st[35] -0;button-out;button;toggle;Теплица;Полив;5;pin[12];st[0] \ No newline at end of file +0;input;inputU;inputDigit;Теплица;Верхний#порог;3 +0;input;inputL;inputDigit;Теплица;Нижний#порог;4 +0;button-out;button;toggle;Теплица;Полив;5;pin[12] \ No newline at end of file diff --git a/data/presets/rel.c.txt b/data/presets/rel.c.txt index af8550f0..faf94758 100644 --- a/data/presets/rel.c.txt +++ b/data/presets/rel.c.txt @@ -1,4 +1,4 @@ -0;button-out;button1;toggle;Реле;Освещение;1;pin[12];st[0] -0;button-out;button2;toggle;Реле;Освещение;2;pin[13];st[0] -0;input-time;T1;inputTime;Реле;Введите#время#включения;3;st[10:00] -0;input-time;T2;inputTime;Реле;Введите#время#выключения;4;st[11:00] \ No newline at end of file +0;button-out;button1;toggle;Реле;Освещение;1;pin[12] +0;button-out;button2;toggle;Реле;Освещение;2;pin[13] +0;input;T1;inputTime;Реле;Введите#время#включения;3 +0;input;T2;inputTime;Реле;Введите#время#выключения;4 \ No newline at end of file diff --git a/data/set.device.json b/data/set.device.json index 5a97f3f8..b9874d8c 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -56,7 +56,8 @@ "title": { "#": "Выберите элемент из списка", "/set?addItem=button-out.pin": "1.Кнопка управляющая пином", - "/set?addItem=button-out.npin": "2.Кнопка виртуальная", + "/set?addItem=button-out.inv": "2.Кнопка управляющая пином (с инверсией)", + "/set?addItem=button-out.npin": "3.Кнопка виртуальная", "/set?addItem=button-in": "4.Кнопка физическая", "/set?addItem=pwm-out": "3.Широтно импульсная модуляция pwm", "/set?addItem=input-digit": "5.Окно ввода цифровых значений", @@ -167,7 +168,7 @@ }, { "type": "button", - "title": "Очистить логи сенсоров", + "title": "Очистить графики и сбросить введенные данные", "action": "/set?cleanlog", "class": "btn btn-block btn-default" }, diff --git a/include/BufferExecute.h b/include/BufferExecute.h index 77996ee6..e77d36db 100644 --- a/include/BufferExecute.h +++ b/include/BufferExecute.h @@ -15,7 +15,7 @@ extern void pwmOutSet(); extern void buttonIn(); extern void buttonInSet(); -extern void inputDigit(); +extern void input(); extern void inputDigitSet(); extern void inputTime(); diff --git a/include/Consts.h b/include/Consts.h index e8e7f96d..31f52549 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -33,6 +33,7 @@ //#define LAYOUT_IN_RAM //#define UDP_ENABLED //#define SSDP_ENABLED +#define SAVE_SETTINGS_TO_FLASH //=========Sensors enable/disable================================================================================================================================= #define LEVEL_ENABLED diff --git a/include/Global.h b/include/Global.h index 12adbee7..fd0205f2 100644 --- a/include/Global.h +++ b/include/Global.h @@ -74,6 +74,9 @@ extern int impuls_EnterCounter; extern String buttonOut_KeyList; extern int buttonOut_EnterCounter; //========================================= +extern String input_KeyList; +extern int input_EnterCounter; +//========================================= // Sensors extern String sensorReadingMap10sec; diff --git a/include/Utils/JsonUtils.h b/include/Utils/JsonUtils.h index c244a14e..4f60503a 100644 --- a/include/Utils/JsonUtils.h +++ b/include/Utils/JsonUtils.h @@ -16,4 +16,6 @@ String jsonWriteFloat(String& json, String name, float value); String jsonWriteBool(String& json, String name, boolean value); -void saveConfig(); \ No newline at end of file +void saveConfig(); + +void saveLive(); \ No newline at end of file diff --git a/include/items/ButtonOutClass.h b/include/items/ButtonOutClass.h deleted file mode 100644 index dca5fadb..00000000 --- a/include/items/ButtonOutClass.h +++ /dev/null @@ -1,41 +0,0 @@ -//#pragma once -//#include -// -//#include "Class/LineParsing.h" -//#include "Global.h" -// -//class ButtonOutClass : public LineParsing { -//public: -// ButtonOutClass() : LineParsing() {}; -// -// void init() { -// if (_pin != "") { -// pinMode(_pin.toInt(), OUTPUT); -// } -// jsonWriteStr(configOptionJson, _key + "_pin", _pin); -// jsonWriteStr(configOptionJson, _key + "_inv", _inv); -// } -// -// void pinStateSetDefault() { -// pinChange(_key, _state); -// } -// -// -// void pinChange(String key, String state) { -// String pin = jsonReadStr(configOptionJson, key + "_pin"); -// String inv = jsonReadStr(configOptionJson, key + "_inv"); -// int pinInt = pin.toInt(); -// -// if (inv == "") { -// digitalWrite(pinInt, state.toInt()); -// } -// else { -// digitalWrite(pinInt, !state.toInt()); -// } -// eventGen2(key, state); -// jsonWriteInt(configLiveJson, key, state.toInt()); -// publishStatus(key, state); -// } -//}; -// -//extern ButtonOutClass myButtonOut; \ No newline at end of file diff --git a/include/items/InputClass.h b/include/items/InputClass.h index 447fccfe..ec7bce19 100644 --- a/include/items/InputClass.h +++ b/include/items/InputClass.h @@ -3,29 +3,29 @@ #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 +//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/ButtonOut.h b/include/items/vButtonOut.h similarity index 96% rename from include/items/ButtonOut.h rename to include/items/vButtonOut.h index 6d3a1863..bf918f8c 100644 --- a/include/items/ButtonOut.h +++ b/include/items/vButtonOut.h @@ -14,7 +14,6 @@ class ButtonOut { ~ButtonOut(); - void init(); void execute(String state); private: diff --git a/include/items/ImpulsOutClass.h b/include/items/vImpulsOut.h similarity index 100% rename from include/items/ImpulsOutClass.h rename to include/items/vImpulsOut.h diff --git a/include/items/vInput.h b/include/items/vInput.h new file mode 100644 index 00000000..9e465b52 --- /dev/null +++ b/include/items/vInput.h @@ -0,0 +1,29 @@ +#pragma once +#include + +#include "Global.h" + +class Input; + +typedef std::vector MyInputVector; + +class Input { + public: + + Input(String key); + + ~Input(); + + void execute(String state); + + private: + + String _key; + + void addNewDelOldData(const String filename, size_t maxPoints, String payload); +}; + +extern MyInputVector* myInput; + +extern void input(); +extern void inputExecute(); diff --git a/include/items/Logging.h b/include/items/vLogging.h similarity index 100% rename from include/items/Logging.h rename to include/items/vLogging.h diff --git a/include/items/SensorDallas.h b/include/items/vSensorDallas.h similarity index 100% rename from include/items/SensorDallas.h rename to include/items/vSensorDallas.h diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index 16584f2c..901d9150 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -1,7 +1,7 @@ #include "BufferExecute.h" // -#include "items/SensorDallas.h" -#include "items/ButtonOut.h" +#include "items/vSensorDallas.h" +#include "items/vButtonOut.h" // #include "Global.h" #include "Module/Terminal.h" @@ -46,10 +46,10 @@ void csvCmdExecute(String& cmdStr) { sCmd.addCommand(order.c_str(), buttonIn); } else if (order == F("input-digit")) { - sCmd.addCommand(order.c_str(), inputDigit); + sCmd.addCommand(order.c_str(), input); } else if (order == F("input-time")) { - sCmd.addCommand(order.c_str(), inputTime); + //sCmd.addCommand(order.c_str(), inputTime); } else if (order == F("output-text")) { sCmd.addCommand(order.c_str(), textOut); diff --git a/src/Global.cpp b/src/Global.cpp index 22731505..d8facc43 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -45,6 +45,9 @@ int impuls_EnterCounter = -1; String buttonOut_KeyList = ""; int buttonOut_EnterCounter = -1; //========================================= +String input_KeyList = ""; +int input_EnterCounter = -1; +//========================================= // Sensors String sensorReadingMap10sec; diff --git a/src/Init.cpp b/src/Init.cpp index fe97b678..36d98c21 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -2,16 +2,21 @@ #include "BufferExecute.h" #include "Cmd.h" #include "Global.h" -#include "items/Logging.h" -#include "items/ImpulsOutClass.h" -#include "items/ButtonOut.h" -#include "items/SensorDallas.h" +#include "items/vLogging.h" +#include "items/vImpulsOut.h" +#include "items/vButtonOut.h" +#include "items/vSensorDallas.h" +#include "items/vInput.h" void loadConfig() { configSetupJson = readFile("config.json", 4096); - //configSetupJson.replace(" ", ""); configSetupJson.replace("\r\n", ""); +#ifdef SAVE_SETTINGS_TO_FLASH + configLiveJson = readFile("live.json", 4096); + configLiveJson.replace("\r\n", ""); +#endif + jsonWriteStr(configSetupJson, "chipID", chipId); jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION); @@ -53,6 +58,12 @@ void Device_init() { } buttonOut_KeyList = ""; buttonOut_EnterCounter = -1; + //======clear input params======= + if (myInput != nullptr) { + myInput->clear(); + } + input_KeyList = ""; + input_EnterCounter = -1; //=================================== diff --git a/src/ItemsCmd.cpp b/src/ItemsCmd.cpp index be6330ac..cbac328a 100644 --- a/src/ItemsCmd.cpp +++ b/src/ItemsCmd.cpp @@ -7,7 +7,7 @@ //#include "Module/Terminal.h" //#include "Servo/Servos.h" // -//#include "items/SensorDallas.h" +//#include "items/vSensorDallas.h" // //Terminal *term = nullptr; // @@ -27,7 +27,7 @@ //sCmd.addCommand("pwm-out", pwmOut); //sCmd.addCommand("button-in", buttonIn); - //sCmd.addCommand("input-digit", inputDigit); + //sCmd.addCommand("input-digit", input); //sCmd.addCommand("input-time", inputTime); //sCmd.addCommand("output-text", textOut); diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index bbe52dc2..cdd18448 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -1,7 +1,7 @@ #include "MqttClient.h" #include -#include "items/Logging.h" +#include "items/vLogging.h" #include "Class/NotAsync.h" #include "Global.h" #include "Init.h" diff --git a/src/Utils/JsonUtils.cpp b/src/Utils/JsonUtils.cpp index 2389773c..fad6c937 100644 --- a/src/Utils/JsonUtils.cpp +++ b/src/Utils/JsonUtils.cpp @@ -53,4 +53,10 @@ String jsonWriteFloat(String& json, String name, float value) { void saveConfig() { writeFile(String("config.json"), configSetupJson); +} + +void saveLive() { +#ifdef SAVE_SETTINGS_TO_FLASH + writeFile(String("live.json"), configLiveJson); +#endif } \ No newline at end of file diff --git a/src/Web.cpp b/src/Web.cpp index cd90a2ca..d3926cba 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -3,7 +3,7 @@ #include "Global.h" #include "Init.h" #include "ItemsList.h" -#include "items/Logging.h" +#include "items/vLogging.h" #include "Telegram.h" bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) { diff --git a/src/items/ButtonOutClass.cpp b/src/items/ButtonOutClass.cpp deleted file mode 100644 index 5de6ca5e..00000000 --- a/src/items/ButtonOutClass.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//#include "items/ButtonOutClass.h" -// -//#include "BufferExecute.h" -////==========================================Модуль кнопок=================================================== -////button-out light toggle Кнопки Свет 1 pin[12] inv[1] st[1] -////========================================================================================================== -//ButtonOutClass myButtonOut; -//void buttonOut() { -// myButtonOut.update(); -// String key = myButtonOut.gkey(); -// String pin = myButtonOut.gpin(); -// String inv = myButtonOut.ginv(); -// sCmd.addCommand(key.c_str(), buttonOutSet); -// myButtonOut.init(); -// myButtonOut.pinStateSetDefault(); -// myButtonOut.clear(); -//} -// -//void buttonOutSet() { -// String key = sCmd.order(); -// String state = sCmd.next(); -// myButtonOut.pinChange(key, state); -//} diff --git a/src/items/InputDigitClass.cpp b/src/items/InputDigitClass.cpp index 1a2e3b38..d9f1383a 100644 --- a/src/items/InputDigitClass.cpp +++ b/src/items/InputDigitClass.cpp @@ -1,19 +1,19 @@ -#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 +//#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 index 9dc16dd4..ae5ce8aa 100644 --- a/src/items/InputTimeClass.cpp +++ b/src/items/InputTimeClass.cpp @@ -2,20 +2,20 @@ #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); -} +//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( diff --git a/src/items/ButtonOut.cpp b/src/items/vButtonOut.cpp similarity index 68% rename from src/items/ButtonOut.cpp rename to src/items/vButtonOut.cpp index 26d574a2..bb4759ec 100644 --- a/src/items/ButtonOut.cpp +++ b/src/items/vButtonOut.cpp @@ -1,4 +1,4 @@ -#include "items/ButtonOut.h" +#include "items/vButtonOut.h" #include @@ -10,22 +10,28 @@ ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) { _pin = pin; _inv = inv; _key = key; + pinMode(_pin, OUTPUT); + int state = jsonReadInt(configLiveJson, key); + this->execute(String(state)); } ButtonOut::~ButtonOut() {} -void ButtonOut::init() { - pinMode(_pin, OUTPUT); -} - void ButtonOut::execute(String state) { - //if (_inv) { - // digitalWrite(_pin, !state.toInt()); - //} - //else { - digitalWrite(_pin, state.toInt()); - //} + if (state == "change") { + state = String(!digitalRead(_pin)); + digitalWrite(_pin, state.toInt()); + } + else { + if (_inv) { + digitalWrite(_pin, !state.toInt()); + } + else { + digitalWrite(_pin, state.toInt()); + } + } eventGen2(_key, state); jsonWriteInt(configLiveJson, _key, state.toInt()); + saveLive(); publishStatus(_key, state); } @@ -36,6 +42,10 @@ void buttonOut() { String key = myLineParsing.gkey(); String pin = myLineParsing.gpin(); String inv = myLineParsing.ginv(); + + bool invb = false; + if (inv.toInt() == 1) invb = true; + myLineParsing.clear(); buttonOut_EnterCounter++; @@ -44,7 +54,7 @@ void buttonOut() { static bool firstTime = true; if (firstTime) myButtonOut = new MyButtonOutVector(); firstTime = false; - myButtonOut->push_back(ButtonOut(pin.toInt(), inv.toInt(), key)); + myButtonOut->push_back(ButtonOut(pin.toInt(), invb, key)); sCmd.addCommand(key.c_str(), buttonOutExecute); } diff --git a/src/items/ImpulsOutClass.cpp b/src/items/vImpulsOut.cpp similarity index 98% rename from src/items/ImpulsOutClass.cpp rename to src/items/vImpulsOut.cpp index 172e89e4..911fdd22 100644 --- a/src/items/ImpulsOutClass.cpp +++ b/src/items/vImpulsOut.cpp @@ -1,4 +1,4 @@ -#include "items/ImpulsOutClass.h" +#include "items/vImpulsOut.h" #include #include "BufferExecute.h" diff --git a/src/items/vInput.cpp b/src/items/vInput.cpp new file mode 100644 index 00000000..7689ff2a --- /dev/null +++ b/src/items/vInput.cpp @@ -0,0 +1,53 @@ +#include "items/vInput.h" + +#include + +#include "Class/LineParsing.h" +#include "Global.h" +#include "BufferExecute.h" + +Input::Input(String key) { + _key = key; + String value = jsonReadStr(configLiveJson, key); + this->execute(value); +} +Input::~Input() {} + +void Input::execute(String state) { + eventGen2(_key, state); + jsonWriteInt(configLiveJson, _key, state.toInt()); + saveLive(); + publishStatus(_key, state); +} + +MyInputVector* myInput = nullptr; + +void input() { + myLineParsing.update(); + 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; + myInput->push_back(Input(key)); + + sCmd.addCommand(key.c_str(), inputExecute); +} + +void inputExecute() { + String key = sCmd.order(); + String state = sCmd.next(); + + int number = getKeyNum(key, input_KeyList); + + if (myInput != nullptr) { + if (number != -1) { + myInput->at(number).execute(state); + } + } +} + diff --git a/src/items/Logging.cpp b/src/items/vLogging.cpp similarity index 98% rename from src/items/Logging.cpp rename to src/items/vLogging.cpp index 2f178d23..7777ef79 100644 --- a/src/items/Logging.cpp +++ b/src/items/vLogging.cpp @@ -1,4 +1,4 @@ -#include "items/Logging.h" +#include "items/vLogging.h" #include @@ -120,5 +120,6 @@ void clean_log_date() { SerialPrint("I", "System", fname); removeFile("logs/" + fname); } + removeFile("live.json"); #endif } diff --git a/src/items/SensorDallas.cpp b/src/items/vSensorDallas.cpp similarity index 97% rename from src/items/SensorDallas.cpp rename to src/items/vSensorDallas.cpp index 1abadc25..323bca12 100644 --- a/src/items/SensorDallas.cpp +++ b/src/items/vSensorDallas.cpp @@ -1,4 +1,4 @@ -#include "items/SensorDallas.h" +#include "items/vSensorDallas.h" #include "Class/LineParsing.h" #include "Global.h" #include "BufferExecute.h" diff --git a/src/main.cpp b/src/main.cpp index 4a809cbd..4751e813 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,9 +15,9 @@ #include "Utils/Timings.h" #include "Utils/WebUtils.h" #include "items/ButtonInClass.h" -#include "items/Logging.h" -#include "items/ImpulsOutClass.h" -#include "items/SensorDallas.h" +#include "items/vLogging.h" +#include "items/vImpulsOut.h" +#include "items/vSensorDallas.h" #include "Telegram.h" void not_async_actions();