1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-19 08:52:15 +01:00

Merged SerialDiscovery and SerialBoardLister

They perform basically the same task, SerialDiscovery just used to proxy
the calls to SerialBoardLister
This commit is contained in:
Cristian Maglie 2018-10-04 13:07:10 +02:00
parent 8d6fa72667
commit 3ccb2d97e1
3 changed files with 70 additions and 124 deletions

View File

@ -37,8 +37,8 @@ import java.util.List;
import java.util.Map;
import cc.arduino.packages.discoverers.PluggableDiscovery;
import cc.arduino.packages.discoverers.serial.SerialDiscovery;
import cc.arduino.packages.discoverers.NetworkDiscovery;
import cc.arduino.packages.discoverers.SerialDiscovery;
import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;

View File

@ -1,103 +0,0 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2013 Arduino LLC (http://www.arduino.cc/)
*/
package cc.arduino.packages.discoverers;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Discovery;
import cc.arduino.packages.discoverers.serial.SerialBoardsLister;
import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
public class SerialDiscovery implements Discovery, Runnable {
private Timer serialBoardsListerTimer;
private final List<BoardPort> serialBoardPorts;
private SerialBoardsLister serialBoardsLister = new SerialBoardsLister(this);
public SerialDiscovery() {
this.serialBoardPorts = new LinkedList<>();
}
@Override
public List<BoardPort> listDiscoveredBoards() {
return getSerialBoardPorts(false);
}
@Override
public List<BoardPort> listDiscoveredBoards(boolean complete) {
return getSerialBoardPorts(complete);
}
private List<BoardPort> getSerialBoardPorts(boolean complete) {
if (complete) {
return new LinkedList<>(serialBoardPorts);
}
List<BoardPort> onlineBoardPorts = new LinkedList<>();
for (BoardPort port : serialBoardPorts) {
if (port.isOnline() == true) {
onlineBoardPorts.add(port);
}
}
return onlineBoardPorts;
}
public void setSerialBoardPorts(List<BoardPort> newSerialBoardPorts) {
serialBoardPorts.clear();
serialBoardPorts.addAll(newSerialBoardPorts);
}
public void forceRefresh() {
serialBoardsLister.retriggerDiscovery(false);
}
public void setUploadInProgress(boolean param) {
serialBoardsLister.uploadInProgress = param;
}
public void pausePolling(boolean param) { serialBoardsLister.pausePolling = param;}
@Override
public void run() {
start();
}
@Override
public void start() {
this.serialBoardsListerTimer = new Timer(SerialBoardsLister.class.getName());
serialBoardsLister.start(serialBoardsListerTimer);
}
@Override
public void stop() {
this.serialBoardsListerTimer.purge();
}
}

View File

@ -29,29 +29,86 @@
package cc.arduino.packages.discoverers.serial;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.discoverers.SerialDiscovery;
import cc.arduino.packages.Discovery;
import processing.app.BaseNoGui;
import processing.app.Platform;
import processing.app.debug.TargetBoard;
import java.util.*;
public class SerialDiscovery implements Discovery, Runnable {
public class SerialBoardsLister extends TimerTask {
private final SerialDiscovery serialDiscovery;
private final List<BoardPort> boardPorts = new LinkedList<>();
private List<String> oldPorts = new LinkedList<>();
private Timer serialBoardsListerTimer;
private final List<BoardPort> serialBoardPorts = new ArrayList<>();
private final List<BoardPort> boardPorts = new ArrayList<>();
private final List<String> oldPorts = new ArrayList<>();
public boolean uploadInProgress = false;
public boolean pausePolling = false;
private BoardPort oldUploadBoardPort = null;
public SerialBoardsLister(SerialDiscovery serialDiscovery) {
this.serialDiscovery = serialDiscovery;
@Override
public List<BoardPort> listDiscoveredBoards() {
return listDiscoveredBoards(false);
}
public void start(Timer timer) {
timer.schedule(this, 0, 1000);
@Override
public List<BoardPort> listDiscoveredBoards(boolean complete) {
if (complete) {
return new ArrayList<>(serialBoardPorts);
}
List<BoardPort> onlineBoardPorts = new ArrayList<>();
for (BoardPort port : serialBoardPorts) {
if (port.isOnline() == true) {
onlineBoardPorts.add(port);
}
}
return onlineBoardPorts;
}
public void setSerialBoardPorts(List<BoardPort> newSerialBoardPorts) {
serialBoardPorts.clear();
serialBoardPorts.addAll(newSerialBoardPorts);
}
public void forceRefresh() {
retriggerDiscovery(false);
}
public void setUploadInProgress(boolean param) {
uploadInProgress = param;
}
public void pausePolling(boolean param) {
pausePolling = param;
}
@Override
public void run() {
start();
}
@Override
public void start() {
serialBoardsListerTimer = new Timer(SerialDiscovery.class.getName());
serialBoardsListerTimer.schedule(new TimerTask() {
@Override
public void run() {
if (BaseNoGui.packages != null) {
retriggerDiscovery(true);
}
}
}, 0, 1000);
}
@Override
public void stop() {
serialBoardsListerTimer.cancel();
}
public synchronized void retriggerDiscovery(boolean polled) {
@ -171,14 +228,6 @@ public class SerialBoardsLister extends TimerTask {
boardPorts.add(boardPort);
}
}
serialDiscovery.setSerialBoardPorts(boardPorts);
}
@Override
public void run() {
if (BaseNoGui.packages == null) {
return;
}
retriggerDiscovery(true);
setSerialBoardPorts(boardPorts);
}
}