示例#1
0
        private void uploadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (cobPorts.SelectedIndex < 0)
            {
                MessageBox.Show("Select a COM Port first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!File.Exists(cfg.buildPath + "sketch.hex") && !File.Exists(cfg.buildPath + "sketch.bin"))
            {
                MessageBox.Show("HEX File not found, run build first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            if (cobPorts.SelectedItem.ToString() == terminal.port)
            {
                if (terminal.isConnected)
                {
                    terminal.disconnect();
                }
            }

            ArduinoBoard board = cfg.arduinoBoards.First(b => b.name.Equals(cobBoard.SelectedItem.ToString()));

            string cmd = cfg.upload("sketch", board, cobPorts.SelectedItem.ToString());

            System.Console.WriteLine(cmd);
            setListBox1("Starting upload...", Color.Green);
            bwUpload.RunWorkerAsync(cmd);
            toolStripButton2.Enabled = false;
            cobPorts.Enabled         = false;
        }
示例#2
0
        public ProcessResult compile(string file, ArduinoBoard board, string additionals = "")
        {
            string cmd;
            string baseFile = Path.GetFileName(file);

            Dictionary <string, string> compileDict = new Dictionary <string, string>();

            compileDict.Add("includes", " -I\"" + board.corePath + "\" " + " -I\"" + board.variantPath + "\"" + additionals);// + " -I\"" + avrLibcInc + "\"");
            compileDict.Add("source_file", file);
            compileDict.Add("object_file", buildPath + baseFile + ".o");
            compileDict.Add("build.mcu", board.cpu);

            switch (Path.GetExtension(file))
            {
            case ".c":
                cmd = ConfigParser.parseLine(board.getCompilerC(), compileDict);
                break;

            case ".cpp":
                string cpp = board.getCompilerCPP();
                cmd = ConfigParser.parseLine(cpp, compileDict);
                break;

            case ".S":
                cmd = ConfigParser.parseLine(board.getCompilerS(), compileDict);
                break;

            default:
                cmd = "";
                break;
            }

            return(runCmd(cmd));
        }
示例#3
0
        public string getSize(string file, ArduinoBoard board)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("build.path", buildPath);
            dict.Add("build.project_name", "sketch");

            string        cmd = ConfigParser.parseLine(board.getSize(), dict);
            ProcessResult res = runCmd(cmd);

            if (res.returnCode != 0)
            {
                return(String.Empty);
            }

            var    matches = Regex.Matches(res.output.ToString(), board.getSizeRegex(), RegexOptions.Multiline);
            string sout    = "";

            foreach (Match m in matches)
            {
                if (m.Success)
                {
                    sout += m.ToString();
                }
            }

            return(sout);
        }
示例#4
0
        public Configuration(string arduinoPath)
        {
            // set path to the components
            this.arduinoPath = arduinoPath;
            buildPath        = System.IO.Path.GetTempPath() + "IDE4Arduino/build/";

            if (!Directory.Exists(buildPath))
            {
                Directory.CreateDirectory(buildPath);
            }
            arduinoCoreLibPath = Path.Combine(arduinoPath, @"hardware\arduino\avr\libraries");
            arduinoLibPath     = Path.Combine(arduinoPath, @"libraries");
            arduinoUserLibPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Arduino\libraries");

            // Parse Platforms
            string[] vendors            = Directory.GetDirectories(Path.Combine(arduinoPath, "hardware"));
            string   userHardwareFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Arduino\hardware");

            string[] usrVendors = Directory.GetDirectories(userHardwareFolder);

            List <ArduinoPlatform> platforms = new List <ArduinoPlatform>();

            arduinoBoards = new List <ArduinoBoard>();

            vendors = vendors.Concat(usrVendors).ToArray();

            foreach (string vendor in vendors)
            {
                string vendor_name = Path.GetFileName(vendor);

                if (vendor_name.Equals("tools"))
                {
                    continue;
                }

                string[] archs = Directory.GetDirectories(vendor);

                foreach (string arch in archs)
                {
                    string arch_name = Path.GetFileName(arch);

                    try
                    {
                        ArduinoPlatform p = new ArduinoPlatform(arduinoPath, Path.Combine(arch, "platform.txt"), vendor_name, arch_name);
                        if (p.cfg.Count < 1)
                        {
                            continue;
                        }
                        arduinoBoards.AddRange(ArduinoBoard.parseBoardFile(Path.Combine(arch, "boards.txt"), p));
                    }
                    catch
                    { }
                }
            }

            recreateLibraries();
        }
示例#5
0
        private void cobCPU_SelectedIndexChanged(object sender, EventArgs e)
        {
            //rebuildAll = true;
            ArduinoBoard cur = cfg.arduinoBoards.First(b => b.name.Equals(cobBoard.SelectedItem.ToString()));

            cur.setCPU(cobCPU.SelectedItem.ToString());

            //cur.cpu = cobCPU.SelectedItem.ToString();
            //curCfg = cfg.buildCurrentConfig(cobBoard.SelectedItem.ToString(), cobCPU.SelectedItem.ToString());
        }
示例#6
0
        public ProcessResult createHEX(string file, ArduinoBoard board)
        {
            Dictionary <string, string> compileDict = new Dictionary <string, string>();

            compileDict.Add("build.path", buildPath);
            compileDict.Add("build.project_name", "sketch");

            string cmd = ConfigParser.parseLine(board.getHEX(), compileDict);

            return(runCmd(cmd));
        }
示例#7
0
        public ProcessResult linkArchive(string file, string archive_file, ArduinoBoard board)
        {
            Dictionary <string, string> linkDict = new Dictionary <string, string>();

            linkDict.Add("build.path", buildPath);
            linkDict.Add("archive_file", archive_file);
            linkDict.Add("object_file", buildPath + file + ".o");

            string cmd = ConfigParser.parseLine(board.getArchive(), linkDict);

            return(runCmd(cmd));
        }
示例#8
0
        public ProcessResult combine(string file, string archive_file, ArduinoBoard board)
        {
            Dictionary <string, string> compileDict = new Dictionary <string, string>();

            compileDict.Add("build.path", buildPath);
            compileDict.Add("build.project_name", "sketch");
            compileDict.Add("object_files", buildPath + "sketch.cpp.o");
            compileDict.Add("archive_file", archive_file);
            compileDict.Add("build.mcu", board.cpu);
            compileDict.Add("build.variant.path", board.variantPath);

            string cmd = ConfigParser.parseLine(board.getCombine(), compileDict);

            return(runCmd(cmd));
        }
示例#9
0
        public string upload(string filename, ArduinoBoard board, string port)
        {
            string cmd = "";

            Dictionary <string, string> toolDict = new Dictionary <string, string>();

            toolDict.Add("build.path", buildPath);
            toolDict.Add("build.project_name", "sketch");
            toolDict.Add("upload.verbose", "");
            toolDict.Add("serial.port", port);
            toolDict.Add("serial.port.file", port);
            toolDict.Add("build.mcu", board.cpu);

            cmd = ConfigParser.parseLine(board.getUploadCmd(), toolDict);

            return(cmd);
        }
示例#10
0
        private void cobBoard_SelectedIndexChanged(object sender, EventArgs e)
        {
            rebuildAll = true;
            cobCPU.Items.Clear();

            ArduinoBoard cur = cfg.arduinoBoards.First(b => b.name.Equals(cobBoard.SelectedItem.ToString()));

            if (cur.cpu_names.Length > 0)
            {
                cobCPU.Items.AddRange(cur.cpu_names);
                cobCPU.SelectedIndex = 0;
                cobCPU.Enabled       = true;
            }
            else
            {
                cobCPU.Enabled = false;
            }
        }
示例#11
0
        private void buildToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (bwCompiler.IsBusy)
            {
                return;
            }

            if (cobBoard.SelectedIndex < 0 || (cobCPU.Items.Count > 0 && cobCPU.SelectedIndex < 0))
            {
                MessageBox.Show("Please select platform / processor", "Build Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            EditorPage page = dockPanel1.ActiveDocument as EditorPage;

            if (page != null)
            {
                if (!page.save())
                {
                    setListBox1("Could not save " + page.fileName, Color.Red);
                }

                outputListBox.Items.Clear();

                string filename = Path.GetFileNameWithoutExtension(page.fileName);

                if (!new DirectoryInfo(cfg.buildPath).Name.Equals(filename))
                {
                    cfg.buildPath += filename + "/";
                }

                _text = page.Editor.Text;

                ArduinoBoard board = cfg.arduinoBoards.First(b => b.name.Equals(cobBoard.SelectedItem.ToString()));


                bwCompiler.RunWorkerAsync(board);
            }
        }
示例#12
0
        private void bwCompiler_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = false;

            ArduinoBoard board = (ArduinoBoard)e.Argument;

            string archive_name = Configuration.GetValidFileName(board.name + board.cpu).Replace(" ", "") + ".a";

            System.Console.WriteLine("Archive Name: " + archive_name);

            List <ArduinoLibrary> usedLibs = new List <ArduinoLibrary>();

            Regex myRegex = new Regex(@"#include [<""](\S+)[>""]", RegexOptions.None);

            foreach (Match myMatch in myRegex.Matches(_text))
            {
                if (myMatch.Success)
                {
                    string incName = myMatch.Groups[myMatch.Groups.Count - 1].ToString();

                    if (incName.Contains("/") || incName.Contains("\\"))
                    {
                        continue;
                    }

                    string libName = Path.GetFileNameWithoutExtension(incName);

                    System.Console.WriteLine("searching for: " + libName);

                    try
                    {
                        ArduinoLibrary f = cfg.arduinoLibs.First(l => l.name.Equals(libName));
                        System.Console.WriteLine("Found by name: " + f.name);
                        usedLibs.Add(f);
                    }
                    catch
                    {
                        bool found = false;
                        foreach (ArduinoLibrary l in cfg.arduinoLibs)
                        {
                            int idx = l.cppFiles.FindIndex(x => Path.GetFileNameWithoutExtension(x).Equals(libName));
                            if (idx != -1)
                            {
                                System.Console.WriteLine("Found by Include: " + l.name);
                                usedLibs.Add(l);
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            setListBox1("Library: " + libName + " not found, assuming system library", Color.Blue);
                        }
                    }
                }
            }

            foreach (ArduinoLibrary l in usedLibs)
            {
                setListBox1(l.name + ": " + l.path, Color.Green);
            }

            List <FunctionListItem> functions = EditorPage.parseFunctions(_text);;

            if (!Directory.Exists(cfg.buildPath))
            {
                Directory.CreateDirectory(cfg.buildPath);
            }

            string[] lines     = _text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            int      lineCnt   = 0;
            bool     incomment = false;

            StringBuilder temp = new StringBuilder();
            EditorPage    page = (EditorPage)dockPanel1.ActiveDocument;

            temp.AppendLine("#line 1 \"" + Path.GetFileName(page.fileName) + "\"");

            foreach (string line in lines)
            {
                lineCnt++;
                string test = line.Trim();

                if (test.Length < 2)
                {
                    temp.AppendLine();
                    continue;
                }

                if (!incomment)
                {
                    if (test[0] == '#' || test.StartsWith("//"))
                    {
                        temp.AppendLine(line);
                        continue;
                    }

                    if (test.StartsWith("/*"))
                    {
                        temp.AppendLine();
                        incomment = true;
                        continue;
                    }

                    break;
                }
                else
                {
                    temp.AppendLine();
                    if (test.EndsWith("*/"))
                    {
                        incomment = false;
                    }
                }
            }

            temp.AppendLine("#include \"Arduino.h\"");

            foreach (FunctionListItem func in functions)
            {
                temp.AppendLine(func.name + ";");
            }

            temp.AppendLine("#line " + lineCnt.ToString()); // +" \"sketch.ino\""

            for (int i = lineCnt - 1; i < lines.Length; i++)
            {
                temp.AppendLine(lines[i]);
            }

            File.WriteAllText(cfg.buildPath + "sketch.ino", _text);
            File.WriteAllText(cfg.buildPath + "sketch.cpp", temp.ToString());

            string[] arduinoSrc = Directory.GetFiles(board.corePath, "*.cpp", SearchOption.AllDirectories);
            arduinoSrc = arduinoSrc.Concat(Directory.GetFiles(board.corePath, "*.c", SearchOption.AllDirectories)).ToArray();
            arduinoSrc = arduinoSrc.Concat(Directory.GetFiles(board.variantPath, "*.cpp", SearchOption.TopDirectoryOnly)).ToArray();
            arduinoSrc = arduinoSrc.Concat(Directory.GetFiles(board.variantPath, "*.c", SearchOption.TopDirectoryOnly)).ToArray();

            string libInc = "";

            foreach (ArduinoLibrary lib in usedLibs)
            {
                libInc += lib.getIncludePath();
            }

            setListBox1("compiling sketch.cpp");

            ProcessResult res = cfg.compile(cfg.buildPath + "sketch.cpp", board, libInc);

            if (res.returnCode == 0)
            {
                if (!File.Exists(cfg.buildPath + archive_name) || rebuildAll)
                {
                    System.Console.WriteLine("Rebuilding Archive: " + cfg.buildPath + archive_name);
                    foreach (string file in arduinoSrc)
                    {
                        string baseFile = Path.GetFileName(file);
                        setListBox1("compiling: " + baseFile);
                        res = cfg.compile(file, board);

                        if (res.returnCode != 0)
                        {
                            setListBox1("Error: " + res.error, Color.Red);

                            return;
                        }
                    }

                    foreach (ArduinoLibrary l in usedLibs)
                    {
                        foreach (string file in l.cppFiles)
                        {
                            setListBox1("compiling: " + file);
                            res = cfg.compile(file, board, libInc);
                            if (res.returnCode != 0)
                            {
                                setListBox1("Error: " + res.error, Color.Red);
                                return;
                            }
                        }
                    }

                    foreach (string file in arduinoSrc)
                    {
                        string baseFile = Path.GetFileName(file);
                        setListBox1("linking " + baseFile + ".o");
                        res = cfg.linkArchive(baseFile, archive_name, board);
                        if (res.returnCode != 0)
                        {
                            setListBox1("Error: " + res.error, Color.Red);
                            return;
                        }
                    }

                    foreach (ArduinoLibrary l in usedLibs)
                    {
                        foreach (string file in l.cppFiles)
                        {
                            string baseFile = Path.GetFileName(file);
                            setListBox1("linking " + baseFile + ".o");
                            res = cfg.linkArchive(baseFile, archive_name, board);
                            if (res.returnCode != 0)
                            {
                                setListBox1("Error: " + res.error, Color.Red);
                                return;
                            }
                        }
                    }
                }

                setListBox1("linking sketch.cpp.o");
                res = cfg.combine("sketch.cpp", archive_name, board);
                if (res.returnCode != 0)
                {
                    setListBox1("Error: " + res.error, Color.Red);
                    return;
                }

                /*
                 * setListBox1("Creating EEPROM file");
                 * res = cfg.createEEProm("sketch.cpp", board);
                 * if (res.returnCode != 0)
                 * {
                 *  setListBox1("Error: " + res.error, Color.Red);
                 *  return;
                 * }*/


                setListBox1("Creating HEX file");
                res = cfg.createHEX("sketch.cpp", board);
                if (res.returnCode != 0)
                {
                    setListBox1("Error: " + res.error, Color.Red);
                    return;
                }

                string size = cfg.getSize("sketch.cpp", board);
                if (size == String.Empty)
                {
                    setListBox1("Error: " + res.error, Color.Red);
                    return;
                }

                setListBox1(size);

                rebuildAll = false;
                setListBox1("success", Color.Green);
                e.Result = true;
            }
            else
            {
                setListBox1("Error: " + res.error, Color.Red);
                return;
            }
        }