Skip to content

Commit 9efcdb7

Browse files
committed
Added a choice to "Erase All Flash" at the end of FS type selections
Updated assets
1 parent fee9640 commit 9efcdb7

File tree

2 files changed

+97
-3
lines changed

2 files changed

+97
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Arduino ESP32 filesystem uploader
22

33
- Arduino plugin which packs sketch data folder into SPIFFS, LittleFS or FatFS filesystem image,
4-
and uploads the image to ESP32 flash memory.
4+
and uploads the image to ESP32 flash memory.
5+
- Added a choice to "Erase all flash"
56
- You can have only one of three filesystems on same Arduino project.
67

78
## Notes for SPIFFS

src/ESP32FS.java

+95-2
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,98 @@ private void createAndUpload(){
407407
}
408408
}
409409

410+
411+
private void eraseFlash(){
412+
413+
if(!PreferencesData.get("target_platform").contentEquals("esp32")){
414+
System.err.println();
415+
editor.statusError(typefs + " Not Supported on "+PreferencesData.get("target_platform"));
416+
return;
417+
}
418+
419+
TargetPlatform platform = BaseNoGui.getTargetPlatform();
420+
421+
String toolExtension = ".py";
422+
if(PreferencesData.get("runtime.os").contentEquals("windows")) {
423+
toolExtension = ".exe";
424+
} else if(PreferencesData.get("runtime.os").contentEquals("macosx")) {
425+
toolExtension = "";
426+
}
427+
428+
String pythonCmd;
429+
if(PreferencesData.get("runtime.os").contentEquals("windows"))
430+
pythonCmd = "python.exe";
431+
else
432+
pythonCmd = "python";
433+
434+
Boolean isNetwork = false;
435+
436+
File esptool = new File(platform.getFolder()+"/tools");
437+
String serialPort = PreferencesData.get("serial.port");
438+
439+
//make sure the serial port or IP is defined
440+
if (serialPort == null || serialPort.isEmpty()) {
441+
System.err.println();
442+
editor.statusError(typefs + " Error: serial port not defined!");
443+
return;
444+
}
445+
446+
//find port
447+
if(serialPort.split("\\.").length == 4){
448+
isNetwork = true;
449+
} else {
450+
String esptoolCmd = "esptool"+toolExtension;
451+
esptool = new File(platform.getFolder()+"/tools", esptoolCmd);
452+
if(!esptool.exists() || !esptool.isFile()){
453+
esptool = new File(platform.getFolder()+"/tools/esptool_py", esptoolCmd);
454+
if(!esptool.exists() || !esptool.isFile()){
455+
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
456+
if(!esptool.exists() || !esptool.isFile()){
457+
esptool = new File(PreferencesData.get("runtime.tools.esptool_py.path"), esptoolCmd);
458+
if(!esptool.exists() || !esptool.isFile()){
459+
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
460+
if(!esptool.exists() || !esptool.isFile()){
461+
System.err.println();
462+
editor.statusError("Error: esptool not found!");
463+
return;
464+
}
465+
}
466+
}
467+
}
468+
}
469+
}
470+
System.out.println("esptool : "+esptool.getAbsolutePath());
471+
System.out.println();
472+
473+
Object[] options = { "Yes", "No" };
474+
String title = "Erase All Flash";
475+
String message = "Are you sure?";
476+
477+
if(JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]) != JOptionPane.YES_OPTION){
478+
System.err.println();
479+
editor.statusError("Warning: Erase All Flash canceled!");
480+
return;
481+
}
482+
483+
editor.statusNotice("Erasing all Flash started...");
484+
System.out.println("Erasing all Flash started...");
485+
486+
if(isNetwork){
487+
System.out.println("Cannot be done through OTA, IP : "+serialPort);
488+
System.out.println();
489+
} else {
490+
System.out.println("Port: "+serialPort);
491+
System.out.println();
492+
if(esptool.getAbsolutePath().endsWith(".py"))
493+
sysExec(new String[]{pythonCmd, esptool.getAbsolutePath(), "--chip", "esp32", "--port", serialPort, "--before", "default_reset", "--after", "hard_reset", "erase_flash"});
494+
else
495+
sysExec(new String[]{esptool.getAbsolutePath(), "--chip", "esp32", "--port", serialPort, "--before", "default_reset", "--after", "hard_reset", "erase_flash"});
496+
}
497+
}
498+
410499
public void run() {
411500
String sketchName = editor.getSketch().getName();
412-
Object[] options = { "LittleFS", "SPIFFS", "FatFS" };
501+
Object[] options = { "LittleFS", "SPIFFS", "FatFS", "!Erase Flash!" };
413502
typefs = (String)JOptionPane.showInputDialog(editor,
414503
"Select FS for " + sketchName +
415504
" /data folder",
@@ -419,7 +508,11 @@ public void run() {
419508
options,
420509
"LittleFS");
421510
if ((typefs != null) && (typefs.length() > 0)) {
422-
createAndUpload();
511+
if (typefs == "!Erase Flash!") {
512+
eraseFlash();
513+
} else {
514+
createAndUpload();
515+
}
423516
} else {
424517
System.out.println("Tool Exit.");
425518
return;

0 commit comments

Comments
 (0)