Skip to content

Commit

Permalink
Avoid board change during compilation/upload
Browse files Browse the repository at this point in the history
By threading the boardChange callback we can busy wait until
the compilation/upload phase has ended and change the board when done.

Fixes arduino#6035
  • Loading branch information
facchinm committed May 2, 2018
1 parent 8e515a2 commit 91f11a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ public void rebuildExamplesMenu(JMenu menu) {
private static String priorPlatformFolder;
private static boolean newLibraryImported;

public void onBoardOrPortChange() {
public synchronized void onBoardOrPortChange() {
BaseNoGui.onBoardOrPortChange();

// reload keywords when package/platform changes
Expand Down Expand Up @@ -1510,12 +1510,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
@SuppressWarnings("serial")
Action action = new AbstractAction(board.getName()) {
public void actionPerformed(ActionEvent actionevent) {
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);

onBoardOrPortChange();
rebuildImportMenu(Editor.importMenu);
rebuildExamplesMenu(Editor.examplesMenu);
new Thread()
{
public void run() {
if (activeEditor != null && activeEditor.isCompiling()) {
// block until isCompiling becomes false, but aboid blocking the UI
while (activeEditor.isCompiling()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
}

BaseNoGui.selectBoard((TargetBoard) getValue("b"));
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
onBoardOrPortChange();
rebuildImportMenu(Editor.importMenu);
rebuildExamplesMenu(Editor.examplesMenu);
}
}.start();
}
};
action.putValue("b", board);
Expand Down
4 changes: 4 additions & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,10 @@ public void run() {
}
}

public boolean isCompiling() {
return uploading;
}

private void resumeOrCloseSerialMonitor() {
// Return the serial monitor window to its initial state
if (serialMonitor != null) {
Expand Down

0 comments on commit 91f11a5

Please sign in to comment.