Ejemplo n.º 1
0
        public override List<ProgramError> Compile()
        {
            List<ProgramError> errors = new List<ProgramError>();

            // Generate, compile and upload Arduino Sketch
            string sketchFileName = ArduinoAppFactory.GetSketchFile(ProgramBlock.Address.ToString());
            if (!Directory.Exists(Path.GetDirectoryName(sketchFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(sketchFileName));
            }
            string sketchMakefile = Path.Combine(Path.GetDirectoryName(sketchFileName), "Makefile");

            try
            {
                // .ino source is stored in the ScriptSource property
                File.WriteAllText(sketchFileName, ProgramBlock.ScriptSource);
                // Makefile source is stored in the ScriptSetup property
                File.WriteAllText(sketchMakefile, ProgramBlock.ScriptSetup);
                errors = ArduinoAppFactory.CompileSketch(sketchFileName, sketchMakefile);
            }
            catch (Exception e)
            {
                errors.Add(new ProgramError()
                {
                    Line = 0,
                    Column = 0,
                    ErrorMessage = "General failure: is 'arduino-mk' package installed?\n\n" + e.Message,
                    ErrorNumber = "500",
                    CodeBlock = CodeBlockEnum.CR
                });
            }

            return errors;
        }
Ejemplo n.º 2
0
        public MethodRunResult Run(string options)
        {
            var result = new MethodRunResult();

            result = new MethodRunResult();
            Homegenie.RaiseEvent(
                Domains.HomeGenie_System,
                Domains.HomeAutomation_HomeGenie_Automation,
                ProgramBlock.Address.ToString(),
                "Arduino Sketch Upload",
                "Arduino.UploadOutput",
                "Upload started"
                );
            string[] outputResult = ArduinoAppFactory.UploadSketch(Path.Combine(
                                                                       AppDomain.CurrentDomain.BaseDirectory,
                                                                       "programs",
                                                                       "arduino",
                                                                       ProgramBlock.Address.ToString()
                                                                       )).Split('\n');
            //
            for (int x = 0; x < outputResult.Length; x++)
            {
                if (!String.IsNullOrWhiteSpace(outputResult[x]))
                {
                    Homegenie.RaiseEvent(
                        Domains.HomeGenie_System,
                        Domains.HomeAutomation_HomeGenie_Automation,
                        ProgramBlock.Address.ToString(),
                        "Arduino Sketch",
                        "Arduino.UploadOutput",
                        outputResult[x]
                        );
                    Thread.Sleep(500);
                }
            }
            //
            Homegenie.RaiseEvent(
                Domains.HomeGenie_System,
                Domains.HomeAutomation_HomeGenie_Automation,
                ProgramBlock.Address.ToString(),
                "Arduino Sketch",
                "Arduino.UploadOutput",
                "Upload finished"
                );
            return(result);
        }
Ejemplo n.º 3
0
 public override MethodRunResult Run(string options)
 {
     var result = new MethodRunResult();
     HomeGenie.RaiseEvent(
         Domains.HomeGenie_System,
         Domains.HomeAutomation_HomeGenie_Automation,
         ProgramBlock.Address.ToString(),
         "Arduino Sketch Upload",
         "Arduino.UploadOutput",
         "Upload started"
     );
     string[] outputResult = ArduinoAppFactory.UploadSketch(Path.Combine(
         AppDomain.CurrentDomain.BaseDirectory,
         "programs",
         "arduino",
         ProgramBlock.Address.ToString()
     )).Split('\n');
     //
     foreach (var res in outputResult)
     {
         if (String.IsNullOrWhiteSpace(res)) continue;
         HomeGenie.RaiseEvent(
             Domains.HomeGenie_System,
             Domains.HomeAutomation_HomeGenie_Automation,
             ProgramBlock.Address.ToString(),
             "Arduino Sketch",
             "Arduino.UploadOutput",
             res
         );
         Thread.Sleep(500);
     }
     //
     HomeGenie.RaiseEvent(
         Domains.HomeGenie_System,
         Domains.HomeAutomation_HomeGenie_Automation,
         ProgramBlock.Address.ToString(),
         "Arduino Sketch",
         "Arduino.UploadOutput",
         "Upload finished"
     );
     return result;
 }