mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
uart
This commit is contained in:
@@ -23,26 +23,28 @@ void uartInit() {
|
||||
}
|
||||
|
||||
void uartHandle() {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
if (myUART->available()) {
|
||||
char inc;
|
||||
inc = myUART->read();
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
if (myUART != nullptr) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
if (myUART->available()) {
|
||||
char inc;
|
||||
inc = myUART->read();
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse(String& incStr) {
|
||||
incStr.replace("\r\n", "");
|
||||
incStr.replace("\r", "");
|
||||
incStr.replace("\n", "");
|
||||
if (incStr.indexOf("set") != -1) {
|
||||
incStr.replace("\r\n", "");
|
||||
incStr.replace("\r", "");
|
||||
incStr.replace("\n", "");
|
||||
incStr = deleteBeforeDelimiter(incStr, " ");
|
||||
SerialPrint("I", "UART", incStr);
|
||||
orderBuf += incStr;
|
||||
|
||||
@@ -38,6 +38,7 @@ void web_init() {
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
addPreset(request->getParam("addPreset")->value());
|
||||
#endif
|
||||
jsonWriteStr(configSetupJson, "warning1", F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "SoftUART.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
//this class save data to flash
|
||||
ButtonOut::ButtonOut(String pin, boolean inv, String key) {
|
||||
ButtonOut::ButtonOut(String pin, boolean inv, String key, String type) {
|
||||
_pin = pin;
|
||||
_inv = inv;
|
||||
_key = key;
|
||||
_type = type;
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
@@ -18,6 +20,13 @@ ButtonOut::ButtonOut(String pin, boolean inv, String key) {
|
||||
ButtonOut::~ButtonOut() {}
|
||||
|
||||
void ButtonOut::execute(String state) {
|
||||
if (_type == "UART") {
|
||||
if (jsonReadBool(configSetupJson, "uart")) {
|
||||
if (myUART != nullptr) {
|
||||
myUART->print(_key + " " + state);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state != "" && _pin != "") {
|
||||
if (state == "change") {
|
||||
state = String(!digitalRead(_pin.toInt()));
|
||||
@@ -45,6 +54,7 @@ void buttonOut() {
|
||||
String key = myLineParsing.gkey();
|
||||
String pin = myLineParsing.gpin();
|
||||
String inv = myLineParsing.ginv();
|
||||
String type = myLineParsing.gtype();
|
||||
|
||||
bool invb = false;
|
||||
if (inv.toInt() == 1) invb = true;
|
||||
@@ -57,7 +67,7 @@ void buttonOut() {
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myButtonOut = new MyButtonOutVector();
|
||||
firstTime = false;
|
||||
myButtonOut->push_back(ButtonOut(pin, invb, key));
|
||||
myButtonOut->push_back(ButtonOut(pin, invb, key, type));
|
||||
|
||||
sCmd.addCommand(key.c_str(), buttonOutExecute);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "items/vInOutput.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Clock.h"
|
||||
|
||||
//this class save date to flash
|
||||
InOutput::InOutput(String key, String widget) {
|
||||
_key = key;
|
||||
@@ -12,7 +12,7 @@ InOutput::InOutput(String key, String widget) {
|
||||
|
||||
if (value == "") {
|
||||
if (widget.indexOf("Digit") != -1) {
|
||||
value = "52";
|
||||
value = "25";
|
||||
}
|
||||
if (widget.indexOf("Time") != -1) {
|
||||
value = "12:00";
|
||||
@@ -52,13 +52,18 @@ void inOutput() {
|
||||
void inOutputExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
//String type = sCmd.next();
|
||||
|
||||
|
||||
if (!isDigitStr(value)) { //если значение - текст
|
||||
if (value.indexOf(":") == -1) { //если этот текст не время
|
||||
String tmp = getValue(value);
|
||||
if(tmp != "no value") {
|
||||
value = tmp;
|
||||
value.replace("#"," ");
|
||||
String valueJson = getValue(value);
|
||||
if (valueJson != "no value") { //если это ключ переменной
|
||||
value = valueJson;
|
||||
}
|
||||
else { //если это просто текст
|
||||
value.replace("#", " ");
|
||||
value.replace("%date%", timeNow->getDateTimeDotFormated());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ void setup() {
|
||||
fileSystemInit();
|
||||
SerialPrint("I", F("FS"), F("FS Init"));
|
||||
|
||||
SerialPrint("I", F("UART"), F("UART Init"));
|
||||
uartInit();
|
||||
|
||||
loadConfig();
|
||||
SerialPrint("I", F("Conf"), F("Config Init"));
|
||||
|
||||
@@ -92,8 +95,7 @@ void setup() {
|
||||
SerialPrint("I", F("Bus"), F("Bus Init"));
|
||||
busInit();
|
||||
|
||||
SerialPrint("I", F("UART"), F("UART Init"));
|
||||
uartInit();
|
||||
|
||||
|
||||
#ifdef SSDP_ENABLED
|
||||
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
|
||||
|
||||
Reference in New Issue
Block a user