Skip to content

Commit 4436c75

Browse files
author
jan
committed
Improved option management
SetOptions does not replace options but adds them. I also added a clean of any invalid menuID's
1 parent 6a99583 commit 4436c75

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.List;
1414
import java.util.Map;
1515
import java.util.Map.Entry;
16+
import java.util.Set;
1617
import java.util.TreeMap;
1718

1819
import org.eclipse.cdt.core.parser.util.StringUtil;
@@ -323,7 +324,7 @@ public BoardDescription(BoardDescription srcObject) {
323324
myUploadPort = srcObject.myUploadPort;
324325
myProgrammer = srcObject.myProgrammer;
325326
myUploadTool = srcObject.myUploadTool;
326-
myOptions = new TreeMap<>(srcObject.myOptions);
327+
myOptions.putAll( new TreeMap<>(srcObject.myOptions));
327328

328329
}
329330

@@ -355,6 +356,17 @@ private void setDefaultOptions() {
355356
}
356357
}
357358

359+
private void removeInvalidMenuIDs() {
360+
Set<String> allMenuIDs = this.mySloeberBoardTxtFile.getMenus().keySet();
361+
Set<String> optionKey=myOptions.keySet();
362+
363+
for ( String curOptionKey : optionKey) {
364+
if(!allMenuIDs.contains(curOptionKey)) {
365+
myOptions.remove(curOptionKey);
366+
}
367+
}
368+
}
369+
358370
/**
359371
* Store the selections the user made so we can reuse them when creating a new
360372
* project
@@ -452,13 +464,18 @@ public void setreferencingBoardsFile(File boardsFile) {
452464
mySloeberBoardTxtFile = new BoardTxtFile(resolvePathEnvironmentString(myUserSelectedBoardsTxtFile));
453465

454466
}
455-
467+
/**
468+
* seOptions add the options to the already existing options and removes the options
469+
* with an invalid menuID
470+
* The enuitemID is not verified and assumed correct.
471+
*
472+
*/
456473
public void setOptions(Map<String, String> options) {
457-
if (options == null) {
474+
if (options == null || options.size()==0) {
458475
return;
459476
}
460-
myOptions.clear();
461477
myOptions.putAll(options);
478+
removeInvalidMenuIDs();
462479
setDirty();
463480
}
464481

io.sloeber.tests/src/io/sloeber/providers/Teensy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public static MCUBoard teensy2() {
5252
return new Teensy(Teensy_2_ID);
5353
}
5454

55-
private Teensy(String boardName) {
55+
private Teensy(String boardID) {
5656
Map<String, String> options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
5757
options.put("usb", "serialhid");
5858
options.put("speed", "48");
5959
options.put("opt", "o2std");
6060
options.put("keys", "en-us");
61-
switch (boardName) {
61+
switch (boardID) {
6262
case Teensy_PP2_ID:
6363
options.put("speed", "8");
6464
break;
@@ -71,7 +71,7 @@ private Teensy(String boardName) {
7171
default:
7272
break;
7373
}
74-
myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, TEENSY_PROVIDER, TEENSY_PLATFORM_ID,boardName,options);
74+
myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, TEENSY_PROVIDER, TEENSY_PLATFORM_ID,boardID,options);
7575

7676
setUploadPort("none");
7777
setAttributes();
@@ -115,7 +115,7 @@ public Map<String, String> getBoardOptions(Example example) {
115115

116116
@Override
117117
public MCUBoard createMCUBoard(BoardDescription boardDescriptor) {
118-
return new Teensy(boardDescriptor);
118+
return new Teensy(boardDescriptor.getBoardID());
119119

120120
}
121121

0 commit comments

Comments
 (0)