-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restored FS/merge panel (work in progress)
- Loading branch information
Showing
10 changed files
with
872 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,229 @@ | ||
package com.arduino; | ||
|
||
import java.nio.file.*; | ||
|
||
import processing.app.Editor; | ||
import processing.app.Sketch; | ||
import processing.app.PreferencesData; | ||
import org.apache.commons.codec.digest.DigestUtils; | ||
import processing.app.BaseNoGui; | ||
import processing.app.debug.TargetPlatform; | ||
import processing.app.helpers.FileUtils; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.nio.file.*; | ||
import java.io.*; | ||
|
||
import com.serifpersia.esp32partitiontool.AppSettings; | ||
|
||
public class AppSettingsArduino extends AppSettings { | ||
|
||
private Editor editor; | ||
private boolean debug_ui = true; | ||
private boolean isWindows; | ||
private File defaultSketchbookFolder; | ||
private String toolsPathBase; | ||
private TargetPlatform platform; | ||
private String espotaCmd; | ||
private String esptoolCmd; | ||
private String genEsp32PartCmd; | ||
|
||
public AppSettingsArduino(Editor editor) { | ||
this.editor = editor; | ||
this.hasFSPanel = true; | ||
init(); | ||
} | ||
|
||
public void load() { | ||
// figure out what csv file is selected in the boards menu, and where it is | ||
TargetPlatform platform = BaseNoGui.getTargetPlatform(); | ||
String defaultCsvSaveDir = editor.getSketch().getFolder().toString(); | ||
String platformPath = platform.getFolder().toString(); | ||
String csvName = BaseNoGui.getBoardPreferences().get("build.partitions"); | ||
String customCsvName = BaseNoGui.getBoardPreferences().get("build.custom_partitions"); | ||
String variantName = BaseNoGui.getBoardPreferences().get("build.variant"); | ||
String variantPath = platformPath + "/variants/" + variantName; | ||
String partitionsPath = platformPath + "/tools/partitions"; | ||
String csvPath = partitionsPath + "/" + csvName + ".csv"; | ||
String variantCsvPath = null; | ||
public void init() { | ||
|
||
load(); | ||
|
||
set("csvDir.path", get("sketchDir.path") ); | ||
|
||
// check if the board uses a custom partition, could be stored in variants or | ||
// tools folder | ||
|
||
String partitionsPath = get("platform.path") + "/tools/partitions"; | ||
String csvPath = partitionsPath + "/" + get("build.partitions") + ".csv"; | ||
String variantCsvPath = null; | ||
|
||
if (BaseNoGui.getBoardPreferences().containsKey("build.custom_partitions")) { | ||
variantCsvPath = variantPath + "/" + customCsvName + ".csv"; | ||
variantCsvPath = get("variant.path") + "/" + get("build.custom_partitions") + ".csv"; | ||
} else { | ||
variantCsvPath = variantPath + "/" + csvName + ".csv"; | ||
variantCsvPath = get("variant.path") + "/" + get("build.partitions") + ".csv"; | ||
} | ||
|
||
System.out.println("build.custom_partitions = " + customCsvName); | ||
System.out.println("build.partitions = " + csvName); | ||
System.out.println("build.variant = " + variantName); | ||
System.out.println("variantCsvPath = " + variantCsvPath); | ||
System.out.println("csvPath = " + csvPath); | ||
|
||
String searchPaths[] = { defaultCsvSaveDir + "/partitions.csv", variantCsvPath, csvPath }; | ||
String searchPaths[] = { get("sketchDir.path") + "/partitions.csv", variantCsvPath, csvPath }; | ||
|
||
for (int i = 0; i < searchPaths.length; i++) { | ||
if (Files.exists(Paths.get(searchPaths[i]))) { | ||
// load csv file | ||
csvFilePath = searchPaths[i]; | ||
set("csvFile.path", searchPaths[i] ); | ||
break; | ||
} | ||
} | ||
|
||
if( debug_ui ) { | ||
prefs.forEach((key, value) -> { | ||
System.out.printf("%-24s : %s\n", key, value ); | ||
}); | ||
} | ||
} | ||
|
||
System.out.println("CSV File: " + csvFilePath); | ||
System.out.println("CSV Path: " + defaultCsvSaveDir); | ||
|
||
break; | ||
@Override | ||
public void load() { | ||
// figure out what csv file is selected in the boards menu, and where it is | ||
isWindows = PreferencesData.get("runtime.os").contentEquals("windows"); | ||
espotaCmd = "espota" + (isWindows ? ".exe" : ".py"); | ||
esptoolCmd = "esptool" + (isWindows ? ".exe" : ".py"); | ||
genEsp32PartCmd = "gen_esp32part" + (isWindows ? ".exe" : ".py"); | ||
defaultSketchbookFolder = BaseNoGui.getDefaultSketchbookFolder(); | ||
toolsPathBase = BaseNoGui.getToolsPath(); | ||
platform = BaseNoGui.getTargetPlatform(); | ||
set("sketch.name", editor.getSketch().getName() ); | ||
set("sketch.path", editor.getSketch().getMainFilePath() ); | ||
set("sketchDir.path", editor.getSketch().getFolder().getAbsolutePath() ); | ||
set("platform.path", platform.getFolder().toString() ); | ||
set("build.partitions", BaseNoGui.getBoardPreferences().get("build.partitions") ); | ||
set("build.custom_partitions", BaseNoGui.getBoardPreferences().get("build.custom_partitions") ); | ||
set("build.variant", BaseNoGui.getBoardPreferences().get("build.variant") ); | ||
set("variant.path", get("platform.path") + "/variants/" + get("build.variant") ); | ||
set("build.path", getBuildFolderPath() ); | ||
set("bootloader.path", getBootloaderImagePath() ); | ||
set("upload.speed", BaseNoGui.getBoardPreferences().get("upload.speed") ); | ||
set("serial.port", BaseNoGui.getBoardPreferences().get("serial.port") ); | ||
set("build.bootloader_addr", BaseNoGui.getBoardPreferences().get("build.bootloader_addr") ); | ||
set("build.mcu", BaseNoGui.getBoardPreferences().get("build.mcu") ); | ||
set("flashMode", BaseNoGui.getBoardPreferences().get("build.flash_mode") ); | ||
set("flashFreq", BaseNoGui.getBoardPreferences().get("build.flash_freq") ); | ||
set("pythonCmd", isWindows ? "python3.exe" : "python3"); | ||
set("espotaCmd", espotaCmd ); | ||
set("esptoolCmd", esptoolCmd ); | ||
set("genEsp32PartCmd", genEsp32PartCmd ); | ||
|
||
String espToolSearchPaths[] = { | ||
PreferencesData.get("runtime.tools.esptool_py.path"), // preferences.txt | ||
get("platform.path") + "/tools", get("platform.path") + "/tools/esptool_py", defaultSketchbookFolder + "/tools", | ||
defaultSketchbookFolder + "/tools/esptool_py", toolsPathBase, toolsPathBase + "/tools/esptool_py" }; | ||
|
||
if (!findFile(esptoolCmd, espToolSearchPaths, "esptool")) { | ||
editor.statusError(" Error: esptool not found!"); | ||
this.hasFSPanel = false; | ||
} | ||
|
||
// search for esptool.[py|exe] in all the following folders | ||
String otaToolSearchPaths[] = { //getProperty("espota.path"), // user.properties (always first) | ||
get("platform.path") + "/tools", defaultSketchbookFolder + "/tools", toolsPathBase, }; | ||
|
||
if (!findFile(espotaCmd, espToolSearchPaths, "espota")) { | ||
editor.statusError(" Error: espota not found!"); | ||
this.hasFSPanel = false; | ||
} | ||
|
||
if (!findFile(genEsp32PartCmd, espToolSearchPaths, "genEsp32Part")) { | ||
editor.statusError(" Error: genEsp32Part not found!"); | ||
this.hasFSPanel = false; | ||
} | ||
|
||
String[] fsNames = {"SPIFFS", "LittleFS", "FatFS"}; | ||
int size = fsNames.length; | ||
|
||
for (int i = 0; i < size; i++) { | ||
|
||
String toolBinName = "mk" + fsNames[i].toLowerCase(); | ||
String toolExeName = toolBinName + (isWindows ? ".exe" : ""); | ||
|
||
String toolPrefName = "runtime.tools." + toolBinName + ".path"; | ||
String toolPathPref = PreferencesData.get(toolPrefName); | ||
|
||
// search for mk{filesystem}fs binary in the following folders: | ||
String searchPaths[] = { // getProperty(toolBinName + ".path"), // user.properties (always first) | ||
toolPathPref, // preferences.txt (always second) | ||
get("platform.path") + "/tools", get("platform.path") + "/tools/" + toolBinName, | ||
defaultSketchbookFolder + "/tools", defaultSketchbookFolder + "/tools/" + toolBinName, | ||
toolsPathBase, toolsPathBase + "/" + toolBinName }; | ||
|
||
findFile(toolExeName, searchPaths, toolBinName); | ||
} | ||
|
||
} | ||
|
||
private String getBootloaderImagePath() { | ||
// precedence: source > variant > build files | ||
String searchPaths[] = { get("sketchDir.path") + "/bootloader.bin", // in source directory | ||
get("variant.path") + "/bootloader.bin", // in board variants directory | ||
get("build.path") + "/" + get("sketch.name") + ".ino" + ".bootloader.bin" // in build directory | ||
}; | ||
// walk the array | ||
for (int i = 0; i < searchPaths.length; i++) { | ||
if (Files.exists(Paths.get(searchPaths[i]))) { | ||
// got a match! | ||
return searchPaths[i]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private String findFile(String fileName, String searchPaths[]) { | ||
for (int j = 0; j < searchPaths.length; j++) { | ||
if (searchPaths[j] == null) | ||
continue; | ||
if (Files.exists(Paths.get(searchPaths[j] + "/" + fileName))) { | ||
return searchPaths[j] + "/" + fileName; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void save() { | ||
private boolean findFile(String fileName, String searchPaths[], String propertyName) { | ||
String full_path = findFile(fileName, searchPaths); | ||
boolean found = full_path != null; | ||
if (found) { // save found path in properties file | ||
//if (debug_ui) | ||
// System.out.println("[" + propertyName + "] => " + full_path); | ||
set(propertyName + ".path", full_path); | ||
} else { | ||
if (debug_ui) | ||
System.out.println("[" + propertyName + "] " + fileName + " not found in any tools folder"); | ||
} | ||
return found; | ||
} | ||
|
||
private String getBuildFolderPath() { | ||
Sketch sketch = editor.getSketch(); | ||
// first of all try the getBuildPath() function introduced with IDE 1.6.12 | ||
// see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03 | ||
try { | ||
String buildpath = sketch.getBuildPath().getAbsolutePath(); | ||
return buildpath; | ||
} catch (IOException er) { | ||
editor.statusError(er); | ||
} catch (Exception er) { | ||
try { | ||
File buildFolder = FileUtils.createTempFolder("build", | ||
DigestUtils.md5Hex(sketch.getMainFilePath()) + ".tmp"); | ||
return buildFolder.getAbsolutePath(); | ||
} catch (IOException e) { | ||
editor.statusError(e); | ||
} catch (Exception e) { | ||
// Arduino 1.6.5 doesn't have FileUtils.createTempFolder | ||
// String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath(); | ||
java.lang.reflect.Method method; | ||
try { | ||
method = BaseNoGui.class.getMethod("getBuildFolder"); | ||
File f = (File) method.invoke(null); | ||
return f.getAbsolutePath(); | ||
} catch (SecurityException ex) { | ||
editor.statusError(ex); | ||
} catch (IllegalAccessException ex) { | ||
editor.statusError(ex); | ||
} catch (InvocationTargetException ex) { | ||
editor.statusError(ex); | ||
} catch (NoSuchMethodException ex) { | ||
editor.statusError(ex); | ||
} | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
src/main/java/com/serifpersia/esp32partitiontool/AppSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
package com.serifpersia.esp32partitiontool; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class AppSettings { | ||
|
||
public String csvFilePath; | ||
public String defaultCsvSaveDir; | ||
public boolean hasFSPanel = false; | ||
public Map<String, String> prefs = new HashMap<>(); | ||
|
||
public String get( String key ) { | ||
return prefs.get( key ); | ||
} | ||
|
||
public String set( String key, String value ) { | ||
return prefs.put( key, value ); | ||
} | ||
|
||
// this method is meant to be overloaded by platformio or arduino AppSettings classes | ||
public void load() { | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.