Skip to content

Commit

Permalink
add a flag to pause polling for serial port
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Apr 1, 2016
1 parent ea405ea commit c5d88f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ public void setSerialBoardPorts(List<BoardPort> newSerialBoardPorts) {
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -54,7 +55,7 @@ public void start(Timer timer) {
timer.schedule(this, 0, 1000);
}

public synchronized void retriggerDiscovery() {
public synchronized void retriggerDiscovery(boolean polled) {
while (BaseNoGui.packages == null) {
try {
Thread.sleep(1000);
Expand All @@ -67,6 +68,10 @@ public synchronized void retriggerDiscovery() {
return;
}

if (polled && pausePolling) {
return;
}

List<String> ports = platform.listSerials();
if (ports.equals(oldPorts)) {
return;
Expand Down Expand Up @@ -163,6 +168,6 @@ public synchronized void retriggerDiscovery() {

@Override
public void run() {
retriggerDiscovery();
retriggerDiscovery(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
return uploadUsingProgrammer(buildPath, className);
}

BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(true);

if (noUploadPort)
{
prefs.put("build.path", buildPath);
Expand All @@ -107,6 +109,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
uploadResult = executeUploadCommand(cmd);
} catch (Exception e) {
throw new RunnerException(e);
} finally {
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
}
return uploadResult;
}
Expand Down Expand Up @@ -148,6 +152,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
throw new RunnerException(e);
} catch (InterruptedException e) {
throw new RunnerException(e.getMessage());
} finally {
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
}
if (actualUploadPort == null) {
actualUploadPort = userSelectedUploadPort;
Expand Down Expand Up @@ -183,9 +189,12 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
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) {
Expand Down

0 comments on commit c5d88f0

Please sign in to comment.