public void recreateLibraries() { arduinoLibs = new List <ArduinoLibrary>(); try { string[] temp = Directory.GetDirectories(arduinoCoreLibPath); foreach (string dir in temp) { ArduinoLibrary lib = new ArduinoLibrary(dir); arduinoLibs.Add(lib); } temp = Directory.GetDirectories(arduinoLibPath); foreach (string dir in temp) { ArduinoLibrary lib = new ArduinoLibrary(dir); arduinoLibs.Add(lib); } temp = Directory.GetDirectories(arduinoUserLibPath); foreach (string dir in temp) { ArduinoLibrary lib = new ArduinoLibrary(dir); arduinoLibs.Add(lib); } } catch { } arduinoLibs.Sort(); keyWords = new List <string>() { "Serial", "pinMode", "INPUT", "OUTPUT", "INPUT_PULLUP", "HIGH", "LOW", "LED_BUILTIN", "true", "false", "available", "begin", "end", "print", "println" }; foreach (ArduinoLibrary lib in arduinoLibs) { keyWords.Add(lib.name); keyWords.AddRange(lib.keyWords.ToArray()); } keyWords = keyWords.Distinct().ToList(); keyWords.Sort(); }
int IComparable.CompareTo(object other) { ArduinoLibrary o = (ArduinoLibrary)other; return(String.Compare(this.name, o.name)); }
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; } }