From c5d88f09aecf35ee16ec09fa3c78495ab1817dcb Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 25 Mar 2016 17:02:19 +0100 Subject: [PATCH] add a flag to pause polling for serial port --- .../cc/arduino/packages/discoverers/SerialDiscovery.java | 4 +++- .../packages/discoverers/serial/SerialBoardsLister.java | 9 +++++++-- .../cc/arduino/packages/uploaders/SerialUploader.java | 9 +++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java index 565e80e90..3e6646d67 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java @@ -75,13 +75,15 @@ public class SerialDiscovery implements Discovery { } public void forceRefresh() { - serialBoardsLister.retriggerDiscovery(); + serialBoardsLister.retriggerDiscovery(false); } public void setUploadInProgress(boolean param) { serialBoardsLister.uploadInProgress = param; } + public void pausePolling(boolean param) { serialBoardsLister.pausePolling = param;} + @Override public void start() { this.serialBoardsListerTimer = new Timer(SerialBoardsLister.class.getName()); diff --git a/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java b/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java index 4de3626f6..0cafed956 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java @@ -44,6 +44,7 @@ public class SerialBoardsLister extends TimerTask { private final List boardPorts = new LinkedList<>(); private List oldPorts = new LinkedList<>(); public boolean uploadInProgress = false; + public boolean pausePolling = false; private BoardPort oldUploadBoardPort = null; public SerialBoardsLister(SerialDiscovery serialDiscovery) { @@ -54,7 +55,7 @@ public class SerialBoardsLister extends TimerTask { timer.schedule(this, 0, 1000); } - public synchronized void retriggerDiscovery() { + public synchronized void retriggerDiscovery(boolean polled) { while (BaseNoGui.packages == null) { try { Thread.sleep(1000); @@ -67,6 +68,10 @@ public class SerialBoardsLister extends TimerTask { return; } + if (polled && pausePolling) { + return; + } + List ports = platform.listSerials(); if (ports.equals(oldPorts)) { return; @@ -163,6 +168,6 @@ public class SerialBoardsLister extends TimerTask { @Override public void run() { - retriggerDiscovery(); + retriggerDiscovery(true); } } diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java index 064e04cfa..19d8a802d 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java @@ -91,6 +91,8 @@ public class SerialUploader extends Uploader { return uploadUsingProgrammer(buildPath, className); } + BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(true); + if (noUploadPort) { prefs.put("build.path", buildPath); @@ -107,6 +109,8 @@ public class SerialUploader extends Uploader { uploadResult = executeUploadCommand(cmd); } catch (Exception e) { throw new RunnerException(e); + } finally { + BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false); } return uploadResult; } @@ -148,6 +152,8 @@ public class SerialUploader extends Uploader { throw new RunnerException(e); } catch (InterruptedException e) { throw new RunnerException(e.getMessage()); + } finally { + BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false); } if (actualUploadPort == null) { actualUploadPort = userSelectedUploadPort; @@ -183,9 +189,12 @@ public class SerialUploader extends Uploader { throw e; } catch (Exception e) { throw new RunnerException(e); + } finally { + BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false); } BaseNoGui.getDiscoveryManager().getSerialDiscoverer().setUploadInProgress(false); + BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false); String finalUploadPort = null; if (uploadResult && doTouch) {