private void ExecuteCommand(ProgramCommand programCommand) { string command = programCommand.Domain + "/" + programCommand.Target + "/" + programCommand.CommandString + "/" + System.Uri.EscapeDataString(programCommand.CommandArguments); var interfaceCommand = new MigInterfaceCommand(command); Homegenie.InterfaceControl(interfaceCommand); }
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); }
private void ExecuteScript(List <ProgramCommand> commands) { int repeatStartLine = 0; int repeatCount = 0; for (int x = 0; x < commands.Count; x++) { if (commands[x].Domain == Domains.HomeAutomation_HomeGenie) { switch (commands[x].Target) { case SourceModule.Automation: // string cs = commands[x].CommandString; switch (cs) { case "Program.Pause": Thread.Sleep((int)(double.Parse(commands[x].CommandArguments, System.Globalization.CultureInfo.InvariantCulture) * 1000)); break; case "Program.Repeat": // TODO: implement check for contiguous repeat statements if (repeatCount <= 0) { repeatCount = (int)(double.Parse(commands[x].CommandArguments, System.Globalization.CultureInfo.InvariantCulture)); } if (--repeatCount == 0) { repeatStartLine = x + 1; } else { x = repeatStartLine - 1; } break; case "Program.Run": string programId = commands[x].CommandArguments; var programToRun = Homegenie.ProgramManager.Programs.Find(p => p.Address.ToString() == programId || p.Name == programId); if (programToRun != null /*&& programToRun.Address != program.Address*/ && !programToRun.IsRunning) { Homegenie.ProgramManager.Run(programToRun, ""); } break; case "Program.WaitFor": hgScriptingHost.Program.WaitFor(commands[x].CommandArguments); break; case "Program.Play": hgScriptingHost.Program.Play(commands[x].CommandArguments); break; case "Program.Say": var language = "en-US"; var sentence = commands[x].CommandArguments; int lidx = sentence.LastIndexOf("/"); if (lidx > 0) { language = sentence.Substring(lidx + 1); sentence = sentence.Substring(0, lidx); } hgScriptingHost.Program.Say(sentence, language); break; default: var programCommand = commands[x]; string wrequest = programCommand.Domain + "/" + programCommand.Target + "/" + programCommand.CommandString + "/" + programCommand.CommandArguments; Homegenie.ExecuteAutomationRequest(new MigInterfaceCommand(wrequest)); break; } // break; } } else { ExecuteCommand(commands[x]); } // Thread.Sleep(10); } }