From ffc5e6c89484ca17b3efff0861375f5f604dd149 Mon Sep 17 00:00:00 2001
From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com>
Date: Wed, 26 Aug 2020 16:39:42 +0300
Subject: [PATCH] output text module added
---
data/items/button-out-np.txt | 1 +
.../{button-out.txt => button-out-p.txt} | 0
data/items/input-digit.txt | 2 +-
data/items/input-time.txt | 2 +-
data/items/output-text.txt | 1 +
data/set.device.json | 12 ++--
include/Class/CallBackTest.h | 2 +-
include/Class/LineParsing.h | 9 ++-
include/Class/OutputModule.h | 24 ++++++++
include/Cmd.h | 4 +-
src/Class/CallBackTest.cpp | 2 +-
src/Class/OutputModule.cpp | 2 +
src/Cmd.cpp | 60 ++++++++++++-------
13 files changed, 83 insertions(+), 38 deletions(-)
create mode 100644 data/items/button-out-np.txt
rename data/items/{button-out.txt => button-out-p.txt} (100%)
create mode 100644 data/items/output-text.txt
create mode 100644 include/Class/OutputModule.h
create mode 100644 src/Class/OutputModule.cpp
diff --git a/data/items/button-out-np.txt b/data/items/button-out-np.txt
new file mode 100644
index 00000000..5fa21dd1
--- /dev/null
+++ b/data/items/button-out-np.txt
@@ -0,0 +1 @@
+button-out;id;toggle;Кнопки;Освещение;order;st[0]
\ No newline at end of file
diff --git a/data/items/button-out.txt b/data/items/button-out-p.txt
similarity index 100%
rename from data/items/button-out.txt
rename to data/items/button-out-p.txt
diff --git a/data/items/input-digit.txt b/data/items/input-digit.txt
index 932b28d5..8c3fbbe0 100644
--- a/data/items/input-digit.txt
+++ b/data/items/input-digit.txt
@@ -1 +1 @@
-input-digit;id;inputDigit;Ввод;Введите.цифру;order;st[60]
\ No newline at end of file
+input-digit;id;inputDigit;Ввод;Введите#цифру;order;st[60]
\ No newline at end of file
diff --git a/data/items/input-time.txt b/data/items/input-time.txt
index ad394ae6..821e29c3 100644
--- a/data/items/input-time.txt
+++ b/data/items/input-time.txt
@@ -1 +1 @@
-input-time;id;inputTime;Ввод;Введите.время;order;st[10-00-00]
\ No newline at end of file
+input-time;id;inputTime;Ввод;Введите#время;order;st[10-00-00]
\ No newline at end of file
diff --git a/data/items/output-text.txt b/data/items/output-text.txt
new file mode 100644
index 00000000..fbe97423
--- /dev/null
+++ b/data/items/output-text.txt
@@ -0,0 +1 @@
+output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено#движение]
\ No newline at end of file
diff --git a/data/set.device.json b/data/set.device.json
index 260af361..533ff559 100644
--- a/data/set.device.json
+++ b/data/set.device.json
@@ -55,11 +55,13 @@
"style": "display:inline",
"title": {
"#": "Выберите элемент из списка",
- "/set?addItem=button-out": "1.Кнопка управляющая пином",
- "/set?addItem=pwm-out": "2.Широтно импульсная модуляция(pwm)",
- "/set?addItem=button-in": "3.Физическая кнопка",
- "/set?addItem=input-digit": "4.Окно ввода цифровых значений",
- "/set?addItem=input-time": "5.Окно ввода времени"
+ "/set?addItem=button-out-p": "1.Кнопка управляющая пином",
+ "/set?addItem=button-out-np": "2.Кнопка не привязанная к пину",
+ "/set?addItem=pwm-out": "3.Широтно импульсная модуляция(pwm)",
+ "/set?addItem=button-in": "4.Физическая кнопка",
+ "/set?addItem=input-digit": "5.Окно ввода цифровых значений",
+ "/set?addItem=input-time": "6.Окно ввода времени",
+ "/set?addItem=output-text": "7.Окно вывода любого текста, предупреждения, цифры"
}
},
{
diff --git a/include/Class/CallBackTest.h b/include/Class/CallBackTest.h
index 7b014ad2..6632bfe0 100644
--- a/include/Class/CallBackTest.h
+++ b/include/Class/CallBackTest.h
@@ -23,4 +23,4 @@ class CallBackTest {
void setCallback(AsyncActionCb cb);
void setCallback(AsyncParamActionCb pcb);
};
-extern CallBackTest* CB;
\ No newline at end of file
+//extern CallBackTest* CB;
\ No newline at end of file
diff --git a/include/Class/LineParsing.h b/include/Class/LineParsing.h
index 53481c9f..2d84a385 100644
--- a/include/Class/LineParsing.h
+++ b/include/Class/LineParsing.h
@@ -66,10 +66,11 @@ class LineParsing {
}
}
}
+
_page.replace("#", " ");
- _descr.replace("#", " ");
- _page.replace(".", " ");
- _descr.replace(".", " ");
+
+ _descr.replace("#", " ");
+
createWidgetClass(_descr, _page, _order, _file, _key);
}
@@ -124,8 +125,6 @@ class LineParsing {
if (!loadWidgetClass(filename, buf)) {
return;
}
- descr.replace("#", " ");
- page.replace("#", " ");
jsonWriteStr(buf, "page", page);
jsonWriteStr(buf, "order", order);
diff --git a/include/Class/OutputModule.h b/include/Class/OutputModule.h
new file mode 100644
index 00000000..7e4adc68
--- /dev/null
+++ b/include/Class/OutputModule.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include
+#include "Class/LineParsing.h"
+#include "Global.h"
+
+class OutputModule : public LineParsing {
+ public:
+ OutputModule() : LineParsing(){};
+
+ void OutputModuleStateSetDefault() {
+ if (_state != "") {
+ OutputModuleChange(_key, _state);
+ }
+ }
+
+ void OutputModuleChange(String key, String state) {
+ state.replace("#", " ");
+ eventGen(key, "");
+ jsonWriteStr(configLiveJson, key, state);
+ MqttClient::publishStatus(key, state);
+ }
+};
+extern OutputModule* myText;
\ No newline at end of file
diff --git a/include/Cmd.h b/include/Cmd.h
index 70bf975e..9ef6054d 100644
--- a/include/Cmd.h
+++ b/include/Cmd.h
@@ -19,8 +19,8 @@ extern void inputDigitSet();
extern void inputTime();
extern void inputTimeSet();
-extern void text();
-extern void textSet();
+extern void textOut();
+extern void textOutSet();
extern void handle_time_init();
extern void stepper();
diff --git a/src/Class/CallBackTest.cpp b/src/Class/CallBackTest.cpp
index 30b7f7cf..55252e5e 100644
--- a/src/Class/CallBackTest.cpp
+++ b/src/Class/CallBackTest.cpp
@@ -37,7 +37,7 @@ void CallBackTest::setCallback(AsyncActionCb cb) {
void CallBackTest::setCallback(AsyncParamActionCb pcb) {
_pcb = pcb;
}
-CallBackTest* CB;
+//CallBackTest* CB;
//CB->setCallback([]() {
// Serial.println("123");
diff --git a/src/Class/OutputModule.cpp b/src/Class/OutputModule.cpp
new file mode 100644
index 00000000..d0496426
--- /dev/null
+++ b/src/Class/OutputModule.cpp
@@ -0,0 +1,2 @@
+#include "Class/OutputModule.h"
+OutputModule* myText;
\ No newline at end of file
diff --git a/src/Cmd.cpp b/src/Cmd.cpp
index 11b35bec..1d0eb782 100644
--- a/src/Cmd.cpp
+++ b/src/Cmd.cpp
@@ -5,6 +5,7 @@
#include "Class/LineParsing.h"
#include "Class/Pwm.h"
#include "Class/Switch.h"
+#include "Class/OutputModule.h"
//-----------------------------
#include "Class/NotAsinc.h"
#include "Global.h"
@@ -32,9 +33,8 @@ void cmd_init() {
sCmd.addCommand("button-in", buttonIn);
sCmd.addCommand("input-digit", inputDigit);
sCmd.addCommand("input-time", inputTime);
+ sCmd.addCommand("output-text", textOut);
- sCmd.addCommand("text", text);
- sCmd.addCommand("textSet", textSet);
@@ -235,29 +235,45 @@ void handle_time_init() {
//===============================================Модуль вывода текста============================================
//output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено.движение]
//===============================================================================================================
-void text() {
- String number = sCmd.next();
- String widget_name = sCmd.next();
- String page_name = sCmd.next();
- String page_number = sCmd.next();
-
- createWidget(widget_name, page_name, page_number, "anydata", "text" + number);
+void textOut() {
+ myText = new OutputModule();
+ myText->update();
+ String key = myText->gkey();
+ sCmd.addCommand(key.c_str(), textOutSet);
+ myText->OutputModuleStateSetDefault();
+ myText->clear();
}
-void textSet() {
- String number = sCmd.next();
- String text = sCmd.next();
- text.replace("_", " ");
-
- if (text.indexOf("-time") >= 0) {
- text.replace("-time", "");
- text.replace("#", " ");
- text = text + " " + timeNow->getDateTimeDotFormated();
- }
-
- jsonWriteStr(configLiveJson, "text" + number, text);
- MqttClient::publishStatus("text" + number, text);
+void textOutSet() {
+ String key = sCmd.order();
+ String state = sCmd.next();
+ myText->OutputModuleChange(key, state);
}
+
+
+//void text() {
+// String number = sCmd.next();
+// String widget_name = sCmd.next();
+// String page_name = sCmd.next();
+// String page_number = sCmd.next();
+//
+// createWidget(widget_name, page_name, page_number, "anydata", "text" + number);
+//}
+//
+//void textSet() {
+// String number = sCmd.next();
+// String text = sCmd.next();
+// text.replace("_", " ");
+//
+// if (text.indexOf("-time") >= 0) {
+// text.replace("-time", "");
+// text.replace("#", " ");
+// text = text + " " + timeNow->getDateTimeDotFormated();
+// }
+//
+// jsonWriteStr(configLiveJson, "text" + number, text);
+// MqttClient::publishStatus("text" + number, text);
+//}
//=====================================================================================================================================
//=========================================Модуль шагового мотора======================================================================
#ifdef STEPPER_ENABLED