Skip to content

Commit e66f869

Browse files
committed
Support ESP32, Manually select ELF if not found
1 parent ba1b702 commit e66f869

File tree

1 file changed

+77
-42
lines changed

1 file changed

+77
-42
lines changed

src/EspExceptionDecoder.java

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.*;
3131
import java.util.regex.*;
3232
import javax.swing.*;
33+
import javax.swing.filechooser.*;
3334
import javax.swing.event.DocumentEvent;
3435
import javax.swing.event.DocumentListener;
3536
import org.apache.commons.codec.digest.DigestUtils;
@@ -121,43 +122,43 @@ public void run() {
121122
}
122123

123124
private String getBuildFolderPath(Sketch s) {
124-
// first of all try the getBuildPath() function introduced with IDE 1.6.12
125-
// see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03
126-
try {
127-
String buildpath = s.getBuildPath().getAbsolutePath();
128-
return buildpath;
129-
}
130-
catch (IOException er) {
131-
editor.statusError(er);
132-
}
133-
catch (Exception er) {
134-
try {
135-
File buildFolder = FileUtils.createTempFolder("build", DigestUtils.md5Hex(s.getMainFilePath()) + ".tmp");
136-
//DeleteFilesOnShutdown.add(buildFolder);
137-
return buildFolder.getAbsolutePath();
138-
}
139-
catch (IOException e) {
140-
editor.statusError(e);
141-
}
142-
catch (Exception e) {
143-
// Arduino 1.6.5 doesn't have FileUtils.createTempFolder
144-
// String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath();
145-
java.lang.reflect.Method method;
146-
try {
147-
method = BaseNoGui.class.getMethod("getBuildFolder");
148-
File f = (File) method.invoke(null);
149-
return f.getAbsolutePath();
150-
} catch (SecurityException ex) {
151-
editor.statusError(ex);
152-
} catch (IllegalAccessException ex) {
153-
editor.statusError(ex);
154-
} catch (InvocationTargetException ex) {
155-
editor.statusError(ex);
156-
} catch (NoSuchMethodException ex) {
157-
editor.statusError(ex);
158-
}
159-
}
160-
}
125+
// first of all try the getBuildPath() function introduced with IDE 1.6.12
126+
// see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03
127+
try {
128+
String buildpath = s.getBuildPath().getAbsolutePath();
129+
return buildpath;
130+
}
131+
catch (IOException er) {
132+
editor.statusError(er);
133+
}
134+
catch (Exception er) {
135+
try {
136+
File buildFolder = FileUtils.createTempFolder("build", DigestUtils.md5Hex(s.getMainFilePath()) + ".tmp");
137+
//DeleteFilesOnShutdown.add(buildFolder);
138+
return buildFolder.getAbsolutePath();
139+
}
140+
catch (IOException e) {
141+
editor.statusError(e);
142+
}
143+
catch (Exception e) {
144+
// Arduino 1.6.5 doesn't have FileUtils.createTempFolder
145+
// String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath();
146+
java.lang.reflect.Method method;
147+
try {
148+
method = BaseNoGui.class.getMethod("getBuildFolder");
149+
File f = (File) method.invoke(null);
150+
return f.getAbsolutePath();
151+
} catch (SecurityException ex) {
152+
editor.statusError(ex);
153+
} catch (IllegalAccessException ex) {
154+
editor.statusError(ex);
155+
} catch (InvocationTargetException ex) {
156+
editor.statusError(ex);
157+
} catch (NoSuchMethodException ex) {
158+
editor.statusError(ex);
159+
}
160+
}
161+
}
161162
return "";
162163
}
163164

@@ -169,14 +170,39 @@ private long getIntPref(String name){
169170
else return Integer.parseInt(data);
170171
}
171172

173+
class ElfFilter extends FileFilter {
174+
public String getExtension(File f) {
175+
String ext = null;
176+
String s = f.getName();
177+
int i = s.lastIndexOf('.');
178+
if (i > 0 && i < s.length() - 1) {
179+
ext = s.substring(i+1).toLowerCase();
180+
}
181+
return ext;
182+
}
183+
public boolean accept(File f) {
184+
if (f.isDirectory()) {
185+
return true;
186+
}
187+
String extension = getExtension(f);
188+
if (extension != null) {
189+
return extension.equals("elf");
190+
}
191+
return false;
192+
}
193+
public String getDescription() {
194+
return "*.elf files";
195+
}
196+
}
197+
172198
private void createAndUpload(){
173-
if(!PreferencesData.get("target_platform").contentEquals("esp8266") && !PreferencesData.get("target_platform").contentEquals("esp31b") && !PreferencesData.get("target_platform").contentEquals("ESP31B")){
199+
if(!PreferencesData.get("target_platform").contentEquals("esp8266") && !PreferencesData.get("target_platform").contentEquals("esp32") && !PreferencesData.get("target_platform").contentEquals("ESP31B")){
174200
System.err.println();
175201
editor.statusError("Not Supported on "+PreferencesData.get("target_platform"));
176202
return;
177203
}
178204

179-
String tc = "esp108";
205+
String tc = "esp32";
180206
if(PreferencesData.get("target_platform").contentEquals("esp8266")){
181207
tc = "lx106";
182208
}
@@ -205,9 +231,18 @@ private void createAndUpload(){
205231
if (!elf.exists() || !elf.isFile()) {
206232
elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".cpp.elf");
207233
if (!elf.exists() || !elf.isFile()){
208-
editor.statusError("ERROR: neither "+editor.getSketch().getName() + ".ino.elf or "+editor.getSketch().getName() + ".cpp.elf were found!");
209-
System.err.println("Did you forget to compile the sketch?");
210-
return;
234+
//lets give the user a chance to select the elf
235+
final JFileChooser fc = new JFileChooser();
236+
fc.addChoosableFileFilter(new ElfFilter());
237+
fc.setAcceptAllFileFilterUsed(false);
238+
int returnVal = fc.showDialog(editor, "Select ELF");
239+
if (returnVal == JFileChooser.APPROVE_OPTION) {
240+
elf = fc.getSelectedFile();
241+
} else {
242+
editor.statusError("ERROR: elf was not found!");
243+
System.err.println("Open command cancelled by user.");
244+
return;
245+
}
211246
}
212247
}
213248

0 commit comments

Comments
 (0)