Search in sources :

Example 1 with MCUBoard

use of io.sloeber.providers.MCUBoard in project arduino-eclipse-plugin by Sloeber.

the class CreateAndCompileLibraryExamplesTest method examples.

@SuppressWarnings("rawtypes")
@Parameters(name = "{index}: {0}")
public static Collection examples() {
    WaitForInstallerToFinish();
    Preferences.setUseArduinoToolSelection(true);
    MCUBoard[] myBoards = { Arduino.leonardo(), Arduino.uno(), Arduino.esplora(), Adafruit.feather(), Arduino.adafruitnCirquitPlayground(), ESP8266.nodeMCU(), ESP8266.wemosD1(), ESP8266.ESPressoLite(), Teensy.Teensy3_6(), Arduino.zero(), Arduino.cirquitPlaygroundExpress(), Arduino.gemma(), Adafruit.trinket8MH(), Arduino.yun() };
    LinkedList<Object[]> examples = new LinkedList<>();
    TreeMap<String, IPath> exampleFolders = LibraryManager.getAllExamples(null);
    for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
        String fqn = curexample.getKey().trim();
        IPath examplePath = curexample.getValue();
        Examples example = new Examples(fqn, null, examplePath);
        // with the current amount of examples only do one
        MCUBoard curBoard = Examples.pickBestBoard(example, myBoards);
        if (curBoard != null) {
            Object[] theData = new Object[] { example.getLibName() + ":" + fqn + ":" + curBoard.getName(), curBoard, example };
            examples.add(theData);
        }
    }
    return examples;
}
Also used : IPath(org.eclipse.core.runtime.IPath) MCUBoard(io.sloeber.providers.MCUBoard) Map(java.util.Map) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with MCUBoard

use of io.sloeber.providers.MCUBoard in project arduino-eclipse-plugin by Sloeber.

the class CompileAndUpload method examples.

@SuppressWarnings("rawtypes")
@Parameters(name = "{index}: {0}")
public static Collection examples() {
    WaitForInstallerToFinish();
    try {
        File file = ConfigurationPreferences.getInstallationPath().append("test.properties").toFile();
        if (!file.exists()) {
            file.createNewFile();
        }
        Properties properties = new Properties();
        try (FileInputStream fileInput = new FileInputStream(file)) {
            properties.load(fileInput);
            fileInput.close();
        }
        String key = "Last Used Blink Interval";
        interval = properties.getProperty(key);
        if ("100".equals(interval)) {
            interval = "1500";
        } else {
            interval = "100";
        }
        properties.put(key, interval);
        try (FileOutputStream fileOutput = new FileOutputStream(file)) {
            properties.store(fileOutput, "This is a file with values for unit testing");
            fileOutput.close();
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    MCUBoard[] boards = MySystem.getUploadBoards();
    // , new NodeMCUBoard()
    LinkedList<Object[]> examples = new LinkedList<>();
    for (MCUBoard curBoard : boards) {
        examples.add(new Object[] { curBoard.getName(), curBoard });
    }
    return examples;
}
Also used : FileOutputStream(java.io.FileOutputStream) MCUBoard(io.sloeber.providers.MCUBoard) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) Parameters(org.junit.runners.Parameterized.Parameters)

Example 3 with MCUBoard

use of io.sloeber.providers.MCUBoard in project arduino-eclipse-plugin by Sloeber.

the class CreateAndCompileExamplesTest method examples.

@SuppressWarnings("rawtypes")
@Parameters(name = "{index}: {0}")
public static Collection examples() {
    WaitForInstallerToFinish();
    MCUBoard[] myBoards = { Arduino.leonardo(), Arduino.uno(), Arduino.esplora(), Adafruit.feather(), Arduino.adafruitnCirquitPlayground(), ESP8266.nodeMCU(), Arduino.primo(), Arduino.getMega2560Board(), Arduino.gemma(), Arduino.zero(), Arduino.mkrfox1200(), Arduino.due() };
    LinkedList<Object[]> examples = new LinkedList<>();
    TreeMap<String, IPath> exampleFolders = LibraryManager.getAllLibraryExamples();
    for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
        ArrayList<IPath> paths = new ArrayList<>();
        paths.add(new Path(curexample.getValue().toString()));
        CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
        String fqn = curexample.getKey();
        String libName = "";
        if (examples.size() == 82) {
            // use this for debugging based on the
            // project number
            // use this to put breakpoint
            int a = 0;
            a = a + 1;
        }
        try {
            libName = fqn.split(" ")[0].trim();
        } catch (Exception e) {
        // ignore error
        }
        Examples example = new Examples(fqn, libName, curexample.getValue());
        // with the current amount of examples only do one
        BoardDescriptor curBoard = Examples.pickBestBoard(example, myBoards).getBoardDescriptor();
        if (curBoard != null) {
            Object[] theData = new Object[] { fqn.trim(), curBoard, codeDescriptor };
            examples.add(theData);
        }
    }
    return examples;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) CodeDescriptor(io.sloeber.core.api.CodeDescriptor) LinkedList(java.util.LinkedList) CoreException(org.eclipse.core.runtime.CoreException) MCUBoard(io.sloeber.providers.MCUBoard) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) Map(java.util.Map) TreeMap(java.util.TreeMap) Parameters(org.junit.runners.Parameterized.Parameters)

Example 4 with MCUBoard

use of io.sloeber.providers.MCUBoard in project arduino-eclipse-plugin by Sloeber.

the class Examples method pickBestBoard.

/**
 * 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;
    }
    /*
		 * This example does not build out of the box
		 */
    if (example.getRequiredBoardAttributes().worksOutOfTheBox) {
        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 archtecture 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;
            }
        }
    }
    // 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;
}
Also used : MCUBoard(io.sloeber.providers.MCUBoard)

Aggregations

MCUBoard (io.sloeber.providers.MCUBoard)4 LinkedList (java.util.LinkedList)3 Parameters (org.junit.runners.Parameterized.Parameters)3 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 IPath (org.eclipse.core.runtime.IPath)2 BoardDescriptor (io.sloeber.core.api.BoardDescriptor)1 CodeDescriptor (io.sloeber.core.api.CodeDescriptor)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1