Skip to content

Commit 51dcc5d

Browse files
committed
Revert using 3 seconds poll on Windows
from listSerialsj library 1.0.8 the serial polling is executed using the listComPorts method (which is much more cpu intensive than the previous one) to avoid bug #4700. The 3 second poll rate is needed to avoid cpu hogging
1 parent 815ccf1 commit 51dcc5d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
import java.util.*;
4040

41+
import static processing.app.helpers.OSUtils.isWindows;
42+
4143
public class SerialBoardsLister extends TimerTask {
4244

4345
private final SerialDiscovery serialDiscovery;
@@ -52,17 +54,15 @@ public SerialBoardsLister(SerialDiscovery serialDiscovery) {
5254
}
5355

5456
public void start(Timer timer) {
55-
timer.schedule(this, 0, 1000);
57+
58+
if (isWindows()) {
59+
timer.schedule(this, 0, 3000);
60+
} else {
61+
timer.schedule(this, 0, 1000);
62+
}
5663
}
5764

5865
public synchronized void retriggerDiscovery(boolean polled) {
59-
while (BaseNoGui.packages == null) {
60-
try {
61-
Thread.sleep(1000);
62-
} catch (InterruptedException e) {
63-
// noop
64-
}
65-
}
6666
Platform platform = BaseNoGui.getPlatform();
6767
if (platform == null) {
6868
return;
@@ -103,6 +103,11 @@ public synchronized void retriggerDiscovery(boolean polled) {
103103
String[] parts = newPort.split("_");
104104
String port = parts[0];
105105

106+
if (parts.length != 3) {
107+
// something went horribly wrong
108+
continue;
109+
}
110+
106111
Map<String, Object> boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages);
107112

108113
BoardPort boardPort = null;
@@ -168,6 +173,9 @@ public synchronized void retriggerDiscovery(boolean polled) {
168173

169174
@Override
170175
public void run() {
176+
if (BaseNoGui.packages == null) {
177+
return;
178+
}
171179
retriggerDiscovery(true);
172180
}
173181
}

0 commit comments

Comments
 (0)