Skip to content

Commit 3c43d99

Browse files
author
Andrew Dalgleish
committed
Add support for a basic generic uploader.
1 parent 27994e7 commit 3c43d99

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed

app/src/processing/app/Sketch.java

+36-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
package processing.app;
2525

2626
import processing.app.debug.AvrdudeUploader;
27+
import processing.app.debug.BasicUploader;
2728
import processing.app.debug.Compiler;
2829
import processing.app.debug.RunnerException;
2930
import processing.app.debug.Sizer;
31+
import processing.app.debug.Target;
3032
import processing.app.debug.Uploader;
3133
import processing.app.preproc.*;
3234
import processing.core.*;
@@ -1694,6 +1696,39 @@ protected void size(String buildPath, String suggestedClassName)
16941696
_("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."));
16951697
}
16961698

1699+
/**
1700+
* Get the appropriate Uploader class to use.
1701+
*
1702+
* Currently this defaults to AvrdudeUploader.
1703+
* If you are using a programmer which has "programmer.uploader=basic", use BasicUploader
1704+
*/
1705+
private Uploader getUploader(boolean usingProgrammer) {
1706+
1707+
// if no protocol is specified for this board, assume it lacks a
1708+
// bootloader and upload using the selected programmer.
1709+
//
1710+
Map<String, String> boardPreferences = Base.getBoardPreferences();
1711+
if (usingProgrammer || boardPreferences.get("upload.protocol") == null) {
1712+
String programmer = Preferences.get("programmer");
1713+
Target target = Base.getTarget();
1714+
1715+
if (programmer.indexOf(":") != -1) {
1716+
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":")));
1717+
programmer = programmer.substring(programmer.indexOf(":") + 1);
1718+
}
1719+
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer);
1720+
1721+
// If the programmer has "programmer.uploader=basic" specified, use the BasicUploader
1722+
//
1723+
if ("basic".equals(programmerPreferences.get("uploader"))) {
1724+
return new BasicUploader();
1725+
}
1726+
}
1727+
1728+
// Use AvrdudeUploader by default.
1729+
//
1730+
return new AvrdudeUploader();
1731+
}
16971732

16981733
protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer)
16991734
throws RunnerException, SerialException {
@@ -1702,7 +1737,7 @@ protected String upload(String buildPath, String suggestedClassName, boolean usi
17021737

17031738
// download the program
17041739
//
1705-
uploader = new AvrdudeUploader();
1740+
uploader = getUploader(usingProgrammer);
17061741
boolean success = uploader.uploadUsingPreferences(buildPath,
17071742
suggestedClassName,
17081743
usingProgrammer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
BasicUploader - basic uploader implementation
5+
Part of the Arduino project - http://www.arduino.cc/
6+
7+
Copyright (c) 2012
8+
Andrew Dalgleish
9+
10+
This program is free software; you can redistribute it and/or modify
11+
it under the terms of the GNU General Public License as published by
12+
the Free Software Foundation; either version 2 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program; if not, write to the Free Software Foundation,
22+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23+
24+
$Id$
25+
*/
26+
27+
package processing.app.debug;
28+
29+
import processing.app.Base;
30+
import processing.app.Preferences;
31+
import processing.app.Serial;
32+
import processing.app.SerialException;
33+
34+
import java.io.*;
35+
import java.util.*;
36+
import java.util.zip.*;
37+
import javax.swing.*;
38+
import gnu.io.*;
39+
40+
41+
public class BasicUploader extends Uploader {
42+
public BasicUploader() {
43+
}
44+
45+
public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
46+
throws RunnerException, SerialException {
47+
this.verbose = verbose;
48+
49+
50+
// if no protocol is specified for this board, assume it lacks a
51+
// bootloader and upload using the selected programmer.
52+
Map<String, String> boardPreferences = Base.getBoardPreferences();
53+
if (!usingProgrammer && boardPreferences.get("upload.protocol") != null) {
54+
// We should never get here - BasicUploader is only for using a programmer
55+
return false;
56+
}
57+
58+
String programmer = Preferences.get("programmer");
59+
Target target = Base.getTarget();
60+
61+
if (programmer.indexOf(":") != -1) {
62+
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":")));
63+
programmer = programmer.substring(programmer.indexOf(":") + 1);
64+
}
65+
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer);
66+
67+
String command = programmerPreferences.get("uploader.basic.command");
68+
String parameters = programmerPreferences.get("uploader.basic.parameters");
69+
70+
List commandList = new ArrayList();
71+
72+
// Try our tools directories first, else assume the command includes the full path
73+
//
74+
if ((new File(Base.getHardwarePath() + "/tools/" + command)).exists()) {
75+
commandList.add(Base.getHardwarePath() + "/tools/" + command);
76+
} else if ((new File(Base.getHardwarePath() + "/tools/avr/bin/" + command)).exists()) {
77+
commandList.add(Base.getHardwarePath() + "/tools/avr/bin/" + command);
78+
} else {
79+
commandList.add(command);
80+
}
81+
82+
// If we have any parameters, split them using the first character
83+
// This lets us define any character for the separator, but you always need at least one.
84+
// For example:
85+
// |param1
86+
// /param1/param2
87+
//
88+
if (parameters != null) {
89+
90+
// Get the first character to use as a separator, and remove it
91+
//
92+
String separator = parameters.substring(0, 1);
93+
parameters = parameters.substring(1);
94+
95+
// While we have another separator, split the first part off and remember the rest
96+
//
97+
while (parameters.indexOf(separator) != -1) {
98+
commandList.add(parameters.substring(0, parameters.indexOf(separator)));
99+
parameters = parameters.substring(parameters.indexOf(separator)+1);
100+
}
101+
102+
// If we have any left, use it
103+
//
104+
if (parameters != null) {
105+
commandList.add(parameters);
106+
}
107+
}
108+
109+
// Add our hex file as the last parameter
110+
commandList.add(buildPath + File.separator + className + ".hex");
111+
112+
return executeUploadCommand(commandList);
113+
}
114+
115+
public boolean burnBootloader() throws RunnerException {
116+
// BasicUploader does not handle burning a bootloader
117+
return false;
118+
}
119+
120+
}

hardware/arduino/programmers.txt

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ arduinoisp.speed=19200
2929
avrdoper.name=AVR-Doper
3030
avrdoper.communication=avrdoper
3131
avrdoper.protocol=stk500v2
32+
33+
# bootloadHID
34+
bootloadhid.name=bootloadHID
35+
bootloadhid.uploader=basic
36+
bootloadhid.uploader.basic.command=bootloadHID.exe
37+
bootloadhid.uploader.basic.parameters=|-r

0 commit comments

Comments
 (0)