From e62a7cbc3d9f6d99986d97a9b1817fb5a9160cac Mon Sep 17 00:00:00 2001 From: jantje Date: Mon, 22 Nov 2021 00:22:50 +0100 Subject: [PATCH] #1339 fix lots of todo's --- .../src/io/sloeber/core/Activator.java | 3 +- .../io/sloeber/core/api/BoardDescription.java | 21 +- .../io/sloeber/core/api/BoardsManager.java | 5 - .../io/sloeber/core/api/SloeberProject.java | 7 +- .../src/io/sloeber/core/tools/Libraries.java | 7 +- .../src/io/sloeber/core/txt/BoardTxtFile.java | 20 +- ...leArduinoIDEExamplesOnAVRHardwareTest.java | 135 ++--- ...CompileArduinoIDEExamplesOnTeensyTest.java | 4 +- ...ArduinoIDEExamplesonJantjesBoardsTest.java | 4 +- ...teAndCompileDefaultInoOnAllBoardsTest.java | 1 - .../core/CreateAndCompileExamplesTest.java | 4 +- .../CreateAndCompileLibraryExamplesTest.java | 8 +- .../src/io/sloeber/core/Example.java | 501 ++++++++++++++++++ .../src/io/sloeber/core/Examples.java | 501 ------------------ .../sloeber/core/NightlyBoardPatronTest.java | 6 +- .../src/io/sloeber/core/Shared.java | 2 +- .../src/io/sloeber/providers/Arduino.java | 493 +++++++++-------- .../src/io/sloeber/providers/Jantje.java | 4 +- .../src/io/sloeber/providers/MCUBoard.java | 6 +- .../src/io/sloeber/providers/Teensy.java | 4 +- 20 files changed, 867 insertions(+), 869 deletions(-) create mode 100644 io.sloeber.tests/src/io/sloeber/core/Example.java delete mode 100644 io.sloeber.tests/src/io/sloeber/core/Examples.java diff --git a/io.sloeber.core/src/io/sloeber/core/Activator.java b/io.sloeber.core/src/io/sloeber/core/Activator.java index 25bc9aad7..0bed083fb 100644 --- a/io.sloeber.core/src/io/sloeber/core/Activator.java +++ b/io.sloeber.core/src/io/sloeber/core/Activator.java @@ -207,8 +207,7 @@ private static void initializeImportantVariables() { try { workspace.setDescription(workspaceDesc); } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, e.getMessage(), e)); } // Make sure some important variables are being initialized InstancePreferences.setPrivateLibraryPaths(InstancePreferences.getPrivateLibraryPaths()); diff --git a/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java b/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java index e8fc4ba8e..62d0dd911 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java +++ b/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java @@ -279,12 +279,12 @@ private void ParseSection() { public static List makeBoardDescriptors(File boardFile, Map options) { BoardTxtFile txtFile = new BoardTxtFile(resolvePathEnvironmentString(boardFile)); List boards = new ArrayList<>(); - String[] allSectionNames = txtFile.getAllSectionNames(); - for (String curboardName : allSectionNames) { - Map boardSection = txtFile.getSection(txtFile.getIDFromNiceName(curboardName)); + List boardIDs = txtFile.getAllBoardIDs(); + for (String curboardID : boardIDs) { + Map boardSection = txtFile.getSection(curboardID); if (boardSection != null) { if (!"true".equalsIgnoreCase(boardSection.get("hide"))) { //$NON-NLS-1$ //$NON-NLS-2$ - boards.add(new BoardDescription(boardFile, txtFile.getIDFromNiceName(curboardName), options)); + boards.add(new BoardDescription(boardFile, curboardID, options)); } } } @@ -571,8 +571,7 @@ public Path getreferencingPlatformPath() { } } - //TODO rename add core - public PlatformTxtFile getreferencedPlatformFile() { + public PlatformTxtFile getreferencedCorePlatformFile() { updateWhenDirty(); if (myReferencedPlatformCore == null) { return null; @@ -584,8 +583,7 @@ public PlatformTxtFile getreferencedPlatformFile() { return null; } - //TODO rename add core - public IPath getReferencedLibraryPath() { + public IPath getReferencedCoreLibraryPath() { updateWhenDirty(); if (myReferencedPlatformCore == null) { return null; @@ -608,8 +606,7 @@ public String getUploadPatternKey() { return TOOLS + DOT + upLoadTool + DOT + UPLOAD + DOT + networkPrefix + PATTERN; } - //TODO rename add core - public IPath getreferencedHardwarePath() { + public IPath getreferencedCoreHardwarePath() { updateWhenDirty(); if (myReferencedPlatformCore == null) { return new Path(myBoardTxtFile.getLoadedFile().toString()).removeLastSegments(1); @@ -773,7 +770,7 @@ public Map getEnvVars() { allVars.putAll(pluginPreProcessingBoardsTxt.getBoardEnvironVars(getBoardID())); String architecture = getArchitecture(); - IPath coreHardwarePath = getreferencedHardwarePath(); + IPath coreHardwarePath = getreferencedCoreHardwarePath(); allVars.put(ENV_KEY_BUILD_ARCH, architecture.toUpperCase()); allVars.put(ENV_KEY_HARDWARE_PATH, coreHardwarePath.removeLastSegments(1).toOSString()); allVars.put(ENV_KEY_BUILD_SYSTEM_PATH, coreHardwarePath.append(SYSTEM).toOSString()); @@ -793,7 +790,7 @@ public Map getEnvVars() { allVars.put(ENV_KEY_BUILD_VARIANT_PATH, EMPTY); } - PlatformTxtFile referencedPlatfromFile = getreferencedPlatformFile(); + PlatformTxtFile referencedPlatfromFile = getreferencedCorePlatformFile(); // process the platform file referenced by the boards.txt if (referencedPlatfromFile != null) { allVars.putAll(referencedPlatfromFile.getAllEnvironVars()); diff --git a/io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java b/io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java index 659af3121..74e71ac03 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java @@ -289,11 +289,6 @@ public static void addPrivateHardwarePath(String newHardwarePath) { InstancePreferences.setPrivateHardwarePaths(newPaths); } - public static String[] getBoardNames(String boardFile) { - BoardTxtFile theBoardsFile = new BoardTxtFile(new File(boardFile)); - return theBoardsFile.getAllSectionNames(); - } - /** * Searches for all boards.txt files from the hardware folders and the boards * manager diff --git a/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java b/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java index 3d52c48aa..b0fc60b07 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java +++ b/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java @@ -1101,10 +1101,10 @@ private IStatus BuildTarget(String targetName) { try { IMakeTargetManager targetManager = MakeCorePlugin.getDefault().getTargetManager(); - IContainer targetResource = myProject.getFolder("Release"); + IContainer targetResource = myProject.getFolder("Release"); //$NON-NLS-1$ IMakeTarget target = targetManager.findTarget(targetResource, targetName); if (target == null) { - target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder"); + target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder"); //$NON-NLS-1$ target.setBuildTarget(targetName); targetManager.addTarget(targetResource, target); } @@ -1112,8 +1112,7 @@ private IStatus BuildTarget(String targetName) { target.build(new NullProgressMonitor()); } } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return new Status(IStatus.ERROR, CORE_PLUGIN_ID, e.getMessage(), e); } return Status.OK_STATUS; } diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java index 25aec3047..70129912f 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -117,7 +117,7 @@ private static Map findAllHarwareLibraries(ICConfigurationDescrip SloeberProject sProject = SloeberProject.getSloeberProject(project, false); BoardDescription boardDescriptor = sProject.getBoardDescription(confDesc.getName(), false); // first add the referenced - IPath libPath = boardDescriptor.getReferencedLibraryPath(); + IPath libPath = boardDescriptor.getReferencedCoreLibraryPath(); if (libPath != null) { ret.putAll(findAllSubFolders(libPath)); } @@ -426,10 +426,7 @@ public static void checkLibraries(IProject affectedProject) { .getLatestInstallableLibraries(uninstalledIncludedHeaders); if (!availableLibs.isEmpty()) { - // We now know which libraries to install - // TODO for now I just install but there should - // be some user - // interaction + // Ask the user which libs need installing availableLibs = installHandler.selectLibrariesToInstall(availableLibs); for (Entry curLib : availableLibs.entrySet()) { LibraryManager.install(curLib.getValue(), new NullProgressMonitor()); diff --git a/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java b/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java index 20581071f..bb3e89bd2 100644 --- a/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java +++ b/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java @@ -7,11 +7,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - public class BoardTxtFile extends TxtFile { public BoardTxtFile(File boardsFile) { @@ -28,7 +29,6 @@ private static File getActualTxtFile(File boardsFile) { return boardsFile; } - public String getMenuItemIDFromMenuItemName(String boardID, String menuID, String menuItemName) { // boardid."menu".menuid.menuitemid=name @@ -149,7 +149,6 @@ public Map getMenus() { return getSection(MENU); } - /** * this is public String[] getAllSectionNames (String[] toaddNames) with a empty * toaddnames @@ -173,7 +172,7 @@ public String[] getAllSectionNames() { * @author Trump * */ - String[] getAllSectionNames(String[] toaddNames) { + public String[] getAllSectionNames(String[] toaddNames) { HashSet allNames = new HashSet<>(); for (String curName : toaddNames) { @@ -193,6 +192,19 @@ String[] getAllSectionNames(String[] toaddNames) { return sBoards; } + public List getAllBoardIDs() { + List allBoardIDs = new LinkedList<>(); + for (String curKey : myData.getChildren().keySet()) { + if ((curKey != null) && (!curKey.isEmpty())) { + String theName = myData.getValue(curKey + DOT + NAME); + if ((theName != null) && (!theName.isEmpty())) { + allBoardIDs.add(curKey); + } + } + } + return allBoardIDs; + } + /** * Get all the key value pairs that need to be added to the environment * variables for the given boardID diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java index 44ea473a1..abfc7427b 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java @@ -9,11 +9,12 @@ * At the time of writing 560 examples are compiled * */ -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -34,72 +35,72 @@ @SuppressWarnings({ "nls" }) @RunWith(Parameterized.class) public class CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest { - private CodeDescription myCodeDescriptor; - private MCUBoard myBoard; - private String myProjectName; - private static int myBuildCounter = 0; - private static int myTotalFails = 0; - private static int maxFails = 50; - private static int mySkipAtStart = 0; - - public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(String projectName, CodeDescription codeDescriptor, - MCUBoard board) { - - myCodeDescriptor = codeDescriptor; - myBoard = board; - myProjectName = projectName; - } - - @SuppressWarnings("rawtypes") - @Parameters(name = " {0}") - public static Collection examples() { - Shared.waitForAllJobsToFinish(); - Preferences.setUseBonjour(false); - LinkedList examples = new LinkedList<>(); - MCUBoard[] allBoards = Arduino.getAllBoards(); - - TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); - for (Map.Entry curexample : exampleFolders.entrySet()) { - String fqn = curexample.getKey().trim(); - IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); - if (!skipExample(example)) { - ArrayList paths = new ArrayList<>(); - - paths.add(examplePath); - CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); - for (MCUBoard curboard : allBoards) { - if (curboard.isExampleSupported(example)) { - String projectName = Shared.getProjectName(codeDescriptor, example, curboard); - Object[] theData = new Object[] { projectName, codeDescriptor, curboard }; - examples.add(theData); - } - } - } - } - - return examples; - - } - - private static boolean skipExample(Examples example) { - // skip Teensy stuff on Arduino hardware - // Teensy is so mutch more advanced that most arduino avr hardware can not - // handle it - return example.getPath().toString().contains("Teensy"); - } - - @Test - public void testExample() { - - Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); - Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); - - if (!Shared.BuildAndVerify(myProjectName, myBoard.getBoardDescriptor(), myCodeDescriptor, + private CodeDescription myCodeDescriptor; + private MCUBoard myBoard; + private String myProjectName; + private static int myBuildCounter = 0; + private static int myTotalFails = 0; + private static int maxFails = 50; + private static int mySkipAtStart = 0; + + public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(String projectName, CodeDescription codeDescriptor, + MCUBoard board) { + + myCodeDescriptor = codeDescriptor; + myBoard = board; + myProjectName = projectName; + } + + @SuppressWarnings("rawtypes") + @Parameters(name = " {0}") + public static Collection examples() { + Shared.waitForAllJobsToFinish(); + Preferences.setUseBonjour(false); + LinkedList examples = new LinkedList<>(); + List allBoards = Arduino.getAllBoards(); + + TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); + for (Map.Entry curexample : exampleFolders.entrySet()) { + String fqn = curexample.getKey().trim(); + IPath examplePath = curexample.getValue(); + Example example = new Example(fqn, examplePath); + if (!skipExample(example)) { + ArrayList paths = new ArrayList<>(); + + paths.add(examplePath); + CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); + for (MCUBoard curboard : allBoards) { + if (curboard.isExampleSupported(example)) { + String projectName = Shared.getProjectName(codeDescriptor, example, curboard); + Object[] theData = new Object[] { projectName, codeDescriptor, curboard }; + examples.add(theData); + } + } + } + } + + return examples; + + } + + private static boolean skipExample(Example example) { + // skip Teensy stuff on Arduino hardware + // Teensy is so mutch more advanced that most arduino avr hardware can not + // handle it + return example.getPath().toString().contains("Teensy"); + } + + @Test + public void testExample() { + + Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); + Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); + + if (!Shared.BuildAndVerify(myProjectName, myBoard.getBoardDescriptor(), myCodeDescriptor, new CompileDescription())) { - myTotalFails++; - fail(Shared.getLastFailMessage()); - } - } + myTotalFails++; + fail(Shared.getLastFailMessage()); + } + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java index 4bd71988d..ef159192c 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java @@ -70,7 +70,7 @@ public static Collection examples() { for (Map.Entry curexample : exampleFolders.entrySet()) { String fqn = curexample.getKey().trim(); IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); + Example example = new Example(fqn, examplePath); if (!skipExample(example)) { ArrayList paths = new ArrayList<>(); paths.add(examplePath); @@ -94,7 +94,7 @@ public static Collection examples() { } @SuppressWarnings("unused") - private static boolean skipExample(Examples example) { + private static boolean skipExample(Example example) { // no need to skip examples in this test return false; } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java index d33bd14b1..1169fd1b1 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java @@ -59,7 +59,7 @@ public static Collection examples() { for (Map.Entry curexample : exampleFolders.entrySet()) { String fqn = curexample.getKey().trim(); IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); + Example example = new Example(fqn, examplePath); if (!skipExample(example)) { ArrayList paths = new ArrayList<>(); @@ -78,7 +78,7 @@ public static Collection examples() { } - private static boolean skipExample(Examples example) { + private static boolean skipExample(Example example) { switch (example.getFQN()) { case "example/10.StarterKit/BasicKit/p13_TouchSensorLamp": return true; diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java index 8ab970cc6..57fea7ac6 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java @@ -269,7 +269,6 @@ public static Collection boards() { List boards = new ArrayList<>(); for (File curBoardFile : BoardsManager.getAllBoardsFiles()) { - // TOFIX these options should not be set here but in IBoard.getOptions Map options = null; System.out.println("Adding boards of " + curBoardFile.toString()); boards.addAll(BoardDescription.makeBoardDescriptors(curBoardFile, options)); diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java index 078c341f3..1942f9449 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java @@ -75,9 +75,9 @@ public static Collection examples() { CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); String fqn=curexample.getKey(); - Examples example=new Examples(fqn,curexample.getValue()); + Example example=new Example(fqn,curexample.getValue()); // with the current amount of examples only do one - MCUBoard board = Examples.pickBestBoard(example, myBoards); + MCUBoard board = Example.pickBestBoard(example, myBoards); if (board != null) { BoardDescription curBoard = board.getBoardDescriptor(); if (curBoard != null) { diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java index 32bca4e1d..36fec502a 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java @@ -38,11 +38,11 @@ public class CreateAndCompileLibraryExamplesTest { private static int myBuildCounter = 0; private static int myTotalFails = 0; - private Examples myExample; + private Example myExample; private MCUBoard myBoard; @SuppressWarnings("unused") - public CreateAndCompileLibraryExamplesTest(String name, MCUBoard boardID, Examples example) { + public CreateAndCompileLibraryExamplesTest(String name, MCUBoard boardID, Example example) { myBoard = boardID; myExample = example; } @@ -66,10 +66,10 @@ public static Collection examples() { for (Map.Entry curexample : exampleFolders.entrySet()) { String fqn = curexample.getKey().trim(); IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); + Example example = new Example(fqn, examplePath); // with the current amount of examples only do one - MCUBoard curBoard = Examples.pickBestBoard(example, myBoards); + MCUBoard curBoard = Example.pickBestBoard(example, myBoards); if (curBoard != null) { Object[] theData = new Object[] { example.getLibName() + ":" + fqn + ":" + curBoard.getID(), curBoard, diff --git a/io.sloeber.tests/src/io/sloeber/core/Example.java b/io.sloeber.tests/src/io/sloeber/core/Example.java new file mode 100644 index 000000000..84e1b609b --- /dev/null +++ b/io.sloeber.tests/src/io/sloeber/core/Example.java @@ -0,0 +1,501 @@ +package io.sloeber.core; + +import java.util.LinkedList; + +import org.eclipse.core.runtime.IPath; + +import io.sloeber.providers.ESP32; +import io.sloeber.providers.MCUBoard; +import io.sloeber.providers.Teensy; + +@SuppressWarnings("nls") +public class Example { + private String myFQN; + private String myLibName; + private IPath myPath; + private BoardAttributes myRequiredBoardAttributes; + private static int noBoardFoundCount = 0; + + public BoardAttributes getRequiredBoardAttributes() { + return myRequiredBoardAttributes; + } + + public Example(String fqn, IPath path) { + myFQN = fqn; + myPath = path; + getLibNameFromPath(); + myRequiredBoardAttributes = new BoardAttributes(); + myRequiredBoardAttributes.serial = examplesUsingSerial().contains(myFQN); + myRequiredBoardAttributes.serial1 = examplesUsingSerial1().contains(myFQN); + myRequiredBoardAttributes.keyboard = examplesUsingKeyboard().contains(myFQN); + myRequiredBoardAttributes.flightSim = examplesUsingFlightSim().contains(myFQN); + myRequiredBoardAttributes.joyStick = examplesUsingJoyStick().contains(myFQN); + myRequiredBoardAttributes.mouse = examplesUsingMouse().contains(myFQN); + myRequiredBoardAttributes.wire1 = examplesUsingWire1().contains(myFQN); + myRequiredBoardAttributes.midi = examplesUsingMidi().contains(myFQN) || myFQN.contains("USB_MIDI"); + myRequiredBoardAttributes.teensy = myFQN.startsWith("Example/Teensy"); + myRequiredBoardAttributes.worksOutOfTheBox = !failingExamples().contains(myFQN); + myRequiredBoardAttributes.boardName = getRequiredBoardID(myFQN); + myRequiredBoardAttributes.mo_mcu = examplesUsingMCUmo().contains(fqn); + myRequiredBoardAttributes.rawHID = myFQN.contains("USB_RawHID"); + myRequiredBoardAttributes.buildInLed = myFQN.contains("Blink"); + myRequiredBoardAttributes = myRequiredBoardAttributes.or(Libraries.getRequiredBoardAttributes(getLibName())); + } + + private void getLibNameFromPath() { + myLibName = new String(); + String[] splits = myFQN.split("/"); + if (splits.length >= 2) { + if ("Library".equals(splits[0])) { + myLibName = splits[1]; + } + } + } + + public IPath getPath() { + return myPath; + } + + public String getLibName() { + return myLibName; + } + + public String getFQN() { + return myFQN; + } + + public String getInoName() { + return myPath.lastSegment(); + } + + private static LinkedList examplesUsingMidi() { + LinkedList myUsesMidiExampleList = new LinkedList<>(); + // myUsesMidiExampleList.add("Example/Teensy/USB_FlightSim/ThrottleServo"); + return myUsesMidiExampleList; + } + + private static LinkedList examplesUsingFlightSim() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_FlightSim/BlinkTransponder"); + ret.add("Example/Teensy/USB_FlightSim/FrameRateDisplay"); + ret.add("Example/Teensy/USB_FlightSim/NavFrequency"); + ret.add("Example/Teensy/USB_FlightSim/ThrottleServo"); + return ret; + } + + private static LinkedList examplesUsingSerial1() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/04.Communication/MultiSerial"); + ret.add("Example/04.Communication/SerialPassthrough"); + ret.add("Example/Teensy/Serial/EchoBoth"); + return ret; + } + + private static LinkedList examplesUsingKeyboard() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/09.USB/Keyboard/KeyboardLogout"); + ret.add("Example/09.USB/Keyboard/KeyboardMessage"); + ret.add("Example/09.USB/Keyboard/KeyboardReprogram"); + ret.add("Example/09.USB/Keyboard/KeyboardSerial"); + ret.add("Example/09.USB/Mouse/ButtonMouseControl"); + ret.add("Example/09.USB/Mouse/JoystickMouseControl"); + ret.add("Example/09.USB/KeyboardAndMouseControl"); + return ret; + } + + private static LinkedList examplesUsingSerial() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/01.Basics/AnalogReadSerial"); + ret.add("Example/01.Basics/DigitalReadSerial"); + ret.add("Example/01.Basics/ReadAnalogVoltage"); + ret.add("Example/02.Digital/DigitalInputPullup"); + ret.add("Example/02.Digital/StateChangeDetection"); + ret.add("Example/02.Digital/tonePitchFollower"); + ret.add("Example/03.Analog/AnalogInOutSerial"); + ret.add("Example/03.Analog/Smoothing"); + ret.add("Example/04.Communication/ASCIITable"); + ret.add("Example/04.Communication/Dimmer"); + ret.add("Example/04.Communication/Graph"); + ret.add("Example/04.Communication/Midi"); + ret.add("Example/04.Communication/PhysicalPixel"); + ret.add("Example/04.Communication/ReadASCIIString"); + ret.add("Example/04.Communication/SerialCallResponse"); + ret.add("Example/04.Communication/SerialCallResponseASCII"); + ret.add("Example/04.Communication/SerialEvent"); + ret.add("Example/04.Communication/VirtualColorMixer"); + ret.add("Example/05.Control/IfStatementConditional"); + ret.add("Example/05.Control/switchCase"); + ret.add("Example/05.Control/switchCase2"); + ret.add("Example/06.Sensors/ADXL3xx"); + ret.add("Example/06.Sensors/Knock"); + ret.add("Example/06.Sensors/Memsic2125"); + ret.add("Example/06.Sensors/Ping"); + ret.add("Example/08.Strings/CharacterAnalysis"); + ret.add("Example/08.Strings/StringAdditionOperator"); + ret.add("Example/08.Strings/StringAppendOperator"); + ret.add("Example/08.Strings/StringCaseChanges"); + ret.add("Example/08.Strings/StringCharacters"); + ret.add("Example/08.Strings/StringComparisonOperators"); + ret.add("Example/08.Strings/StringConstructors"); + ret.add("Example/08.Strings/StringIndexOf"); + ret.add("Example/08.Strings/StringLength"); + ret.add("Example/08.Strings/StringLengthTrim"); + ret.add("Example/08.Strings/StringReplace"); + ret.add("Example/08.Strings/StringStartsWithEndsWith"); + ret.add("Example/08.Strings/StringSubstring"); + ret.add("Example/08.Strings/StringToInt"); + ret.add("Example/10.StarterKit_BasicKit/p03_LoveOMeter"); + ret.add("Example/10.StarterKit_BasicKit/p04_ColorMixingLamp"); + ret.add("Example/10.StarterKit_BasicKit/p05_ServoMoodIndicator"); + ret.add("Example/10.StarterKit_BasicKit/p07_Keyboard"); + ret.add("Example/10.StarterKit_BasicKit/p12_KnockLock"); + ret.add("Example/10.StarterKit_BasicKit/p13_TouchSensorLamp"); + ret.add("Example/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo"); + ret.add("Example/11.ArduinoISP/ArduinoISP"); + ret.add("Example/Teensy/Tutorial3/HelloSerialMonitor"); + ret.add("Example/Teensy/Tutorial3/Pushbutton"); + ret.add("Example/Teensy/Tutorial3/PushbuttonPullup"); + ret.add("Example/Teensy/Tutorial3/PushbuttonRGBcolor"); + ret.add("Example/Teensy/Tutorial4/AnalogInput"); + ret.add("Example/Teensy/Tutorial4/TemperatureNumberOnly"); + ret.add("Example/Teensy/Tutorial4/TemperatureScaled"); + ret.add("Example/Teensy/Tutorial4/TemperatureScaledMulti"); + return ret; + } + + private static LinkedList examplesUsingJoyStick() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_Joystick/Basic"); + ret.add("Example/Teensy/USB_Joystick/Buttons"); + ret.add("Example/Teensy/USB_Joystick/Complete"); + return ret; + } + + private static LinkedList examplesUsingMouse() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_Joystick/Basic"); + ret.add("Example/Teensy/USB_Joystick/Buttons"); + ret.add("Example/Teensy/USB_Joystick/Complete"); + ret.add("Example/Teensy/USB_RawHID/Basic"); + return ret; + } + + private static LinkedList examplesUsingWire1() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_Joystick/Basic"); + ret.add("Example/Teensy/USB_Joystick/Buttons"); + ret.add("Example/Teensy/USB_Joystick/Complete"); + ret.add("Example/Teensy/USB_RawHID/Basic"); + ret.add("Library/Adafruit_BME280_Library/advancedsettings"); + ret.add("Library/AS3935MI/AS3935MI_LightningDetector_otherInterfaces"); + return ret; + } + + private static LinkedList examplesUsingMCUmo() { + LinkedList ret = new LinkedList<>(); + ret.add("Library/Adafruit_Circuit_Playground/CircuitPlaygroundFirmata_Express_CodeOrg"); + return ret; + } + + /* + * These examples that are known to fail + */ + private static LinkedList failingExamples() { + LinkedList ret = new LinkedList<>(); + /* + * Because you can not define a enum 2 times Sloeber can not add the enum in + * Sloeber.ino.cpp as a result the function declarations using these enums + * generate a error because the enum is not defined. The examples below fail due + * to this + */ + ret.add("Library/_2020Bot_Library/_2020Bot_Demo"); + // These examples are the processing part and are not a deal of sloeber + ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); + // manual action is needed for following examples + ret.add("Library/Accessories/CANCommander"); + ret.add("Library/Accessories_CANCommander"); + ret.add("Library/Accessories/Demo"); + ret.add("Library/Accessories/Full"); + ret.add("Library/Accessories/Group"); + ret.add("Library/Accessories/LightFading"); + ret.add("Library/Accessories/LMD18200"); + ret.add("Library/Accessories/Servos"); + ret.add("Library/Accessories/SignalFrench"); + ret.add("Library/Accessories/Signals4x3"); + ret.add("Library/Accessories/SimpleLed"); + ret.add("Library/Accessories/SimpleLedMulti"); + ret.add("Library/Accessories/Stepper"); + ret.add("Library/Accessory/Shield/OLED/example/Adafruit"); + ret.add("Library/Accessory/Shield/temp/humidity/oled"); + // at the time of testing there were case sensetivity issues + ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioRecording"); + ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioWavPlayer"); + ret.add("Library/AutoAnalogAudio/AudioRadioRelay"); + ret.add("Library/AutoAnalogAudio/WirelessMicrophone"); + ret.add("Library/AutoAnalogAudio/WirelessSpeaker"); + ret.add("Library/AutoAnalogAudio/WirelessTx_RPi"); + // needs to get the defines and includes right + ret.add("Library/Accessories/Locoduino.org/Programme4"); + ret.add("Library/Accessories/Locoduino.org/Programme5"); + // Should be build on a stm32 (nucleo as far as I get) + // but these bards require #927 (and probably more :-( + ret.add("Library/ADCTouchSensor/CapacitiveController"); + ret.add("Library/ADCTouchSensor/CapacitivePiano"); + // failed in SPI :-( + ret.add("Library/Adafruit_TinyFlash/TrinketPlayer"); + // not sure how this could work + ret.add("Library/Adafruit_VS1053_Library/feather_midi"); + // all kinds of incompatibility issues I guess + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8b_Use_Bluetooth_Signal_Strength_to_Control_Things"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8c_Change_Andee_Bluetooth_Device_Name"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8d_How_to_Read_and_Write_to_SD_Card"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8f_Using_Andee_IO_Pins_as_OUTPUT_Pins"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8g_Getting_Inputs_from_Andee_IO_Pins"); + ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9a_Get_Device_Bluetooth_MAC_Address_ANDROID_Only"); + ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9b_Filter_Devices_by_Bluetooth_MAC_Address_ANDROID_Only"); + // doc says not finished + ret.add("Library/ANT-Arduino/NativeAnt"); + // uses missing library MobileBLE + ret.add("Library/ArduinoBlue/differentialDriveCar"); + // defining struct/enum in ino file + ret.add("Library/ArduinoJson/JsonConfigFile"); + ret.add("Library/Arduboy2/RGBled"); + // error: no matching function for call to 'aREST_UI::addToBuffer(const char + ret.add("Library/aREST_UI/ESP8266"); + ret.add("Library/aREST_UI/WiFi_CC3000"); + ret.add("Library/aREST_UI/WildFire"); + // uses arduinoWIFI + ret.add("Library/Braccio/braccioOfUnoWiFi"); + // uses lib that does not has lib folder= include-.h + ret.add("Library/ArduinoCloud/SimpleCloudButtonYun"); + // usi!ng non exsisting methods + ret.add("Library/CAN-BUS_Shield/gpioRead"); + ret.add("Library/CAN-BUS_Shield/gpioWrite"); + // using defines inino file to generate functions (not supported in Sloeber) + ret.add("Library/Adafruit_VEML6070_Library/unittests"); + // uses a non existing header + ret.add("Library/AESLib/complex"); + // using wrong sdfat librarie + ret.add("Library/Arduino_OPL2_SimpleTone"); + ret.add("Library/Arduino_OPL2_Teensy_PlayDRO"); + ret.add("Library/Arduino_OPL2_Teensy_PlayIMF"); + // I don't recall why following examples didn't work + ret.add("Library/arduino_ess_ess_yun"); + ret.add("Library/arduino_ess_linkit_one_dweet"); + ret.add("Library/AD7193/AD7193_VoltageMeasurePsuedoDifferential_Example"); + ret.add("Library/bunny_cuberotate/cuberotate"); + ret.add("Library/XPT2046_Touchscreen/ILI9341Test"); + ret.add("Library/Adafruit_AHRS/ahrs_mahony"); + ret.add("Library/Adafruit_BLEFirmata/StandardFirmata"); + ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); + ret.add("Library/Adafruit_GPS_Library/due_shield_sdlog"); + ret.add("Library/Adafruit_Graphic_VFD_Display_Library/GraphicVFDtest"); + ret.add("Library/Adafruit_GPS_Library/locus_erase"); + ret.add("Library/Adafruit_GPS_Library/shield_sdlog"); + ret.add("Library/Adafruit_HX8357_Library/breakouttouchpaint"); + ret.add("Library/Adafruit_ILI9341/breakouttouchpaint"); + ret.add("Library/Adafruit_ILI9341/onoffbutton_breakout"); + ret.add("Library/Adafruit_GPS_Library/echo"); + ret.add("Library/Adafruit_LED_Backpack_Library/wavface"); + ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_i2c"); + ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_spi"); + ret.add("Library/Adafruit_ST7735_Library/soft_spitftbitmap"); + ret.add("Library/Adafruit_TCS34725/colorview/processing/colorview"); + ret.add("Library/Adafruit_TinyRGBLCDShield/TinyHelloWorld"); + ret.add("Library/Akafugu_TWILiquidCrystal_Library/change_address"); + ret.add("Library/Akafugu_WireRtc_Library/alarm"); + ret.add("Library/ALA/RgbStripButton"); + ret.add("Library/APA102/GameOfLife"); + ret.add("Library/arduino-menusystem/led_matrix"); + ret.add("Library/arduino-menusystem/led_matrix_animated"); + ret.add("Library/Arduino_Low_Power/TianStandby"); + ret.add("Library/aREST/BLE"); + ret.add("Library/aREST/ESP32"); + ret.add("Library/aREST/ESP32_cloud"); + ret.add("Library/ArduinoHttpClient/DweetGet"); + ret.add("Library/ArduinoMenu_library/adafruitGfx/lcdMono/lcdMono"); + ret.add("Library/ArduinoMenu_library/adafruitGfx/tft/tft"); + ret.add("Library/ArdVoice/Sample2-Complex"); + ret.add("Library/Aspen_SIM800/Access_HTTP"); + ret.add("Library/Awesome/advanced/how_fast"); + ret.add("Library/Awesome/advanced/lie_detector"); + ret.add("Library/AzureIoTUtility/simplesample_http"); + ret.add("Library/BLEPeripheral/ir_bridge"); + ret.add("Library/BLEPeripheral/temp_sensor"); + ret.add("Library/Brasilino/Basicos/controleGradual"); + ret.add("Library/ClosedCube_HDC1010/hdc1010demo"); + ret.add("Library/Chrono/Resolutions"); + ret.add("Library/Chrono/StopResume"); + ret.add("Library/ConfigurableFirmata/ConfigurableFirmataWiFi"); + ret.add("Library/ControleForno/configuravel"); + ret.add("Library/CopyThreads/c"); + ret.add("Library/ArduinoCloud/SimpleCloudButtoBrzo_I2C"); + ret.add("Library/CopyThreads/FromReadme"); + ret.add("Library/DallasTemperature/Multibus_simple"); + ret.add("Library/DecodeIR/InfraredDecode"); + ret.add("Library/AutoAnalogAudio/SimpleSine"); + ret.add("Library/DimSwitch/DimSwitchTester-ESP-MQTT"); + ret.add("Library/DS3231/echo_time"); + ret.add("Library/Easy_NeoPixels"); + ret.add("Library/DallasTemperature/AlarmHandler"); + ret.add("Library/AmazonDRS/amazonDashNfc"); + ret.add("Library/Andee/Lesson_02_Buttons/Lesson_2h_Using_Buttons_to_Control_Servos"); + ret.add("Library/Andee/Project_Christmas_Lights_and_Annoying_Music"); + ret.add("Library/Andee/Project_Rubber_Band_Launcher"); + ret.add("Library/Andee/Project_Time_Automated_Data_Logger"); + ret.add("Library/ANT-Arduino_library/NativeAnt"); + ret.add("Library/arduino-fsm/timed_switchoff"); + ret.add("Library/BME280/BME_280_BRZO_I2C_Test"); + ret.add("Library/Adafruit_seesaw_Library/DAP"); + // uses unknown NO_ERROR + ret.add("Library/ClosedCube_TCA9546A/tca9546a_sht31d"); + // uses dht.h from dht_sensor_lib + ret.add("Library/CMMC_MQTT_Connector/basic_dht"); + ret.add("Library/ArduinoLearningKitStarter/boardTest"); + // uses altsoftserial and then Serial2???? + ret.add("Library/CMMC_NB-IoT/example1"); + // some bu!g I guess + ret.add("Library/CopyThreads/ExamplesFromReadme"); + ret.add("Library/CRC_Simula_Arduino_IDE_Library/Simula_BehaviorTree"); + // empty sketch?? + ret.add("Library/DFW/ProvisionController"); + // error: 'mapSensor' was not declared in this scope + ret.add("Library/AD_Sensors/ConstrainAnalogSensor"); + // error: 'sensor' was not declared in this scope + ret.add("Library/AD_Sensors/MapAndConstrainAnalogSensor"); + // ess-yun.ino:17:12: error: no matching function for call to + // 'HttpClient::HttpClient()' + ret.add("Library/arduino-ess/ess-yun"); + // I have no linket board in test setup + ret.add("Library/arduino-ess/linkit-one-dweet"); + //cores\arduino/WString.h:38:74: error: statement-expressions + ret.add("Library/ArduinoTrace/TraceFromGlobalScope"); + // no matching function for call to 'aREST::handle(EthernetClient&)' + ret.add("Library/aREST/Ethernet"); + // AsciiMassage_servos.ino:75:37: error: no matching function for call to + // 'AsciiMassagePacker::streamEmpty(const char [6])' + ret.add("Library/AsciiMassage/AsciiMassage_servos"); + // \BH1750FVI_Simple.ino:33:10: error: 'class Serial_' has no member named + // 'printf' + ret.add("Library/BH1750FVI/BH1750FVI_Simple"); + // * This example not complete at all. + ret.add("Library/Blinker/Blinker_AUTO/AUTO_MQTT"); + // 3: error: 'StaticJsonBuffer' was not declared in this scope + ret.add("Library/Boodskap_Message_library/SimpleMessageUsage"); + return ret; + } + + /** + * Give a list of boards pick the board that is best to test this code Boards in + * the beginning of the array are prefered (first found ok algorithm) + * + * returns null if this code should not be tested return null if myBoards is + * empty returns the best known boarddescriptor to run this example + */ + public static MCUBoard pickBestBoard(Example example, MCUBoard myBoards[]) { + String libName = example.getLibName(); + String fqn = example.getFQN(); + if (myBoards.length == 0) { + return null; + } + + if (example.getRequiredBoardAttributes().worksOutOfTheBox) { + + // if example states which board it wants use that board + if (example.getRequiredBoardAttributes().boardName != null) { + String wantedBoardName = example.getRequiredBoardAttributes().boardName; + for (MCUBoard curBoard : myBoards) { + if (curBoard.getID().equals(wantedBoardName)) { + return curBoard; + } + } + } else { + // examples using DHT_sensor_library libraries are not found as the include is + // DHT.h + if (!libName.equals("DHT_sensor_library") && fqn.contains("DHT")) { + return null; + } + // if the boardname is in the libname or ino name pick this one + for (MCUBoard curBoard : myBoards) { + String curBoardName = curBoard.getSlangName().toLowerCase(); + if (libName.toLowerCase().contains(curBoardName) || fqn.toLowerCase().contains(curBoardName)) { + if (curBoard.isExampleSupported(example)) { + return curBoard; + } + } + } + // If the architecture is in the libname or boardname pick this one + for (MCUBoard curBoard : myBoards) { + String curArchitectureName = curBoard.getBoardDescriptor().getArchitecture().toLowerCase(); + if (libName.toLowerCase().contains(curArchitectureName) + || fqn.toLowerCase().contains(curArchitectureName)) { + if (curBoard.isExampleSupported(example)) { + return curBoard; + } + } + } + // if the example name contains teensy try teensy board + if (example.getFQN().toLowerCase().contains("teensy")) { + for (MCUBoard curBoard : myBoards) { + if (Teensy.class.isInstance(curBoard)) { + return curBoard; + } + } + } + // if the example name contains ESP32 try ESP32 board + if (example.getFQN().toLowerCase().contains("esp32")) { + for (MCUBoard curBoard : myBoards) { + if (ESP32.class.isInstance(curBoard)) { + return curBoard; + } + } + } + // if the example name contains ESP try ESP8266 board + // if (example.getFQN().toLowerCase().contains("esp")) { + // for (MCUBoard curBoard : myBoards) { + // if (ESP8266.class.isInstance(curBoard)) { + // return curBoard; + // } + // } + // } + //causes issues with response + + // Out of guesses based on the name. Take the first ok one + for (MCUBoard curBoard : myBoards) { + if (curBoard.isExampleSupported(example)) { + return curBoard; + } + } + } + } + System.out.println("No board found for " + Integer.toString(++noBoardFoundCount) + " " + example.getFQN()); + return null; + } + + private static String getRequiredBoardID(String fqn) { + switch (fqn) { + case "Library/Accessory_Shield/OLED_example_Adafruit": + case "Library/Accessory_Shield/temp_humidity_oled": + return "uno"; + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_NeoPixel": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Read": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Record": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Send": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Testpattern": + case "Library/Adafruit_Zero_FFT_Library/CircuitPlayground": + return "adafruit_circuitplayground_m0"; + case "Library/Adafruit_MiniMLX90614/templight": + return "gemma"; + case "Library/ArduinoThread/SensorThread": + return "due"; + case "Library/AudioFrequencyMeter/SimpleAudioFrequencyMeter": + case "Library/Adafruit_NeoPXL8/strandtest": + return "zero"; + case "Library/BLEPeripheral/iBeacon": + return "feather52"; + default: + return null; + } + + } +} diff --git a/io.sloeber.tests/src/io/sloeber/core/Examples.java b/io.sloeber.tests/src/io/sloeber/core/Examples.java deleted file mode 100644 index d40c79759..000000000 --- a/io.sloeber.tests/src/io/sloeber/core/Examples.java +++ /dev/null @@ -1,501 +0,0 @@ -package io.sloeber.core; - -import java.util.LinkedList; - -import org.eclipse.core.runtime.IPath; - -import io.sloeber.providers.ESP32; -import io.sloeber.providers.MCUBoard; -import io.sloeber.providers.Teensy; - -@SuppressWarnings("nls") -public class Examples { - private String myFQN; - private String myLibName; - private IPath myPath; - private BoardAttributes myRequiredBoardAttributes; - private static int noBoardFoundCount = 0; - - public BoardAttributes getRequiredBoardAttributes() { - return myRequiredBoardAttributes; - } - - public Examples(String fqn, IPath path) { - myFQN = fqn; - myPath = path; - getLibNameFromPath(); - myRequiredBoardAttributes = new BoardAttributes(); - myRequiredBoardAttributes.serial = examplesUsingSerial().contains(myFQN); - myRequiredBoardAttributes.serial1 = examplesUsingSerial1().contains(myFQN); - myRequiredBoardAttributes.keyboard = examplesUsingKeyboard().contains(myFQN); - myRequiredBoardAttributes.flightSim = examplesUsingFlightSim().contains(myFQN); - myRequiredBoardAttributes.joyStick = examplesUsingJoyStick().contains(myFQN); - myRequiredBoardAttributes.mouse = examplesUsingMouse().contains(myFQN); - myRequiredBoardAttributes.wire1 = examplesUsingWire1().contains(myFQN); - myRequiredBoardAttributes.midi = examplesUsingMidi().contains(myFQN) || myFQN.contains("USB_MIDI"); - myRequiredBoardAttributes.teensy = myFQN.startsWith("Example/Teensy"); - myRequiredBoardAttributes.worksOutOfTheBox = !failingExamples().contains(myFQN); - myRequiredBoardAttributes.boardName = getRequiredBoardID(myFQN); - myRequiredBoardAttributes.mo_mcu = examplesUsingMCUmo().contains(fqn); - myRequiredBoardAttributes.rawHID = myFQN.contains("USB_RawHID"); - myRequiredBoardAttributes.buildInLed = myFQN.contains("Blink"); - myRequiredBoardAttributes = myRequiredBoardAttributes.or(Libraries.getRequiredBoardAttributes(getLibName())); - } - - private void getLibNameFromPath() { - myLibName = new String(); - String[] splits = myFQN.split("/"); - if (splits.length >= 2) { - if ("Library".equals(splits[0])) { - myLibName = splits[1]; - } - } - } - - public IPath getPath() { - return myPath; - } - - public String getLibName() { - return myLibName; - } - - public String getFQN() { - return myFQN; - } - - public String getInoName() { - return myPath.lastSegment(); - } - - private static LinkedList examplesUsingMidi() { - LinkedList myUsesMidiExampleList = new LinkedList<>(); - // myUsesMidiExampleList.add("Example/Teensy/USB_FlightSim/ThrottleServo"); - return myUsesMidiExampleList; - } - - private static LinkedList examplesUsingFlightSim() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_FlightSim/BlinkTransponder"); - ret.add("Example/Teensy/USB_FlightSim/FrameRateDisplay"); - ret.add("Example/Teensy/USB_FlightSim/NavFrequency"); - ret.add("Example/Teensy/USB_FlightSim/ThrottleServo"); - return ret; - } - - private static LinkedList examplesUsingSerial1() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/04.Communication/MultiSerial"); - ret.add("Example/04.Communication/SerialPassthrough"); - ret.add("Example/Teensy/Serial/EchoBoth"); - return ret; - } - - private static LinkedList examplesUsingKeyboard() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/09.USB/Keyboard/KeyboardLogout"); - ret.add("Example/09.USB/Keyboard/KeyboardMessage"); - ret.add("Example/09.USB/Keyboard/KeyboardReprogram"); - ret.add("Example/09.USB/Keyboard/KeyboardSerial"); - ret.add("Example/09.USB/Mouse/ButtonMouseControl"); - ret.add("Example/09.USB/Mouse/JoystickMouseControl"); - ret.add("Example/09.USB/KeyboardAndMouseControl"); - return ret; - } - - private static LinkedList examplesUsingSerial() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/01.Basics/AnalogReadSerial"); - ret.add("Example/01.Basics/DigitalReadSerial"); - ret.add("Example/01.Basics/ReadAnalogVoltage"); - ret.add("Example/02.Digital/DigitalInputPullup"); - ret.add("Example/02.Digital/StateChangeDetection"); - ret.add("Example/02.Digital/tonePitchFollower"); - ret.add("Example/03.Analog/AnalogInOutSerial"); - ret.add("Example/03.Analog/Smoothing"); - ret.add("Example/04.Communication/ASCIITable"); - ret.add("Example/04.Communication/Dimmer"); - ret.add("Example/04.Communication/Graph"); - ret.add("Example/04.Communication/Midi"); - ret.add("Example/04.Communication/PhysicalPixel"); - ret.add("Example/04.Communication/ReadASCIIString"); - ret.add("Example/04.Communication/SerialCallResponse"); - ret.add("Example/04.Communication/SerialCallResponseASCII"); - ret.add("Example/04.Communication/SerialEvent"); - ret.add("Example/04.Communication/VirtualColorMixer"); - ret.add("Example/05.Control/IfStatementConditional"); - ret.add("Example/05.Control/switchCase"); - ret.add("Example/05.Control/switchCase2"); - ret.add("Example/06.Sensors/ADXL3xx"); - ret.add("Example/06.Sensors/Knock"); - ret.add("Example/06.Sensors/Memsic2125"); - ret.add("Example/06.Sensors/Ping"); - ret.add("Example/08.Strings/CharacterAnalysis"); - ret.add("Example/08.Strings/StringAdditionOperator"); - ret.add("Example/08.Strings/StringAppendOperator"); - ret.add("Example/08.Strings/StringCaseChanges"); - ret.add("Example/08.Strings/StringCharacters"); - ret.add("Example/08.Strings/StringComparisonOperators"); - ret.add("Example/08.Strings/StringConstructors"); - ret.add("Example/08.Strings/StringIndexOf"); - ret.add("Example/08.Strings/StringLength"); - ret.add("Example/08.Strings/StringLengthTrim"); - ret.add("Example/08.Strings/StringReplace"); - ret.add("Example/08.Strings/StringStartsWithEndsWith"); - ret.add("Example/08.Strings/StringSubstring"); - ret.add("Example/08.Strings/StringToInt"); - ret.add("Example/10.StarterKit_BasicKit/p03_LoveOMeter"); - ret.add("Example/10.StarterKit_BasicKit/p04_ColorMixingLamp"); - ret.add("Example/10.StarterKit_BasicKit/p05_ServoMoodIndicator"); - ret.add("Example/10.StarterKit_BasicKit/p07_Keyboard"); - ret.add("Example/10.StarterKit_BasicKit/p12_KnockLock"); - ret.add("Example/10.StarterKit_BasicKit/p13_TouchSensorLamp"); - ret.add("Example/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo"); - ret.add("Example/11.ArduinoISP/ArduinoISP"); - ret.add("Example/Teensy/Tutorial3/HelloSerialMonitor"); - ret.add("Example/Teensy/Tutorial3/Pushbutton"); - ret.add("Example/Teensy/Tutorial3/PushbuttonPullup"); - ret.add("Example/Teensy/Tutorial3/PushbuttonRGBcolor"); - ret.add("Example/Teensy/Tutorial4/AnalogInput"); - ret.add("Example/Teensy/Tutorial4/TemperatureNumberOnly"); - ret.add("Example/Teensy/Tutorial4/TemperatureScaled"); - ret.add("Example/Teensy/Tutorial4/TemperatureScaledMulti"); - return ret; - } - - private static LinkedList examplesUsingJoyStick() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_Joystick/Basic"); - ret.add("Example/Teensy/USB_Joystick/Buttons"); - ret.add("Example/Teensy/USB_Joystick/Complete"); - return ret; - } - - private static LinkedList examplesUsingMouse() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_Joystick/Basic"); - ret.add("Example/Teensy/USB_Joystick/Buttons"); - ret.add("Example/Teensy/USB_Joystick/Complete"); - ret.add("Example/Teensy/USB_RawHID/Basic"); - return ret; - } - - private static LinkedList examplesUsingWire1() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_Joystick/Basic"); - ret.add("Example/Teensy/USB_Joystick/Buttons"); - ret.add("Example/Teensy/USB_Joystick/Complete"); - ret.add("Example/Teensy/USB_RawHID/Basic"); - ret.add("Library/Adafruit_BME280_Library/advancedsettings"); - ret.add("Library/AS3935MI/AS3935MI_LightningDetector_otherInterfaces"); - return ret; - } - - private static LinkedList examplesUsingMCUmo() { - LinkedList ret = new LinkedList<>(); - ret.add("Library/Adafruit_Circuit_Playground/CircuitPlaygroundFirmata_Express_CodeOrg"); - return ret; - } - - /* - * These examples that are known to fail - */ - private static LinkedList failingExamples() { - LinkedList ret = new LinkedList<>(); - /* - * Because you can not define a enum 2 times Sloeber can not add the enum in - * Slober.ino.cpp as a result the function declarations using these enums - * generate a error because the enum is not defined. The examples below fail due - * to this - */ - ret.add("Library/_2020Bot_Library/_2020Bot_Demo"); - // These examples are the processing part and are not a deal of sloeber - ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); - // manual action is needed for following examples - ret.add("Library/Accessories/CANCommander"); - ret.add("Library/Accessories_CANCommander"); - ret.add("Library/Accessories/Demo"); - ret.add("Library/Accessories/Full"); - ret.add("Library/Accessories/Group"); - ret.add("Library/Accessories/LightFading"); - ret.add("Library/Accessories/LMD18200"); - ret.add("Library/Accessories/Servos"); - ret.add("Library/Accessories/SignalFrench"); - ret.add("Library/Accessories/Signals4x3"); - ret.add("Library/Accessories/SimpleLed"); - ret.add("Library/Accessories/SimpleLedMulti"); - ret.add("Library/Accessories/Stepper"); - ret.add("Library/Accessory/Shield/OLED/example/Adafruit"); - ret.add("Library/Accessory/Shield/temp/humidity/oled"); - // at the time of testing there were case sensetivity issues - ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioRecording"); - ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioWavPlayer"); - ret.add("Library/AutoAnalogAudio/AudioRadioRelay"); - ret.add("Library/AutoAnalogAudio/WirelessMicrophone"); - ret.add("Library/AutoAnalogAudio/WirelessSpeaker"); - ret.add("Library/AutoAnalogAudio/WirelessTx_RPi"); - // needs to get the defines and includes right - ret.add("Library/Accessories/Locoduino.org/Programme4"); - ret.add("Library/Accessories/Locoduino.org/Programme5"); - // Should be build on a stm32 (nucleo as far as I get) - // but these bards require #927 (and probably more :-( - ret.add("Library/ADCTouchSensor/CapacitiveController"); - ret.add("Library/ADCTouchSensor/CapacitivePiano"); - // failed in SPI :-( - ret.add("Library/Adafruit_TinyFlash/TrinketPlayer"); - // not sure how this could work - ret.add("Library/Adafruit_VS1053_Library/feather_midi"); - // all kinds of incompatibility issues I guess - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8b_Use_Bluetooth_Signal_Strength_to_Control_Things"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8c_Change_Andee_Bluetooth_Device_Name"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8d_How_to_Read_and_Write_to_SD_Card"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8f_Using_Andee_IO_Pins_as_OUTPUT_Pins"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8g_Getting_Inputs_from_Andee_IO_Pins"); - ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9a_Get_Device_Bluetooth_MAC_Address_ANDROID_Only"); - ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9b_Filter_Devices_by_Bluetooth_MAC_Address_ANDROID_Only"); - // doc says not finished - ret.add("Library/ANT-Arduino/NativeAnt"); - // uses missing library MobileBLE - ret.add("Library/ArduinoBlue/differentialDriveCar"); - // defining struct/enum in ino file - ret.add("Library/ArduinoJson/JsonConfigFile"); - ret.add("Library/Arduboy2/RGBled"); - // error: no matching function for call to 'aREST_UI::addToBuffer(const char - ret.add("Library/aREST_UI/ESP8266"); - ret.add("Library/aREST_UI/WiFi_CC3000"); - ret.add("Library/aREST_UI/WildFire"); - // uses arduinoWIFI - ret.add("Library/Braccio/braccioOfUnoWiFi"); - // uses lib that does not has lib folder= include-.h - ret.add("Library/ArduinoCloud/SimpleCloudButtonYun"); - // usi!ng non exsisting methods - ret.add("Library/CAN-BUS_Shield/gpioRead"); - ret.add("Library/CAN-BUS_Shield/gpioWrite"); - // using defines inino file to generate functions (not supported in Sloeber) - ret.add("Library/Adafruit_VEML6070_Library/unittests"); - // uses a non existing header - ret.add("Library/AESLib/complex"); - // using wrong sdfat librarie - ret.add("Library/Arduino_OPL2_SimpleTone"); - ret.add("Library/Arduino_OPL2_Teensy_PlayDRO"); - ret.add("Library/Arduino_OPL2_Teensy_PlayIMF"); - // I don't recall why following examples didn't work - ret.add("Library/arduino_ess_ess_yun"); - ret.add("Library/arduino_ess_linkit_one_dweet"); - ret.add("Library/AD7193/AD7193_VoltageMeasurePsuedoDifferential_Example"); - ret.add("Library/bunny_cuberotate/cuberotate"); - ret.add("Library/XPT2046_Touchscreen/ILI9341Test"); - ret.add("Library/Adafruit_AHRS/ahrs_mahony"); - ret.add("Library/Adafruit_BLEFirmata/StandardFirmata"); - ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); - ret.add("Library/Adafruit_GPS_Library/due_shield_sdlog"); - ret.add("Library/Adafruit_Graphic_VFD_Display_Library/GraphicVFDtest"); - ret.add("Library/Adafruit_GPS_Library/locus_erase"); - ret.add("Library/Adafruit_GPS_Library/shield_sdlog"); - ret.add("Library/Adafruit_HX8357_Library/breakouttouchpaint"); - ret.add("Library/Adafruit_ILI9341/breakouttouchpaint"); - ret.add("Library/Adafruit_ILI9341/onoffbutton_breakout"); - ret.add("Library/Adafruit_GPS_Library/echo"); - ret.add("Library/Adafruit_LED_Backpack_Library/wavface"); - ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_i2c"); - ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_spi"); - ret.add("Library/Adafruit_ST7735_Library/soft_spitftbitmap"); - ret.add("Library/Adafruit_TCS34725/colorview/processing/colorview"); - ret.add("Library/Adafruit_TinyRGBLCDShield/TinyHelloWorld"); - ret.add("Library/Akafugu_TWILiquidCrystal_Library/change_address"); - ret.add("Library/Akafugu_WireRtc_Library/alarm"); - ret.add("Library/ALA/RgbStripButton"); - ret.add("Library/APA102/GameOfLife"); - ret.add("Library/arduino-menusystem/led_matrix"); - ret.add("Library/arduino-menusystem/led_matrix_animated"); - ret.add("Library/Arduino_Low_Power/TianStandby"); - ret.add("Library/aREST/BLE"); - ret.add("Library/aREST/ESP32"); - ret.add("Library/aREST/ESP32_cloud"); - ret.add("Library/ArduinoHttpClient/DweetGet"); - ret.add("Library/ArduinoMenu_library/adafruitGfx/lcdMono/lcdMono"); - ret.add("Library/ArduinoMenu_library/adafruitGfx/tft/tft"); - ret.add("Library/ArdVoice/Sample2-Complex"); - ret.add("Library/Aspen_SIM800/Access_HTTP"); - ret.add("Library/Awesome/advanced/how_fast"); - ret.add("Library/Awesome/advanced/lie_detector"); - ret.add("Library/AzureIoTUtility/simplesample_http"); - ret.add("Library/BLEPeripheral/ir_bridge"); - ret.add("Library/BLEPeripheral/temp_sensor"); - ret.add("Library/Brasilino/Basicos/controleGradual"); - ret.add("Library/ClosedCube_HDC1010/hdc1010demo"); - ret.add("Library/Chrono/Resolutions"); - ret.add("Library/Chrono/StopResume"); - ret.add("Library/ConfigurableFirmata/ConfigurableFirmataWiFi"); - ret.add("Library/ControleForno/configuravel"); - ret.add("Library/CopyThreads/c"); - ret.add("Library/ArduinoCloud/SimpleCloudButtoBrzo_I2C"); - ret.add("Library/CopyThreads/FromReadme"); - ret.add("Library/DallasTemperature/Multibus_simple"); - ret.add("Library/DecodeIR/InfraredDecode"); - ret.add("Library/AutoAnalogAudio/SimpleSine"); - ret.add("Library/DimSwitch/DimSwitchTester-ESP-MQTT"); - ret.add("Library/DS3231/echo_time"); - ret.add("Library/Easy_NeoPixels"); - ret.add("Library/DallasTemperature/AlarmHandler"); - ret.add("Library/AmazonDRS/amazonDashNfc"); - ret.add("Library/Andee/Lesson_02_Buttons/Lesson_2h_Using_Buttons_to_Control_Servos"); - ret.add("Library/Andee/Project_Christmas_Lights_and_Annoying_Music"); - ret.add("Library/Andee/Project_Rubber_Band_Launcher"); - ret.add("Library/Andee/Project_Time_Automated_Data_Logger"); - ret.add("Library/ANT-Arduino_library/NativeAnt"); - ret.add("Library/arduino-fsm/timed_switchoff"); - ret.add("Library/BME280/BME_280_BRZO_I2C_Test"); - ret.add("Library/Adafruit_seesaw_Library/DAP"); - // uses unknown NO_ERROR - ret.add("Library/ClosedCube_TCA9546A/tca9546a_sht31d"); - // uses dht.h from dht_sensor_lib - ret.add("Library/CMMC_MQTT_Connector/basic_dht"); - ret.add("Library/ArduinoLearningKitStarter/boardTest"); - // uses altsoftserial and then Serial2???? - ret.add("Library/CMMC_NB-IoT/example1"); - // some bu!g I guess - ret.add("Library/CopyThreads/ExamplesFromReadme"); - ret.add("Library/CRC_Simula_Arduino_IDE_Library/Simula_BehaviorTree"); - // empty sketch?? - ret.add("Library/DFW/ProvisionController"); - // error: 'mapSensor' was not declared in this scope - ret.add("Library/AD_Sensors/ConstrainAnalogSensor"); - // error: 'sensor' was not declared in this scope - ret.add("Library/AD_Sensors/MapAndConstrainAnalogSensor"); - // ess-yun.ino:17:12: error: no matching function for call to - // 'HttpClient::HttpClient()' - ret.add("Library/arduino-ess/ess-yun"); - // I have no linket board in test setup - ret.add("Library/arduino-ess/linkit-one-dweet"); - //cores\arduino/WString.h:38:74: error: statement-expressions - ret.add("Library/ArduinoTrace/TraceFromGlobalScope"); - // no matching function for call to 'aREST::handle(EthernetClient&)' - ret.add("Library/aREST/Ethernet"); - // AsciiMassage_servos.ino:75:37: error: no matching function for call to - // 'AsciiMassagePacker::streamEmpty(const char [6])' - ret.add("Library/AsciiMassage/AsciiMassage_servos"); - // \BH1750FVI_Simple.ino:33:10: error: 'class Serial_' has no member named - // 'printf' - ret.add("Library/BH1750FVI/BH1750FVI_Simple"); - // * This example not complete at all, TODO. - ret.add("Library/Blinker/Blinker_AUTO/AUTO_MQTT"); - // 3: error: 'StaticJsonBuffer' was not declared in this scope - ret.add("Library/Boodskap_Message_library/SimpleMessageUsage"); - return ret; - } - - /** - * Give a list of boards pick the board that is best to test this code Boards in - * the beginning of the array are prefered (first found ok algorithm) - * - * returns null if this code should not be tested return null if myBoards is - * empty returns the best known boarddescriptor to run this example - */ - public static MCUBoard pickBestBoard(Examples example, MCUBoard myBoards[]) { - String libName = example.getLibName(); - String fqn = example.getFQN(); - if (myBoards.length == 0) { - return null; - } - - if (example.getRequiredBoardAttributes().worksOutOfTheBox) { - - // if example states which board it wants use that board - if (example.getRequiredBoardAttributes().boardName != null) { - String wantedBoardName = example.getRequiredBoardAttributes().boardName; - for (MCUBoard curBoard : myBoards) { - if (curBoard.getID().equals(wantedBoardName)) { - return curBoard; - } - } - } else { - // examples using DHT_sensor_library libraries are not found as the include is - // DHT.h - if (!libName.equals("DHT_sensor_library") && fqn.contains("DHT")) { - return null; - } - // if the boardname is in the libname or ino name pick this one - for (MCUBoard curBoard : myBoards) { - String curBoardName = curBoard.getSlangName().toLowerCase(); - if (libName.toLowerCase().contains(curBoardName) || fqn.toLowerCase().contains(curBoardName)) { - if (curBoard.isExampleSupported(example)) { - return curBoard; - } - } - } - // If the architecture is in the libname or boardname pick this one - for (MCUBoard curBoard : myBoards) { - String curArchitectureName = curBoard.getBoardDescriptor().getArchitecture().toLowerCase(); - if (libName.toLowerCase().contains(curArchitectureName) - || fqn.toLowerCase().contains(curArchitectureName)) { - if (curBoard.isExampleSupported(example)) { - return curBoard; - } - } - } - // if the example name contains teensy try teensy board - if (example.getFQN().toLowerCase().contains("teensy")) { - for (MCUBoard curBoard : myBoards) { - if (Teensy.class.isInstance(curBoard)) { - return curBoard; - } - } - } - // if the example name contains ESP32 try ESP32 board - if (example.getFQN().toLowerCase().contains("esp32")) { - for (MCUBoard curBoard : myBoards) { - if (ESP32.class.isInstance(curBoard)) { - return curBoard; - } - } - } - // if the example name contains ESP try ESP8266 board -// if (example.getFQN().toLowerCase().contains("esp")) { -// for (MCUBoard curBoard : myBoards) { -// if (ESP8266.class.isInstance(curBoard)) { -// return curBoard; -// } -// } -// } -//causes issues with response - - // Out of guesses based on the name. Take the first ok one - for (MCUBoard curBoard : myBoards) { - if (curBoard.isExampleSupported(example)) { - return curBoard; - } - } - } - } - System.out.println("No board found for " + Integer.toString(++noBoardFoundCount) + " " + example.getFQN()); - return null; - } - - private static String getRequiredBoardID(String fqn) { - switch (fqn) { - case "Library/Accessory_Shield/OLED_example_Adafruit": - case "Library/Accessory_Shield/temp_humidity_oled": - return "uno"; - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_NeoPixel": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Read": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Record": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Send": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Testpattern": - case "Library/Adafruit_Zero_FFT_Library/CircuitPlayground": - return "adafruit_circuitplayground_m0"; - case "Library/Adafruit_MiniMLX90614/templight": - return "gemma"; - case "Library/ArduinoThread/SensorThread": - return "due"; - case "Library/AudioFrequencyMeter/SimpleAudioFrequencyMeter": - case "Library/Adafruit_NeoPXL8/strandtest": - return "zero"; - case "Library/BLEPeripheral/iBeacon": - return "feather52"; - default: - return null; - } - - } -} diff --git a/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java b/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java index 00e76c514..ea62f3ed8 100644 --- a/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java @@ -28,7 +28,7 @@ public class NightlyBoardPatronTest { private static int myBuildCounter = 0; - private Examples myExample; + private Example myExample; private MCUBoard myBoardID; private static int mySkipAtStart = 0; private static int myTotalFails = 0; @@ -36,7 +36,7 @@ public class NightlyBoardPatronTest { private static CompileDescription myCompileOptions; private static boolean deleteProjects =true; //delete the projects after trying to build them - public NightlyBoardPatronTest(String name, MCUBoard boardID, Examples example) { + public NightlyBoardPatronTest(String name, MCUBoard boardID, Example example) { myBoardID = boardID; myExample = example; } @@ -62,7 +62,7 @@ public static Collection examples() { IPath examplePath = curexample.getValue(); //for patron Keith Willis. Thanks Keith if (fqn.contains("RTCZero")) { - Examples example = new Examples(fqn, examplePath); + Example example = new Example(fqn, examplePath); Object[] theData = new Object[] {Shared.getCounterName( example.getLibName() + ":" + fqn + ":" + zeroBoard.getID()), zeroBoard, example }; diff --git a/io.sloeber.tests/src/io/sloeber/core/Shared.java b/io.sloeber.tests/src/io/sloeber/core/Shared.java index 8a3bface4..4e19d46d6 100644 --- a/io.sloeber.tests/src/io/sloeber/core/Shared.java +++ b/io.sloeber.tests/src/io/sloeber/core/Shared.java @@ -263,7 +263,7 @@ public static String getCounterName(String name) { } @SuppressWarnings("unused") - public static String getProjectName(CodeDescription codeDescriptor, Examples example, MCUBoard board) { + public static String getProjectName(CodeDescription codeDescriptor, Example example, MCUBoard board) { return String.format("%05d_%s_%s", Integer.valueOf(myTestCounter++), codeDescriptor.getExampleName(), board.getBoardDescriptor().getBoardID()); } diff --git a/io.sloeber.tests/src/io/sloeber/providers/Arduino.java b/io.sloeber.tests/src/io/sloeber/providers/Arduino.java index 506849dd5..b3c4f24ac 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Arduino.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Arduino.java @@ -7,185 +7,202 @@ import java.util.Map; import java.util.TreeMap; +import io.sloeber.core.api.BoardDescription; import io.sloeber.core.api.BoardsManager; +import io.sloeber.core.api.Json.ArduinoPackage; +import io.sloeber.core.api.Json.ArduinoPlatform; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; @SuppressWarnings("nls") public class Arduino extends MCUBoard { - private static final String providerArduino = "arduino"; - private static final String providerIntel = "Intel"; + private static final String providerArduino = "arduino"; + private static final String providerIntel = "Intel"; private static final String AVRArchitectureName = "avr"; private static final String SAMDArchitectureName = "samd"; private static final String SAMArchitectureName = "sam"; private static final String NFRArchitectureName = "nrf52"; private static final String intelCurieArchitectureName = "arc32"; - private static final String jsonFileName ="package_index.json"; - - public static final String circuitplay32ID="circuitplay32u4cat"; - public static final String unoID="uno"; - public static final String ethernetID="ethernet"; - - public static MCUBoard gemma() { - MCUBoard ret = new Arduino(providerArduino, AVRArchitectureName, "gemma"); - ret.mySlangName="gemma"; - return ret; - } - - public static MCUBoard MegaADK() { - return new Arduino(providerArduino, AVRArchitectureName, "megaADK"); - } - - public static MCUBoard esplora() { - return new Arduino(providerArduino, AVRArchitectureName, "esplora"); - } - - public static MCUBoard adafruitnCirquitPlayground() { - return new Arduino(providerArduino, AVRArchitectureName, circuitplay32ID); - } - public static MCUBoard cirquitPlaygroundExpress() { + private static final String jsonFileName = "package_index.json"; + + public static final String circuitplay32ID = "circuitplay32u4cat"; + public static final String unoID = "uno"; + public static final String ethernetID = "ethernet"; + + public static MCUBoard gemma() { + MCUBoard ret = new Arduino(providerArduino, AVRArchitectureName, "gemma"); + ret.mySlangName = "gemma"; + return ret; + } + + public static MCUBoard MegaADK() { + return new Arduino(providerArduino, AVRArchitectureName, "megaADK"); + } + + public static MCUBoard esplora() { + return new Arduino(providerArduino, AVRArchitectureName, "esplora"); + } + + public static MCUBoard adafruitnCirquitPlayground() { + return new Arduino(providerArduino, AVRArchitectureName, circuitplay32ID); + } + + public static MCUBoard cirquitPlaygroundExpress() { return new Arduino(providerArduino, SAMDArchitectureName, "adafruit_circuitplayground_m0"); - } - - public static MCUBoard getAvrBoard(String boardID) { - return new Arduino(providerArduino, AVRArchitectureName, boardID); - } - - public static MCUBoard fried2016() { - return new Arduino(providerArduino, AVRArchitectureName, "LilyPadUSB"); - } - - public static MCUBoard fried2016(String uploadPort) { - MCUBoard fried = fried2016(); - fried.myBoardDescriptor.setUploadPort(uploadPort); - return fried; - } - - public static MCUBoard getMega2560Board() { - MCUBoard mega = new Arduino(providerArduino, AVRArchitectureName, "mega"); - Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - options.put("cpu", "atmega2560"); - mega.myBoardDescriptor.setOptions(options); - return mega; - } - - public static MCUBoard getMega2560Board(String uploadPort) { - MCUBoard mega = getMega2560Board(); - mega.myBoardDescriptor.setUploadPort(uploadPort); - return mega; - } - - public static MCUBoard leonardo() { - MCUBoard leonardo = new Arduino(providerArduino, AVRArchitectureName, "leonardo"); - return leonardo; - } - - public static MCUBoard leonardo(String uploadPort) { - MCUBoard leonardo = leonardo(); - leonardo.myBoardDescriptor.setUploadPort(uploadPort); - return leonardo; - } - - public static MCUBoard yun() { - MCUBoard yun = new Arduino(providerArduino, AVRArchitectureName, "yun"); - return yun; - } - - public static MCUBoard yun(String uploadPort) { - MCUBoard yun = yun(); - yun.myBoardDescriptor.setUploadPort(uploadPort); - return yun; - } - - public static MCUBoard zeroProgrammingPort() { + } + + public static MCUBoard getAvrBoard(String boardID) { + return new Arduino(providerArduino, AVRArchitectureName, boardID); + } + + public static MCUBoard fried2016() { + return new Arduino(providerArduino, AVRArchitectureName, "LilyPadUSB"); + } + + public static MCUBoard fried2016(String uploadPort) { + MCUBoard fried = fried2016(); + fried.myBoardDescriptor.setUploadPort(uploadPort); + return fried; + } + + public static MCUBoard getMega2560Board() { + MCUBoard mega = new Arduino(providerArduino, AVRArchitectureName, "mega"); + Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + options.put("cpu", "atmega2560"); + mega.myBoardDescriptor.setOptions(options); + return mega; + } + + public static MCUBoard getMega2560Board(String uploadPort) { + MCUBoard mega = getMega2560Board(); + mega.myBoardDescriptor.setUploadPort(uploadPort); + return mega; + } + + public static MCUBoard leonardo() { + MCUBoard leonardo = new Arduino(providerArduino, AVRArchitectureName, "leonardo"); + return leonardo; + } + + public static MCUBoard leonardo(String uploadPort) { + MCUBoard leonardo = leonardo(); + leonardo.myBoardDescriptor.setUploadPort(uploadPort); + return leonardo; + } + + public static MCUBoard yun() { + MCUBoard yun = new Arduino(providerArduino, AVRArchitectureName, "yun"); + return yun; + } + + public static MCUBoard yun(String uploadPort) { + MCUBoard yun = yun(); + yun.myBoardDescriptor.setUploadPort(uploadPort); + return yun; + } + + public static MCUBoard zeroProgrammingPort() { MCUBoard zero = new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_edbg"); - zero.mySlangName="zero"; - return zero; - } + zero.mySlangName = "zero"; + return zero; + } - public static MCUBoard zeroProgrammingPort(String uploadPort) { - MCUBoard zero = zeroProgrammingPort(); - zero.myBoardDescriptor.setUploadPort(uploadPort); - return zero; - } + public static MCUBoard zeroProgrammingPort(String uploadPort) { + MCUBoard zero = zeroProgrammingPort(); + zero.myBoardDescriptor.setUploadPort(uploadPort); + return zero; + } - public static MCUBoard due() { + public static MCUBoard due() { return new Arduino(providerArduino, SAMArchitectureName, "arduino_due_x"); - } + } - public static MCUBoard due(String uploadPort) { - MCUBoard board = due(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } + public static MCUBoard due(String uploadPort) { + MCUBoard board = due(); + board.myBoardDescriptor.setUploadPort(uploadPort); + return board; + } - public static MCUBoard dueprogramming() { + public static MCUBoard dueprogramming() { return new Arduino(providerArduino, SAMArchitectureName, "arduino_due_x_dbg"); - } + } - public static MCUBoard dueprogramming(String uploadPort) { - MCUBoard board = dueprogramming(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } + public static MCUBoard dueprogramming(String uploadPort) { + MCUBoard board = dueprogramming(); + board.myBoardDescriptor.setUploadPort(uploadPort); + return board; + } - public static MCUBoard mkrfox1200() { + public static MCUBoard mkrfox1200() { return new Arduino(providerArduino, SAMDArchitectureName, "mkrfox1200"); - } + } - public static MCUBoard primo() { + public static MCUBoard primo() { return new Arduino(providerArduino, NFRArchitectureName, "primo"); - } - - public static MCUBoard uno() { - MCUBoard uno = new Arduino(providerArduino, AVRArchitectureName, unoID); - uno.mySlangName="uno"; - return uno; - } - public static MCUBoard ethernet() { - MCUBoard uno = new Arduino(providerArduino, AVRArchitectureName, ethernetID); - return uno; - } - - public static MCUBoard uno(String uploadPort) { - MCUBoard uno = uno(); - uno.myBoardDescriptor.setUploadPort(uploadPort); - return uno; - } - - public static MCUBoard arduino_101() { - MCUBoard arduino_101 = new Arduino(providerIntel, intelCurieArchitectureName, "arduino_101"); - arduino_101.mySlangName="101"; - return arduino_101; - } + } + + public static MCUBoard uno() { + MCUBoard uno = new Arduino(providerArduino, AVRArchitectureName, unoID); + uno.mySlangName = "uno"; + return uno; + } - public static MCUBoard arduino_101(String uploadPort) { - MCUBoard arduino_101 = arduino_101(); - arduino_101.myBoardDescriptor.setUploadPort(uploadPort); - return arduino_101; - } + public static MCUBoard ethernet() { + MCUBoard uno = new Arduino(providerArduino, AVRArchitectureName, ethernetID); + return uno; + } + + public static MCUBoard uno(String uploadPort) { + MCUBoard uno = uno(); + uno.myBoardDescriptor.setUploadPort(uploadPort); + return uno; + } + public static MCUBoard arduino_101() { + MCUBoard arduino_101 = new Arduino(providerIntel, intelCurieArchitectureName, "arduino_101"); + arduino_101.mySlangName = "101"; + return arduino_101; + } - private Arduino(String providerName, String architectureName, String boardName) { + public static MCUBoard arduino_101(String uploadPort) { + MCUBoard arduino_101 = arduino_101(); + arduino_101.myBoardDescriptor.setUploadPort(uploadPort); + return arduino_101; + } + + private Arduino(String providerName, String architectureName, String boardID) { this.myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, providerName, architectureName, - boardName, null); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } - this.myBoardDescriptor.setUploadPort("none"); - - myAttributes.serial = !doesNotSupportSerialList().contains(boardName); - myAttributes.serial1 = supportSerial1List().contains(boardName); - myAttributes.keyboard = supportKeyboardList().contains(boardName); - myAttributes.wire1 = supportWire1List().contains(boardName); - myAttributes.buildInLed = !doesNotSupportbuildInLed().contains(boardName); - - } - - static List supportWire1List() { - List ret = new LinkedList<>(); - ret.add("zero"); - return ret; - } + boardID, null); + if (this.myBoardDescriptor == null) { + fail(boardID + " Board not found"); + } + this.myBoardDescriptor.setUploadPort("none"); + + myAttributes.serial = !doesNotSupportSerialList().contains(boardID); + myAttributes.serial1 = supportSerial1List().contains(boardID); + myAttributes.keyboard = supportKeyboardList().contains(boardID); + myAttributes.wire1 = supportWire1List().contains(boardID); + myAttributes.buildInLed = !doesNotSupportbuildInLed().contains(boardID); + + } + + private Arduino(BoardDescription boardDescriptor) { + myBoardDescriptor = boardDescriptor; + myBoardDescriptor.setUploadPort("none"); + String boardID = myBoardDescriptor.getBoardID(); + myAttributes.serial = !doesNotSupportSerialList().contains(boardID); + myAttributes.serial1 = supportSerial1List().contains(boardID); + myAttributes.keyboard = supportKeyboardList().contains(boardID); + myAttributes.wire1 = supportWire1List().contains(boardID); + myAttributes.buildInLed = !doesNotSupportbuildInLed().contains(boardID); + + } + + static List supportWire1List() { + List ret = new LinkedList<>(); + ret.add("zero"); + return ret; + } static List doesNotSupportbuildInLed() { List ret = new LinkedList<>(); @@ -194,54 +211,55 @@ static List doesNotSupportbuildInLed() { return ret; } - static List supportSerial1List() { - List ret = new LinkedList<>(); - ret.add("circuitplay32u4cat"); - ret.add("LilyPadUSB"); - ret.add("Micro"); - ret.add("yunMini"); - ret.add("robotControl"); - ret.add("Esplora"); - ret.add("mega"); - ret.add("chiwawa"); - ret.add("yun"); - ret.add("one"); - ret.add("leonardo"); - ret.add("robotMotor"); - ret.add("leonardoEth"); - ret.add("megaADK"); - - return ret; - } - - static List doesNotSupportSerialList() { - List ret = new LinkedList<>(); - ret.add("gemma"); - - return ret; - } - - static List supportKeyboardList() { - List ret = new LinkedList<>(); - ret.add("circuitplay32u4cat"); - ret.add("LilyPadUSB"); - ret.add("Micro"); - ret.add("yunMini"); - ret.add("robotControl"); - ret.add("Esplora"); - ret.add("chiwawa"); - ret.add("yun"); - // mySupportKeyboardList.add("one"); - // mySupportKeyboardList.add("Leonardo"); - // mySupportKeyboardList.add("robotMotor"); - // mySupportKeyboardList.add("LeonardoEth"); - // mySupportKeyboardList.add("MegaADK"); - - return ret; - } - public static void installLatestAVRBoards() { - BoardsManager.installLatestPlatform(jsonFileName,providerArduino, AVRArchitectureName); - } + static List supportSerial1List() { + List ret = new LinkedList<>(); + ret.add("circuitplay32u4cat"); + ret.add("LilyPadUSB"); + ret.add("Micro"); + ret.add("yunMini"); + ret.add("robotControl"); + ret.add("Esplora"); + ret.add("mega"); + ret.add("chiwawa"); + ret.add("yun"); + ret.add("one"); + ret.add("leonardo"); + ret.add("robotMotor"); + ret.add("leonardoEth"); + ret.add("megaADK"); + + return ret; + } + + static List doesNotSupportSerialList() { + List ret = new LinkedList<>(); + ret.add("gemma"); + + return ret; + } + + static List supportKeyboardList() { + List ret = new LinkedList<>(); + ret.add("circuitplay32u4cat"); + ret.add("LilyPadUSB"); + ret.add("Micro"); + ret.add("yunMini"); + ret.add("robotControl"); + ret.add("Esplora"); + ret.add("chiwawa"); + ret.add("yun"); + // mySupportKeyboardList.add("one"); + // mySupportKeyboardList.add("Leonardo"); + // mySupportKeyboardList.add("robotMotor"); + // mySupportKeyboardList.add("LeonardoEth"); + // mySupportKeyboardList.add("MegaADK"); + + return ret; + } + + public static void installLatestAVRBoards() { + BoardsManager.installLatestPlatform(jsonFileName, providerArduino, AVRArchitectureName); + } public static void installLatestSamDBoards() { BoardsManager.installLatestPlatform(jsonFileName, providerArduino, SAMDArchitectureName); @@ -255,54 +273,35 @@ public static void installLatestIntellCurieBoards() { BoardsManager.installLatestPlatform(jsonFileName, providerIntel, intelCurieArchitectureName); } - public static MCUBoard[] getAllBoards() { - // TODO - // hardcode this stuff now because I want to release 4.3.1 - //shoulds be something like - //return PackageManager.getAllBoardDescriptors(getJsonFileName(),getPackageName(),getPlatformName() , options); - MCUBoard[] boards = { Arduino.uno(), - Arduino.leonardo(), - Arduino.esplora(), - Arduino.yun(), - Arduino.getAvrBoard("diecimila"), - Arduino.getMega2560Board(), - Arduino.MegaADK(), - Arduino.getAvrBoard("leonardoeth"), - Arduino.getAvrBoard("micro"), - Arduino.getAvrBoard("mini"), - Arduino.getAvrBoard("ethernet"), - Arduino.getAvrBoard("fio"), - Arduino.getAvrBoard("bt"), - Arduino.getAvrBoard("LilyPadUSB"), - Arduino.getAvrBoard("lilypad"), - Arduino.getAvrBoard("pro"), - Arduino.getAvrBoard("atmegang"), - Arduino.getAvrBoard("robotControl"), - Arduino.getAvrBoard("robotMotor"), - Arduino.getAvrBoard("gemma"), - Arduino.adafruitnCirquitPlayground(), - Arduino.getAvrBoard("yunmini"), - Arduino.getAvrBoard("chiwawa"), - Arduino.getAvrBoard("one"), - Arduino.getAvrBoard("unowifi"), }; - return boards; - - } - public static MCUBoard zeroNatviePort() { - MCUBoard zero = new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_native"); - zero.mySlangName="zero Native"; - zero.mySerialPort="SerialUSB"; - return zero; - } + public static List getAllBoards() { + List ret = new LinkedList<>(); + Map options = null; + ArduinoPackage arduinoPkg = BoardsManager.getPackageByProvider(providerArduino); + for (ArduinoPlatform curPlatform : arduinoPkg.getPlatforms()) { + ArduinoPlatformVersion curPlatformVersion = curPlatform.getNewestInstalled(); + if (curPlatformVersion != null) { + List boardDescriptions = BoardDescription + .makeBoardDescriptors(curPlatformVersion.getBoardsFile(), options); + for (BoardDescription curBoardDesc : boardDescriptions) { + ret.add(new Arduino(curBoardDesc)); + } + } + } + return ret; + } - public static MCUBoard zeroNatviePort(String uploadPort) { - MCUBoard zero = zeroNatviePort(); - zero.myBoardDescriptor.setUploadPort(uploadPort); - return zero; - } + public static MCUBoard zeroNatviePort() { + MCUBoard zero = new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_native"); + zero.mySlangName = "zero Native"; + zero.mySerialPort = "SerialUSB"; + return zero; + } + + public static MCUBoard zeroNatviePort(String uploadPort) { + MCUBoard zero = zeroNatviePort(); + zero.myBoardDescriptor.setUploadPort(uploadPort); + return zero; + } - - - } \ No newline at end of file diff --git a/io.sloeber.tests/src/io/sloeber/providers/Jantje.java b/io.sloeber.tests/src/io/sloeber/providers/Jantje.java index b72df9739..5bcd93846 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Jantje.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Jantje.java @@ -6,7 +6,7 @@ import java.util.Map; import java.util.TreeMap; -import io.sloeber.core.Examples; +import io.sloeber.core.Example; import io.sloeber.core.api.BoardsManager; @SuppressWarnings("nls") @@ -36,7 +36,7 @@ public Jantje(String boardName) { myAttributes.keyboard=Arduino.supportKeyboardList().contains(boardName); } @Override - public boolean isExampleSupported(Examples example) { + public boolean isExampleSupported(Example example) { LinkedList notSupportedExamples = new LinkedList<>(); notSupportedExamples.add("Example/09.USB/Keyboard/KeyboardLogout"); notSupportedExamples.add("Example/09.USB/Keyboard/KeyboardMessage"); diff --git a/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java b/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java index 6904088e2..7fd955fdd 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java +++ b/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java @@ -4,7 +4,7 @@ import java.util.TreeMap; import io.sloeber.core.BoardAttributes; -import io.sloeber.core.Examples; +import io.sloeber.core.Example; import io.sloeber.core.api.BoardDescription; @SuppressWarnings("nls") @@ -21,7 +21,7 @@ public BoardDescription getBoardDescriptor() { } - public boolean isExampleSupported(Examples example) { + public boolean isExampleSupported(Example example) { if (myBoardDescriptor == null) { return false; } @@ -70,7 +70,7 @@ public String getSlangName() { } @SuppressWarnings({ "static-method" }) - public Map getBoardOptions(Examples example) { + public Map getBoardOptions(Example example) { Map ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); return ret; } diff --git a/io.sloeber.tests/src/io/sloeber/providers/Teensy.java b/io.sloeber.tests/src/io/sloeber/providers/Teensy.java index e84f83352..3187d34ca 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Teensy.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Teensy.java @@ -7,7 +7,7 @@ import java.util.TreeMap; import io.sloeber.core.BoardAttributes; -import io.sloeber.core.Examples; +import io.sloeber.core.Example; import io.sloeber.core.MySystem; import io.sloeber.core.api.BoardsManager; @@ -113,7 +113,7 @@ private Teensy(String boardName) { * io.sloeber.core.boards.MCUBoard#getBoardOptions(io.sloeber.core.Examples) */ @Override - public Map getBoardOptions(Examples example) { + public Map getBoardOptions(Example example) { Map ret = super.getBoardOptions(example); switch (myBoardDescriptor.getBoardID()) { case Teensy3_5_ID: