diff --git a/include/Global.h b/include/Global.h index da313a07..ab5ca375 100644 --- a/include/Global.h +++ b/include/Global.h @@ -255,6 +255,7 @@ extern void do_mqtt_send_settings_to_udp(); extern void Web_server_init(); // iot_firmware +extern void loopSerial(); extern void loopCmd(); extern void loopButton(); extern void loopScenario(); diff --git a/include/Module/Terminal.h b/include/Module/Terminal.h index 11c5232e..3d3234d8 100644 --- a/include/Module/Terminal.h +++ b/include/Module/Terminal.h @@ -114,7 +114,7 @@ enum State { ST_INACTIVE, class Terminal : public Print { public: Terminal(Stream *stream = nullptr); - ~Terminal(); + void setStream(Stream *stream); void setEOL(EOLType_t code); void enableControlCodes(bool enabled = true); @@ -153,7 +153,7 @@ class Terminal : public Print { uint8_t curX = 0xff; unsigned long _lastReceived = 0; - State state = ST_INACTIVE; + State state; Stream *_stream; EditLine _line; char _cc_buf[32] = {0}; diff --git a/src/Cmd.cpp b/src/Cmd.cpp index bb597623..85b7e48e 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -250,6 +250,12 @@ void switch_() { but[switch_number.toInt()] = true; } +void loopSerial() { + if (term) { + term->loop(); + } +} + void loopButton() { static uint8_t switch_number = 1; @@ -523,10 +529,6 @@ void serialBegin() { delete mySerial; } - if (term) { - delete term; - } - mySerial = new SoftwareSerial(rxPin.toInt(), txPin.toInt()); mySerial->begin(s_speed.toInt()); @@ -538,6 +540,7 @@ void serialBegin() { term->setOnReadLine([](const char *str) { String line = String(str); pm.info("serial read: " + line); + line.replace("#", " "); order_loop += line + ","; }); } diff --git a/src/Module/Terminal.cpp b/src/Module/Terminal.cpp index 17d96b91..4de12887 100644 --- a/src/Module/Terminal.cpp +++ b/src/Module/Terminal.cpp @@ -10,14 +10,12 @@ Terminal::Terminal(Stream *stream) : _stream{stream}, _color(false), _controlCodes(false), _echo(false), - _eol(CRLF){}; + _eol(CRLF) { state = ST_NORMAL; }; void Terminal::setStream(Stream *stream) { _stream = stream; } -Terminal::~Terminal() {} - void Terminal::setOnReadLine(TerminalInputEventHandler h) { inputHandler_ = h; } void Terminal::setOnEvent(TerminalEventHandler h) { eventHandler_ = h; } diff --git a/src/main.cpp b/src/main.cpp index a2d77deb..67b3fb9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,6 +93,9 @@ void loop() { #ifdef UDP_ENABLED loopUdp(); #endif + + loopSerial(); + ts.update(); }