mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Moved some parameter processing methods from Base to BaseNoGui.
This commit is contained in:
committed by
Cristian Maglie
parent
abe6ff5f32
commit
443f7a7150
@ -463,59 +463,11 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void processBoardArgument(String selectBoard) {
|
protected void processBoardArgument(String selectBoard) {
|
||||||
// No board selected? Nothing to do
|
BaseNoGui.processBoardArgument(selectBoard);
|
||||||
if (selectBoard == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
String[] split = selectBoard.split(":", 4);
|
|
||||||
|
|
||||||
if (split.length < 3) {
|
|
||||||
showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TargetPackage targetPackage = getTargetPackage(split[0]);
|
|
||||||
if (targetPackage == null) {
|
|
||||||
showError(null, I18n.format(_("{0}: Unknown package"), split[0]), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TargetPlatform targetPlatform = targetPackage.get(split[1]);
|
|
||||||
if (targetPlatform == null) {
|
|
||||||
showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TargetBoard targetBoard = targetPlatform.getBoard(split[2]);
|
|
||||||
if (targetBoard == null) {
|
|
||||||
showError(null, I18n.format(_("{0}: Unknown board"), split[2]), 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
selectBoard(targetBoard);
|
|
||||||
|
|
||||||
if (split.length > 3) {
|
|
||||||
String[] options = split[3].split(",");
|
|
||||||
for (String option : options) {
|
|
||||||
String[] keyValue = option.split("=", 2);
|
|
||||||
|
|
||||||
if (keyValue.length != 2)
|
|
||||||
showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), 3);
|
|
||||||
String key = keyValue[0].trim();
|
|
||||||
String value = keyValue[1].trim();
|
|
||||||
|
|
||||||
if (!targetBoard.hasMenu(key))
|
|
||||||
showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), 3);
|
|
||||||
if (targetBoard.getMenuLabel(key, value) == null)
|
|
||||||
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
|
|
||||||
|
|
||||||
Preferences.set("custom_" + key, targetBoard.getId() + "_" + value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processPrefArgument(String arg) {
|
protected void processPrefArgument(String arg) {
|
||||||
String[] split = arg.split("=", 2);
|
BaseNoGui.processPrefArgument(arg);
|
||||||
if (split.length != 2 || split[0].isEmpty())
|
|
||||||
showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), 3);
|
|
||||||
|
|
||||||
Preferences.set(split[0], split[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1483,24 +1435,11 @@ public class Base {
|
|||||||
|
|
||||||
|
|
||||||
private void selectBoard(TargetBoard targetBoard) {
|
private void selectBoard(TargetBoard targetBoard) {
|
||||||
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
|
BaseNoGui.selectBoard(targetBoard);
|
||||||
TargetPackage targetPackage = targetPlatform.getContainerPackage();
|
|
||||||
|
|
||||||
Preferences.set("target_package", targetPackage.getId());
|
|
||||||
Preferences.set("target_platform", targetPlatform.getId());
|
|
||||||
Preferences.set("board", targetBoard.getId());
|
|
||||||
|
|
||||||
File platformFolder = targetPlatform.getFolder();
|
|
||||||
Preferences.set("runtime.platform.path", platformFolder.getAbsolutePath());
|
|
||||||
Preferences.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void selectSerialPort(String port) {
|
public static void selectSerialPort(String port) {
|
||||||
Preferences.set("serial.port", port);
|
BaseNoGui.selectSerialPort(port);
|
||||||
if (port.startsWith("/dev/"))
|
|
||||||
Preferences.set("serial.port.file", port.substring(5));
|
|
||||||
else
|
|
||||||
Preferences.set("serial.port.file", port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rebuildProgrammerMenu(JMenu menu) {
|
public void rebuildProgrammerMenu(JMenu menu) {
|
||||||
@ -1903,7 +1842,7 @@ public class Base {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static public TargetPackage getTargetPackage(String packageName) {
|
static public TargetPackage getTargetPackage(String packageName) {
|
||||||
return BaseNoGui.packages.get(packageName);
|
return BaseNoGui.getTargetPackage(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,6 +259,16 @@ public class BaseNoGui {
|
|||||||
return getTargetPlatform().getBoard(boardId);
|
return getTargetPlatform().getBoard(boardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a specific TargetPackage
|
||||||
|
*
|
||||||
|
* @param packageName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static public TargetPackage getTargetPackage(String packageName) {
|
||||||
|
return packages.get(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently selected TargetPlatform.
|
* Returns the currently selected TargetPlatform.
|
||||||
*
|
*
|
||||||
@ -499,6 +509,62 @@ public class BaseNoGui {
|
|||||||
PreferencesData.init(absoluteFile(preferencesFile));
|
PreferencesData.init(absoluteFile(preferencesFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static protected void processBoardArgument(String selectBoard) {
|
||||||
|
// No board selected? Nothing to do
|
||||||
|
if (selectBoard == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String[] split = selectBoard.split(":", 4);
|
||||||
|
|
||||||
|
if (split.length < 3) {
|
||||||
|
showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
TargetPackage targetPackage = getTargetPackage(split[0]);
|
||||||
|
if (targetPackage == null) {
|
||||||
|
showError(null, I18n.format(_("{0}: Unknown package"), split[0]), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
TargetPlatform targetPlatform = targetPackage.get(split[1]);
|
||||||
|
if (targetPlatform == null) {
|
||||||
|
showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
TargetBoard targetBoard = targetPlatform.getBoard(split[2]);
|
||||||
|
if (targetBoard == null) {
|
||||||
|
showError(null, I18n.format(_("{0}: Unknown board"), split[2]), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectBoard(targetBoard);
|
||||||
|
|
||||||
|
if (split.length > 3) {
|
||||||
|
String[] options = split[3].split(",");
|
||||||
|
for (String option : options) {
|
||||||
|
String[] keyValue = option.split("=", 2);
|
||||||
|
|
||||||
|
if (keyValue.length != 2)
|
||||||
|
showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), 3);
|
||||||
|
String key = keyValue[0].trim();
|
||||||
|
String value = keyValue[1].trim();
|
||||||
|
|
||||||
|
if (!targetBoard.hasMenu(key))
|
||||||
|
showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), 3);
|
||||||
|
if (targetBoard.getMenuLabel(key, value) == null)
|
||||||
|
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
|
||||||
|
|
||||||
|
Preferences.set("custom_" + key, targetBoard.getId() + "_" + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected void processPrefArgument(String arg) {
|
||||||
|
String[] split = arg.split("=", 2);
|
||||||
|
if (split.length != 2 || split[0].isEmpty())
|
||||||
|
showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), 3);
|
||||||
|
|
||||||
|
PreferencesData.set(split[0], split[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively remove all files within a directory,
|
* Recursively remove all files within a directory,
|
||||||
* used with removeDir(), or when the contents of a dir
|
* used with removeDir(), or when the contents of a dir
|
||||||
@ -649,6 +715,27 @@ public class BaseNoGui {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static protected void selectBoard(TargetBoard targetBoard) {
|
||||||
|
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
|
||||||
|
TargetPackage targetPackage = targetPlatform.getContainerPackage();
|
||||||
|
|
||||||
|
PreferencesData.set("target_package", targetPackage.getId());
|
||||||
|
PreferencesData.set("target_platform", targetPlatform.getId());
|
||||||
|
PreferencesData.set("board", targetBoard.getId());
|
||||||
|
|
||||||
|
File platformFolder = targetPlatform.getFolder();
|
||||||
|
PreferencesData.set("runtime.platform.path", platformFolder.getAbsolutePath());
|
||||||
|
PreferencesData.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void selectSerialPort(String port) {
|
||||||
|
PreferencesData.set("serial.port", port);
|
||||||
|
if (port.startsWith("/dev/"))
|
||||||
|
PreferencesData.set("serial.port.file", port.substring(5));
|
||||||
|
else
|
||||||
|
PreferencesData.set("serial.port.file", port);
|
||||||
|
}
|
||||||
|
|
||||||
static public void showError(String title, String message, int exit_code) {
|
static public void showError(String title, String message, int exit_code) {
|
||||||
showError(title, message, null, exit_code);
|
showError(title, message, null, exit_code);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user