2020-12-16 13:59:01 +01:00
|
|
|
#ifdef uartEnable
|
2020-12-06 00:34:30 +03:00
|
|
|
#include "SoftUART.h"
|
2020-12-06 02:08:37 +03:00
|
|
|
#include "Global.h"
|
2020-12-06 00:34:30 +03:00
|
|
|
|
2020-12-06 00:40:48 +03:00
|
|
|
#ifdef ESP8266
|
|
|
|
|
SoftwareSerial* myUART = nullptr;
|
|
|
|
|
#else
|
|
|
|
|
HardwareSerial* myUART = nullptr;
|
|
|
|
|
#endif
|
2020-12-06 00:34:30 +03:00
|
|
|
|
|
|
|
|
void uartInit() {
|
2020-12-16 13:59:01 +01:00
|
|
|
if (!jsonReadBool(configSetupJson, "uartEnable")) {
|
2020-12-06 02:08:37 +03:00
|
|
|
return;
|
|
|
|
|
}
|
2020-12-06 00:34:30 +03:00
|
|
|
if (!myUART) {
|
2020-12-06 00:40:48 +03:00
|
|
|
#ifdef ESP8266
|
2020-12-06 02:08:37 +03:00
|
|
|
myUART = new SoftwareSerial(jsonReadInt(configSetupJson, "uartTX"), jsonReadInt(configSetupJson, "uartRX"));
|
|
|
|
|
myUART->begin(jsonReadInt(configSetupJson, "uartS"));
|
2020-12-06 00:40:48 +03:00
|
|
|
#else
|
|
|
|
|
myUART = new HardwareSerial(2);
|
|
|
|
|
myUART->begin(4, 5);
|
|
|
|
|
#endif
|
2020-12-06 00:34:30 +03:00
|
|
|
}
|
2020-12-10 19:12:15 +03:00
|
|
|
SerialPrint("I", F("UART"), F("UART Init"));
|
2020-12-06 00:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uartHandle() {
|
2020-12-10 19:12:15 +03:00
|
|
|
if (myUART) {
|
2020-12-16 13:59:01 +01:00
|
|
|
if (!jsonReadBool(configSetupJson, "uartEnable")) {
|
2020-12-10 05:13:09 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
static String incStr;
|
|
|
|
|
if (myUART->available()) {
|
|
|
|
|
char inc;
|
|
|
|
|
inc = myUART->read();
|
|
|
|
|
incStr += inc;
|
|
|
|
|
if (inc == '\n') {
|
|
|
|
|
parse(incStr);
|
2020-12-10 19:12:15 +03:00
|
|
|
incStr = "";
|
2020-12-10 05:13:09 +03:00
|
|
|
}
|
2020-12-06 00:34:30 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void parse(String& incStr) {
|
2020-12-10 05:13:09 +03:00
|
|
|
incStr.replace("\r\n", "");
|
|
|
|
|
incStr.replace("\r", "");
|
|
|
|
|
incStr.replace("\n", "");
|
2020-12-06 02:08:37 +03:00
|
|
|
if (incStr.indexOf("set") != -1) {
|
|
|
|
|
incStr = deleteBeforeDelimiter(incStr, " ");
|
|
|
|
|
orderBuf += incStr;
|
2020-12-10 19:12:15 +03:00
|
|
|
SerialPrint("I", "=>UART", incStr);
|
2020-12-06 02:08:37 +03:00
|
|
|
}
|
2020-12-16 13:59:01 +01:00
|
|
|
}
|
|
|
|
|
#endif
|