@@ -109,7 +109,7 @@ public class Base {
109
109
Editor activeEditor ;
110
110
111
111
112
- static public void main (String args []) {
112
+ static public void main (String args []) throws Exception {
113
113
try {
114
114
File versionFile = getContentFile ("lib/version.txt" );
115
115
if (versionFile .exists ()) {
@@ -240,7 +240,7 @@ static protected void initRequirements() {
240
240
}
241
241
242
242
243
- public Base (String [] args ) {
243
+ public Base (String [] args ) throws Exception {
244
244
platform .init (this );
245
245
246
246
// Get the sketchbook path, and make sure it's set properly
@@ -276,11 +276,28 @@ public Base(String[] args) {
276
276
// Setup board-dependent variables.
277
277
onBoardOrPortChange ();
278
278
279
- // Check if there were previously opened sketches to be restored
280
- boolean opened = restoreSketches ();
281
-
279
+ boolean opened = false ;
280
+ boolean doUpload = false ;
281
+ String selectBoard = null ;
282
+ String selectPort = null ;
282
283
// Check if any files were passed in on the command line
283
284
for (int i = 0 ; i < args .length ; i ++) {
285
+ if (args [i ].equals ("--upload" )) {
286
+ doUpload = true ;
287
+ continue ;
288
+ }
289
+ if (args [i ].equals ("--board" )) {
290
+ i ++;
291
+ if (i < args .length )
292
+ selectBoard = args [i ];
293
+ continue ;
294
+ }
295
+ if (args [i ].equals ("--port" )) {
296
+ i ++;
297
+ if (i < args .length )
298
+ selectPort = args [i ];
299
+ continue ;
300
+ }
284
301
String path = args [i ];
285
302
// Fix a problem with systems that use a non-ASCII languages. Paths are
286
303
// being passed in with 8.3 syntax, which makes the sketch loader code
@@ -299,6 +316,23 @@ public Base(String[] args) {
299
316
}
300
317
}
301
318
319
+ if (doUpload ) {
320
+ if (!opened )
321
+ throw new Exception (_ ("Can't open source sketch!" ));
322
+ Thread .sleep (2000 );
323
+ Editor editor = editors .get (0 );
324
+ if (selectPort != null )
325
+ editor .selectSerialPort (selectPort );
326
+ if (selectBoard != null )
327
+ selectBoard (selectBoard );
328
+ editor .exportHandler .run ();
329
+ System .exit (0 );
330
+ }
331
+
332
+ // Check if there were previously opened sketches to be restored
333
+ if (restoreSketches ())
334
+ opened = true ;
335
+
302
336
// Create a new empty window (will be replaced with any files to be opened)
303
337
if (!opened ) {
304
338
handleNew ();
@@ -1131,19 +1165,10 @@ public void rebuildBoardsMenu(JMenu menu) {
1131
1165
@ SuppressWarnings ("serial" )
1132
1166
AbstractAction action = new AbstractAction (boardName ) {
1133
1167
public void actionPerformed (ActionEvent actionevent ) {
1134
- Preferences .set ("target_package" , (String ) getValue ("package" ));
1135
- Preferences .set ("target_platform" , (String ) getValue ("platform" ));
1136
- Preferences .set ("board" , (String ) getValue ("board" ));
1137
-
1138
- onBoardOrPortChange ();
1139
- Sketch .buildSettingChanged ();
1140
- rebuildImportMenu (Editor .importMenu );
1141
- rebuildExamplesMenu (Editor .examplesMenu );
1168
+ selectBoard ((String ) getValue ("b" ));
1142
1169
}
1143
1170
};
1144
- action .putValue ("package" , packageName );
1145
- action .putValue ("platform" , platformName );
1146
- action .putValue ("board" , board );
1171
+ action .putValue ("b" , packageName + ":" + platformName + ":" + board );
1147
1172
JMenuItem item = new JRadioButtonMenuItem (action );
1148
1173
if (packageName .equals (selPackage ) &&
1149
1174
platformName .equals (selPlatform ) && board .equals (selBoard )) {
@@ -1155,7 +1180,20 @@ public void actionPerformed(ActionEvent actionevent) {
1155
1180
}
1156
1181
}
1157
1182
}
1158
-
1183
+
1184
+
1185
+ private void selectBoard (String selectBoard ) {
1186
+ String [] split = selectBoard .split (":" );
1187
+ Preferences .set ("target_package" , split [0 ]);
1188
+ Preferences .set ("target_platform" , split [1 ]);
1189
+ Preferences .set ("board" , split [2 ]);
1190
+ onBoardOrPortChange ();
1191
+ Sketch .buildSettingChanged ();
1192
+ rebuildImportMenu (Editor .importMenu );
1193
+ rebuildExamplesMenu (Editor .examplesMenu );
1194
+ }
1195
+
1196
+
1159
1197
public void rebuildProgrammerMenu (JMenu menu ) {
1160
1198
menu .removeAll ();
1161
1199
ButtonGroup group = new ButtonGroup ();
0 commit comments