Skip to content

Commit

Permalink
Added a choice to "Erase All Flash" at the end of FS type selections
Browse files Browse the repository at this point in the history
Updated assets
  • Loading branch information
lorol committed Oct 9, 2020
1 parent fee9640 commit 9efcdb7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Arduino ESP32 filesystem uploader

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

## Notes for SPIFFS
Expand Down
97 changes: 95 additions & 2 deletions src/ESP32FS.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,98 @@ private void createAndUpload(){
}
}


private void eraseFlash(){

if(!PreferencesData.get("target_platform").contentEquals("esp32")){
System.err.println();
editor.statusError(typefs + " Not Supported on "+PreferencesData.get("target_platform"));
return;
}

TargetPlatform platform = BaseNoGui.getTargetPlatform();

String toolExtension = ".py";
if(PreferencesData.get("runtime.os").contentEquals("windows")) {
toolExtension = ".exe";
} else if(PreferencesData.get("runtime.os").contentEquals("macosx")) {
toolExtension = "";
}

String pythonCmd;
if(PreferencesData.get("runtime.os").contentEquals("windows"))
pythonCmd = "python.exe";
else
pythonCmd = "python";

Boolean isNetwork = false;

File esptool = new File(platform.getFolder()+"/tools");
String serialPort = PreferencesData.get("serial.port");

//make sure the serial port or IP is defined
if (serialPort == null || serialPort.isEmpty()) {
System.err.println();
editor.statusError(typefs + " Error: serial port not defined!");
return;
}

//find port
if(serialPort.split("\\.").length == 4){
isNetwork = true;
} else {
String esptoolCmd = "esptool"+toolExtension;
esptool = new File(platform.getFolder()+"/tools", esptoolCmd);
if(!esptool.exists() || !esptool.isFile()){
esptool = new File(platform.getFolder()+"/tools/esptool_py", esptoolCmd);
if(!esptool.exists() || !esptool.isFile()){
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
if(!esptool.exists() || !esptool.isFile()){
esptool = new File(PreferencesData.get("runtime.tools.esptool_py.path"), esptoolCmd);
if(!esptool.exists() || !esptool.isFile()){
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
if(!esptool.exists() || !esptool.isFile()){
System.err.println();
editor.statusError("Error: esptool not found!");
return;
}
}
}
}
}
}
System.out.println("esptool : "+esptool.getAbsolutePath());
System.out.println();

Object[] options = { "Yes", "No" };
String title = "Erase All Flash";
String message = "Are you sure?";

if(JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]) != JOptionPane.YES_OPTION){
System.err.println();
editor.statusError("Warning: Erase All Flash canceled!");
return;
}

editor.statusNotice("Erasing all Flash started...");
System.out.println("Erasing all Flash started...");

if(isNetwork){
System.out.println("Cannot be done through OTA, IP : "+serialPort);
System.out.println();
} else {
System.out.println("Port: "+serialPort);
System.out.println();
if(esptool.getAbsolutePath().endsWith(".py"))
sysExec(new String[]{pythonCmd, esptool.getAbsolutePath(), "--chip", "esp32", "--port", serialPort, "--before", "default_reset", "--after", "hard_reset", "erase_flash"});
else
sysExec(new String[]{esptool.getAbsolutePath(), "--chip", "esp32", "--port", serialPort, "--before", "default_reset", "--after", "hard_reset", "erase_flash"});
}
}

public void run() {
String sketchName = editor.getSketch().getName();
Object[] options = { "LittleFS", "SPIFFS", "FatFS" };
Object[] options = { "LittleFS", "SPIFFS", "FatFS", "!Erase Flash!" };
typefs = (String)JOptionPane.showInputDialog(editor,
"Select FS for " + sketchName +
" /data folder",
Expand All @@ -419,7 +508,11 @@ public void run() {
options,
"LittleFS");
if ((typefs != null) && (typefs.length() > 0)) {
createAndUpload();
if (typefs == "!Erase Flash!") {
eraseFlash();
} else {
createAndUpload();
}
} else {
System.out.println("Tool Exit.");
return;
Expand Down

0 comments on commit 9efcdb7

Please sign in to comment.