Esempio n. 1
0
        public static ClController ProMicro()
        {
            ClController output = new ClController();

            output.name        = "Pro Micro - Atmega32u4";
            output.startEEPROM = 600;
            output.endEEPROM   = 1000;
            output.pins        = new List <string> {
                "2", "3", "4", "5", "6", "7", "8", "9", "10", "14", "15", "16", "A0", "A1", "A2", "A3"
            };
            output.reservedPins = new List <ClReservedPin>();
            output.reservedPins.Add(new ClReservedPin("2", "I2C"));
            output.reservedPins.Add(new ClReservedPin("3", "I2C"));
            output.reservedPins.Add(new ClReservedPin("14", "SPI"));
            output.reservedPins.Add(new ClReservedPin("15", "SPI"));
            output.reservedPins.Add(new ClReservedPin("16", "SPI"));
            output.features = new List <string> {
                "I2C", "SPI"
            };
            return(output);
        }
Esempio n. 2
0
 public static void init()
 {
     _selectedController = new ClController();
     profile             = new ClBuildProfile();
 }
Esempio n. 3
0
        public static string BuildAnimus(ClBuildProfile bp, ClController controller, string animusPath, string modPath, string outputPath)
        {
            string output = "";

            if (animusPath.EndsWith(MdConstant.pseparator.ToString()))
            {
                //donothing
            }
            else
            {
                animusPath = animusPath + MdConstant.pseparator;
            }

            if (modPath.EndsWith(MdConstant.pseparator.ToString()))
            {
                //donothing
            }
            else
            {
                modPath = modPath + MdConstant.pseparator;
            }

            if (outputPath.EndsWith(MdConstant.pseparator.ToString()))
            {
                //donothing
            }
            else
            {
                outputPath = outputPath + MdConstant.pseparator;
            }

            if (bp.name.Contains("\"") || bp.name.Contains("\\") ||
                bp.driver_build.Contains("\"") || bp.driver_build.Contains("\\") ||
                bp.variant.Contains("\"") || bp.variant.Contains("\\"))
            {
                output = "Error: name, build, or variant contains illegal characters.";
                return(output);
            }

            if (bp.hpins.Count < 1 || bp.vpins.Count < 1)
            {
                output = "Error: you need at least 1 pin per column and row.";
                return(output);
            }

            if (!File.Exists(animusPath + MdConstant.pseparator + "animus.ino"))
            {
                output = "Error: animus.ino missing, animus path is invalid";
                return(output);
            }

            if (!Directory.Exists(modPath))
            {
                output = "Error: mod folder missing, mod path is invalid.";
                return(output);
            }

            var cmr = bp.CheckMods(controller, modPath);


            if (cmr == ClBuildProfile.CheckModResponse.DirectoryDoesNotExist)
            {
                output = "Error: mod directory does not exist.";
                return(output);
            }
            else if (cmr == ClBuildProfile.CheckModResponse.ModDoesNotExist)
            {
                output = "Error: mod not found.";
                return(output);
            }
            else if (cmr == ClBuildProfile.CheckModResponse.ModNamingError)
            {
                output = "Error: mod naming error, mod file name and mod name does not match.";
                return(output);
            }
            else if (cmr == ClBuildProfile.CheckModResponse.PinConflictError)
            {
                output = "Error: Pin conflict error, a pin is used more than once.";
                return(output);
            }
            else if (cmr == ClBuildProfile.CheckModResponse.PinDoesNotExist)
            {
                output = "Error: Pin does not exist for the selected controller.";
                return(output);
            }
            else if (cmr == ClBuildProfile.CheckModResponse.EEPROMConflictError)
            {
                output = "Error: EEPROM conflict.";
                return(output);
            }
            else if (cmr == ClBuildProfile.CheckModResponse.AllClear)
            {
                // vars
                string ofolder = outputPath + bp.bp_name + MdConstant.pseparator + Path.GetFileNameWithoutExtension(animusPath) + MdConstant.pseparator + "animus";
                Console.WriteLine(ofolder);
                string mafile = ofolder + MdConstant.pseparator + "animus.ino";
                string mmfile = ofolder + MdConstant.pseparator + "mod.ino";

                // copy main animus files
                MdCore.DirectoryCopy(animusPath, ofolder);

                // edit main animus file
                MdCore.SetFileAttribute(mafile, MdConstant.bRow, bp.vpins.Count.ToString());
                MdCore.SetFileAttribute(mafile, MdConstant.bCol, bp.hpins.Count.ToString());

                MdCore.SetFileAttribute(mafile, MdConstant.bName, "\"" + bp.name + "\"");

                MdCore.SetFileAttribute(mafile, MdConstant.bVariant, "\"" + bp.variant + "\"");

                MdCore.SetFileAttribute(mafile, MdConstant.bBuild, "\"" + bp.driver_build + "\"");

                MdCore.SetFileAttribute(mafile, MdConstant.bVPins, ListStringToString(bp.vpins));

                MdCore.SetFileAttribute(mafile, MdConstant.bHPins, ListStringToString(bp.hpins));

                MdCore.SetFileAttribute(mafile, MdConstant.bRefresh, bp.refresh);

                // edit main mod file

                MdCore.SetFileAttribute(mmfile, MdConstant.bMStart, GenerateModMethodString(bp.mods, MdConstant.bMEStartup));
                MdCore.SetFileAttribute(mmfile, MdConstant.bMPreCoord, GenerateModMethodString(bp.mods, MdConstant.bMEPreCoord));
                MdCore.SetFileAttribute(mmfile, MdConstant.bMPrePress, GenerateModMethodString(bp.mods, MdConstant.bMEPrePress));
                MdCore.SetFileAttribute(mmfile, MdConstant.bMKDown, GenerateModMethodString(bp.mods, MdConstant.bMEKDown));
                MdCore.SetFileAttribute(mmfile, MdConstant.bMKUp, GenerateModMethodString(bp.mods, MdConstant.bMEKUp));
                MdCore.SetFileAttribute(mmfile, MdConstant.bMLoop, GenerateModMethodString(bp.mods, MdConstant.bMELoop));
                MdCore.SetFileAttribute(mmfile, MdConstant.bMSerial, GenerateModMethodString(bp.mods, MdConstant.bMESerial));

                // copy mod files
                List <string> modpaths = bp.mods.Select(str => modPath + str).ToList();
                foreach (string str in modpaths)
                {
                    DirectoryCopy(str, ofolder, false);
                    string modName = str.Substring(modPath.Length);
                    string modFile = ofolder + MdConstant.pseparator + "mod_" + modName + ".ino";
                    EnsureMethodExists(modFile, MdConstant.bMFPreCoord);
                    EnsureMethodExists(modFile, MdConstant.bMFPrePress);
                }
            }
            else
            {
                output = "Error: Unknown build error.";
                return(output);
            }

            /*
             * List<string> modpool = new List<string>();
             * modpool = Directory.GetDirectories(MdSetting.setting.modPath).Select(str => Path.GetFileNameWithoutExtension(str)).ToList();
             * foreach (string mod in bp.mods)
             * {
             *  if (modpool.Contains(mod))
             *  {
             *
             *  }
             *  else
             *  {
             *      output = "Error: mod " + mod + " missing from the mod path.";
             *      return output;
             *  }
             * }
             */

            output = "Build Completed for " + bp.name;
            return(output);
        }
Esempio n. 4
0
        public CheckModResponse CheckMods(ClController controller, string modPath)
        {
            CheckModResponse output = CheckModResponse.AllClear;

            if (!Directory.Exists(modPath))
            {
                output = CheckModResponse.DirectoryDoesNotExist;
                return(output);
            }

            List <string> usedPins     = new List <string>();
            List <string> usedEEPROM   = new List <string>();
            List <string> usedFeatures = new List <string>();

            usedPins.AddRange(hpins);
            usedPins.AddRange(vpins);


            List <string> modpool = new List <string>();

            modpool = Directory.GetDirectories(MdSetting.setting.modPath).Select(str => Path.GetFileNameWithoutExtension(str)).ToList();
            foreach (string mod in mods)
            {
                if (modpool.Contains(mod))
                {
                    string mfName = "mod_" + mod + ".ino";
                    string modDir = modPath;
                    if (modDir.EndsWith(MdConstant.pseparator.ToString()))
                    {
                        // do nothing
                    }
                    else
                    {
                        modDir = modDir + MdConstant.pseparator;
                    }
                    modDir = modDir + mod + MdConstant.pseparator;
                    string mfPath = modDir + mfName;
                    Console.WriteLine(mfPath);
                    if (!File.Exists(mfPath))
                    {
                        output = CheckModResponse.ModDoesNotExist;
                        return(output);
                    }

                    List <string> mfContent = File.ReadAllLines(mfPath).ToList();

                    // checks if #define mod_modname is correctly made
                    if (mfContent.Find(str => str.StartsWith("#define mod_modname")) == "#define mod_modname " + mod)
                    {
                        // do nothing
                    }
                    else
                    {
                        output = CheckModResponse.ModNamingError;
                        return(output);
                    }

                    // gets list of requirements
                    List <string> mfRequirements = new List <string>();
                    bool          addToReq       = false;
                    foreach (string str in mfContent)
                    {
                        if (str == "BUILDER_REQUIREMENT_END")
                        {
                            addToReq = false;
                        }

                        if (addToReq)
                        {
                            mfRequirements.Add(str);
                        }

                        if (str == "BUILDER_REQUIREMENT_START")
                        {
                            addToReq = true;
                        }

                        // break omitted for readability
                    }

                    if (mfRequirements.Count > 0)
                    {
                        foreach (string str in mfContent)
                        {
                            // gets pin ownership
                            if (str.StartsWith("Pin("))
                            {
                                string temp = str.Substring(str.IndexOf('(') + 1);
                                temp = temp.Substring(0, temp.IndexOf(')'));

                                temp     = temp.Replace(" ", string.Empty);
                                usedPins = temp.Split(',').ToList();
                                if (usedPins.All(pstr => controller.pins.Contains(pstr)))
                                {
                                    // do nothing
                                }
                                else
                                {
                                    output = CheckModResponse.PinDoesNotExist;
                                    return(output);
                                }
                            }
                            else if (str.StartsWith("EEPROM("))// reserves EEPROM addresses
                            {
                                string temp = str.Substring(str.IndexOf('(') + 1);
                                temp = temp.Substring(0, temp.IndexOf(')'));

                                temp       = temp.Replace(" ", string.Empty);
                                usedEEPROM = temp.Split(',').ToList();
                            }
                            else // adds additional features
                            {
                                // f**k LINQ, i love you LINQ but i am having a brain fart right now
                                if (controller.features.Contains(str))
                                {
                                    usedFeatures.Add(str);
                                    foreach (ClReservedPin rp in controller.reservedPins)
                                    {
                                        if (rp.use == str)
                                        {
                                            if (usedPins.Contains(rp.name))
                                            {
                                                output = CheckModResponse.PinConflictError;
                                                return(output);
                                            }
                                            else
                                            {
                                                usedPins.Add(rp.name);
                                            }
                                        }
                                    }
                                }
                            }

                            if (usedEEPROM.Distinct().Count() != usedEEPROM.Count)
                            {
                                output = CheckModResponse.EEPROMConflictError;
                                return(output);
                            }


                            foreach (string eeprom in usedEEPROM)
                            {
                                if (Convert.ToInt32(eeprom) < controller.startEEPROM || Convert.ToInt32(eeprom) > controller.endEEPROM)
                                {
                                    output = CheckModResponse.EEPROMConflictError;
                                    return(output);
                                }
                            }
                        }
                    }
                }
                else
                {
                    output = CheckModResponse.ModDoesNotExist;
                    return(output);
                }
            }

            output = CheckModResponse.AllClear;
            return(output);
        }