From 605cd36e2783733d57e4ad2a29b17c6f67806a2e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 18 Mar 2020 00:09:40 +0200 Subject: [PATCH] Send a text to device on ENTER with ``send_on_enter`` filter // Resolve #926 --- HISTORY.rst | 3 +- docs | 2 +- .../commands/device/filters/send_on_enter.py | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 platformio/commands/device/filters/send_on_enter.py diff --git a/HISTORY.rst b/HISTORY.rst index 17d63084..f5806fa1 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -22,8 +22,9 @@ PlatformIO Core 4 - Added **PlatformIO Device Monitor Filter API** (dev-platforms can extend base device monitor with a custom functionality, such as exception decoding) (`pull #3383 `_) - Configure project device monitor with `monitor_filters `__ option - - Show a timestamp for each new line with ``time`` filter (`issue #981 `_) - `Capture device monitor output to a file `__ with ``log2file`` filter (`issue #670 `_) + - Show a timestamp for each new line with ``time`` filter (`issue #981 `_) + - Send a text to device on ENTER with ``send_on_enter`` filter (`issue #926 `_) * Added support for Arm Mbed "module.json" ``dependencies`` field (`issue #3400 `_) * Improved support for Arduino "library.properties" ``depends`` field diff --git a/docs b/docs index 873114bd..4fc291ef 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 873114bdbb091a26e25b61d9536b76439d5f9c3a +Subproject commit 4fc291ef035ef4464afef8f8c53d18f545155512 diff --git a/platformio/commands/device/filters/send_on_enter.py b/platformio/commands/device/filters/send_on_enter.py new file mode 100644 index 00000000..102348d1 --- /dev/null +++ b/platformio/commands/device/filters/send_on_enter.py @@ -0,0 +1,31 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from platformio.commands.device import DeviceMonitorFilter + + +class SendOnEnter(DeviceMonitorFilter): + NAME = "send_on_enter" + + def __init__(self, *args, **kwargs): + super(SendOnEnter, self).__init__(*args, **kwargs) + self._buffer = "" + + def tx(self, text): + self._buffer += text + if "\r\n" in self._buffer: + text = self._buffer + self._buffer = "" + return text + return ""