diff --git a/CHANGELOG.md b/CHANGELOG.md index 5335d34..7637eee 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased (but available on Github) +- Added option to change the newLine character via `getNewlineCharacter()` and `setNewlineCharacter()` as suggest by [Roy](https://github.com/FunDeckHermit) in [#69](https://github.com/LennartHennigs/ESPTelnet/pull/69) + **Note:** Unreleased changes are checked in but not part of an official release (available through the Arduino IDE or PlatfomIO) yet. This allows you to test WiP features and give feedback to them. ## [2.2.1] – 2024-02-17 diff --git a/README.md b/README.md index 14def02..d24a62d 100755 --- a/README.md +++ b/README.md @@ -45,9 +45,10 @@ If you find this library helpful please consider giving it a ⭐️ at [GitHub]( ### Output and Input -* Via `print()` and `println()` you can output text on the telnet server. +* Via `print()`, `printf()` and `println()` you can output text on the telnet server. * To receive and parse input from the telnet client you can add a handler via `onInputReceived()`. * By default, the library waits for a newline character from the client, and sends data to the callback handler one line at a time. This behaviour can be deactivated by calling `setlineMode(false)`. +* A default newline character `'\n'` is used to determine the end of a line. This can be overridden by by calling `setNewlineCharacter('\r')` where `'\r'` can be swapped with any character. ### Using stream functions @@ -148,6 +149,12 @@ These are the constructors and the member functions the library provides: void setKeepAliveInterval(int ms); int getKeepAliveInterval(); + bool isLineModeSet(); + void setLineMode(bool value = true); + + char getNewlineCharacter(); + void setNewlineCharacter(char value = '\n'); + void onConnect(CallbackFunction f); void onConnectionAttempt(CallbackFunction f); void onReconnect(CallbackFunction f); @@ -193,6 +200,12 @@ These are the constructors and the member functions the library provides: Open the Arduino IDE choose "Sketch > Include Library" and search for "ESPTelnet". Or download the [ZIP archive](https://github.com/lennarthennigs/ESPTelnet/zipball/master), and choose "Sketch > Include Library > Add .ZIP Library..." and select the downloaded file. +The "ESPTelnet" library is also available on the PlatformIO registry and can be included by adding the following line to the leb_deps option of the platformio.ini file: + +``` json + lennarthennigs/ESP Telnet@^2.2.2 +``` + ## License MIT License diff --git a/keywords.txt b/keywords.txt index 89eb47a..06c35e1 100755 --- a/keywords.txt +++ b/keywords.txt @@ -25,4 +25,6 @@ flush KEYWORD2 write KEYWORD2 printf KEYWORD2 getTimeoutInterval KEYWORD2 -setTimeoutInterval KEYWORD2 \ No newline at end of file +setTimeoutInterval KEYWORD2 +getNewlineCharacter KEYWORD2 +setNewlineCharacter KEYWORD2 \ No newline at end of file diff --git a/src/ESPTelnet.cpp b/src/ESPTelnet.cpp index 69a8d76..c7f2907 100755 --- a/src/ESPTelnet.cpp +++ b/src/ESPTelnet.cpp @@ -8,7 +8,7 @@ void ESPTelnet::handleInput() { char c = client.read(); // collect string if (_lineMode) { - if (c != '\n') { + if (c != _newlineCharacter) { if (c >= 32 && c < 127) { input += c; } @@ -81,4 +81,16 @@ void ESPTelnet::setLineMode(bool value /* = true */) { _lineMode = value; } -///////////////////////////////////////////////////////////////// \ No newline at end of file +///////////////////////////////////////////////////////////////// + +char ESPTelnet::getNewlineCharacter() { + return _newlineCharacter; +} + +///////////////////////////////////////////////////////////////// + +void ESPTelnet::setNewlineCharacter(char value /* = '\n' */) { + _newlineCharacter = value; +} + +///////////////////////////////////////////////////////////////// diff --git a/src/ESPTelnet.h b/src/ESPTelnet.h index 8bab293..a59b1b3 100755 --- a/src/ESPTelnet.h +++ b/src/ESPTelnet.h @@ -65,8 +65,12 @@ class ESPTelnet : public ESPTelnetBase { bool isLineModeSet(); void setLineMode(bool value = true); - protected: + char getNewlineCharacter(); + void setNewlineCharacter(char value = '\n'); + + protected: bool _lineMode = true; + char _newlineCharacter = '\n'; void handleInput(); };