updated code to reflect upstream API changes

This commit is contained in:
Federico Fissore 2013-04-18 17:33:33 +02:00
parent 0c03dc8db9
commit 2f5d71fb59
3 changed files with 14 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import javax.swing.UIManager;
import com.sun.jna.Library; import com.sun.jna.Library;
import com.sun.jna.Native; import com.sun.jna.Native;
import processing.app.debug.TargetBoard;
import processing.app.debug.TargetPackage; import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform; import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap; import processing.app.helpers.PreferencesMap;
@ -147,14 +148,14 @@ public class Platform {
protected String resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String readVIDPID) { protected String resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String readVIDPID) {
for (TargetPackage targetPackage : packages.values()) { for (TargetPackage targetPackage : packages.values()) {
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) { for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
for (PreferencesMap board : targetPlatform.getBoards().values()) { for (TargetBoard board : targetPlatform.getBoards().values()) {
List<String> vids = new LinkedList<String>(board.createSubTree("vid").values()); List<String> vids = new LinkedList<String>(board.getPreferences().subTree("vid").values());
if (!vids.isEmpty()) { if (!vids.isEmpty()) {
List<String> pids = new LinkedList<String>(board.createSubTree("pid").values()); List<String> pids = new LinkedList<String>(board.getPreferences().subTree("pid").values());
for (int i = 0; i< vids.size(); i++) { for (int i = 0; i< vids.size(); i++) {
String vidPid = vids.get(i) + "_" + pids.get(i); String vidPid = vids.get(i) + "_" + pids.get(i);
if (vidPid.toUpperCase().equals(readVIDPID)) { if (vidPid.toUpperCase().equals(readVIDPID)) {
return board.get("name"); return board.getName();
} }
} }
} }

View File

@ -7,8 +7,8 @@ public class UploaderFactory {
private static final Pattern IPV4_ADDRESS = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); private static final Pattern IPV4_ADDRESS = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
public Uploader newUploader(Map<String, String> preferences, String port) { public Uploader newUploader(TargetBoard board, String port) {
if ("true".equals(preferences.get("upload.via_http")) && IPV4_ADDRESS.matcher(port).find()) { if ("true".equals(board.getPreferences().get("upload.via_http")) && IPV4_ADDRESS.matcher(port).find()) {
return new HttpUploader(port); return new HttpUploader(port);
} }

View File

@ -2,6 +2,7 @@ package processing.app.debug;
import org.junit.Test; import org.junit.Test;
import processing.app.AbstractWithPreferencesTest; import processing.app.AbstractWithPreferencesTest;
import processing.app.helpers.PreferencesMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -14,7 +15,8 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
public void shouldCreateAnInstanceOfHttpUploader() throws Exception { public void shouldCreateAnInstanceOfHttpUploader() throws Exception {
Map<String, String> prefs = new HashMap<String, String>(); Map<String, String> prefs = new HashMap<String, String>();
prefs.put("upload.via_http", "true"); prefs.put("upload.via_http", "true");
Uploader uploader = new UploaderFactory().newUploader(prefs, "192.168.0.1 (mydogstick)"); TargetBoard board = new TargetBoard("dummy", new PreferencesMap(prefs), null);
Uploader uploader = new UploaderFactory().newUploader(board, "192.168.0.1 (mydogstick)");
assertTrue(uploader instanceof HttpUploader); assertTrue(uploader instanceof HttpUploader);
} }
@ -22,7 +24,8 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
@Test @Test
public void shouldCreateAnInstanceOfBasicUploaderWhenHTTPIsUnsupported() throws Exception { public void shouldCreateAnInstanceOfBasicUploaderWhenHTTPIsUnsupported() throws Exception {
Map<String, String> prefs = new HashMap<String, String>(); Map<String, String> prefs = new HashMap<String, String>();
Uploader uploader = new UploaderFactory().newUploader(prefs, "192.168.0.1 (mydogstick)"); TargetBoard board = new TargetBoard("dummy", new PreferencesMap(prefs), null);
Uploader uploader = new UploaderFactory().newUploader(board, "192.168.0.1 (mydogstick)");
assertTrue(uploader instanceof BasicUploader); assertTrue(uploader instanceof BasicUploader);
} }
@ -30,7 +33,8 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
@Test @Test
public void shouldCreateAnInstanceOfBasicUploaderWhenPortIsSerial() throws Exception { public void shouldCreateAnInstanceOfBasicUploaderWhenPortIsSerial() throws Exception {
Map<String, String> prefs = new HashMap<String, String>(); Map<String, String> prefs = new HashMap<String, String>();
Uploader uploader = new UploaderFactory().newUploader(prefs, "/dev/ttyACM0 (Arduino Leonardo)"); TargetBoard board = new TargetBoard("dummy", new PreferencesMap(prefs), null);
Uploader uploader = new UploaderFactory().newUploader(board, "/dev/ttyACM0 (Arduino Leonardo)");
assertTrue(uploader instanceof BasicUploader); assertTrue(uploader instanceof BasicUploader);
} }