1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

add a flag to pause polling for serial port

This commit is contained in:
Martino Facchin 2016-03-25 17:02:19 +01:00
parent ea405ea534
commit c5d88f09ae
3 changed files with 19 additions and 3 deletions

View File

@ -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());

View File

@ -44,6 +44,7 @@ public class SerialBoardsLister extends TimerTask {
private final List<BoardPort> boardPorts = new LinkedList<>();
private List<String> 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<String> ports = platform.listSerials();
if (ports.equals(oldPorts)) {
return;
@ -163,6 +168,6 @@ public class SerialBoardsLister extends TimerTask {
@Override
public void run() {
retriggerDiscovery();
retriggerDiscovery(true);
}
}

View File

@ -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) {