diff --git a/include/Module/Telnet.h b/include/Module/Telnet.h index 38ec2a91..ade6e4f2 100644 --- a/include/Module/Telnet.h +++ b/include/Module/Telnet.h @@ -24,6 +24,7 @@ class Telnet : public Module { void sendData(const String&); bool hasClient(); bool isShellActive(); + void setCommandShell(CommandShell*); protected: bool onInit() override; diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 377eae5a..1542f702 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -1,5 +1,8 @@ #include "Global.h" +#include "Module/Terminal.h" +Terminal *term = nullptr; + boolean but[NUM_BUTTONS]; Bounce *buttons = new Bounce[NUM_BUTTONS]; @@ -516,14 +519,24 @@ void serialBegin() { if (mySerial) { delete mySerial; } + + if (term) { + delete term; + } + mySerial = new SoftwareSerial(rxPin.toInt(), txPin.toInt()); mySerial->begin(s_speed.toInt()); + + term = new Terminal(mySerial); + term->setOnReadLine([](const char *str) { + order_loop += String(str) + ","; + }); } void serialWrite() { String payload = sCmd.next(); - if (mySerial) { - mySerial->println(payload); + if (term) { + term->println(payload.c_str()); } } #endif diff --git a/src/Module/Telnet.cpp b/src/Module/Telnet.cpp index 0c2681ee..f4b92fc7 100644 --- a/src/Module/Telnet.cpp +++ b/src/Module/Telnet.cpp @@ -6,9 +6,6 @@ bool Telnet::onInit() { _term->enableControlCodes(); _term->enableEcho(false); _term->setStream(&_client); - - // _shell = new CommandShell(Cli::get()); - _shell->setTerm(_term); return true; } @@ -37,6 +34,11 @@ void Telnet::sendData(const String& data) { } } +void Telnet::setCommandShell(CommandShell* shell) { + _shell = shell; + _shell->setTerm(_term); +} + void Telnet::setEventHandler(TelnetEventHandler h) { _eventHandler = h; } void Telnet::onLoop() {