From 01afcb1c9eb6991e64523684811aaeaa53c0709c Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 26 Jun 2017 17:14:38 +0300 Subject: [PATCH] =?UTF-8?q?New=20monitor=20target=20which=20allows=20to=20?= =?UTF-8?q?launch=20Serial=20Monitor=20automatically=20after=20successful?= =?UTF-8?q?=20=E2=80=9Cbuild=E2=80=9D=20or=20=E2=80=9Cupload=E2=80=9D=20op?= =?UTF-8?q?erations=20//=20Resolve=20#788?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HISTORY.rst | 4 ++++ docs | 2 +- platformio/commands/run.py | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index fb34f947..cfcaedee 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -23,6 +23,10 @@ PlatformIO 3.0 * Custom ``test_transport`` for `PIO Unit Testing `__ Engine * Configure Serial Port Monitor in `Project Configuration File "platformio.ini" `__ (`issue #787 `_) +* New `monitor `__ + target which allows to launch Serial Monitor automatically after successful + "build" or "upload" operations + (`issue #788 `_) * Project generator for `VIM `__ * Multi-line support for the different options in `Project Configuration File "platformio.ini" `__, such as: ``build_flags``, ``build_unflags``, etc. diff --git a/docs b/docs index 90756ec9..dd628f3e 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 90756ec9f7138b0d147b70f28bdd3d85dd5da17a +Subproject commit dd628f3e8e500d27e3b12b1f80269327b11e5ab0 diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 403a0a15..fdd9cefe 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -21,6 +21,7 @@ from time import time import click from platformio import __version__, exception, telemetry, util +from platformio.commands.device import device_monitor as cmd_device_monitor from platformio.commands.lib import lib_install as cmd_lib_install from platformio.commands.lib import get_builtin_libs from platformio.commands.platform import \ @@ -107,7 +108,11 @@ def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) - results.append((envname, ep.process())) + result = (envname, ep.process()) + results.append(result) + if result[1] and "monitor" in ep.get_build_targets() and \ + "nobuild" not in ep.get_build_targets(): + ctx.invoke(cmd_device_monitor) found_error = any([status is False for (_, status) in results]) @@ -226,7 +231,7 @@ class EnvironmentProcessor(object): result[k] = v return result - def _get_build_variables(self): + def get_build_variables(self): variables = {"pioenv": self.name} if self.upload_port: variables['upload_port'] = self.upload_port @@ -240,7 +245,7 @@ class EnvironmentProcessor(object): variables[k] = v return variables - def _get_build_targets(self): + def get_build_targets(self): targets = [] if self.targets: targets = [t for t in self.targets] @@ -252,11 +257,14 @@ class EnvironmentProcessor(object): if "platform" not in self.options: raise exception.UndefinedEnvPlatform(self.name) - build_vars = self._get_build_variables() - build_targets = self._get_build_targets() + build_vars = self.get_build_variables() + build_targets = self.get_build_targets() telemetry.on_run_environment(self.options, build_targets) + # skip monitor target, we call it above + if "monitor" in build_targets: + build_targets.remove("monitor") if "nobuild" not in build_targets: # install dependent libraries if "lib_install" in self.options: