diff --git a/X-Plane Voice Control/Commands/LightsControl.cs b/X-Plane Voice Control/Commands/LightsControl.cs new file mode 100644 index 0000000..d405954 --- /dev/null +++ b/X-Plane Voice Control/Commands/LightsControl.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Speech.Recognition; +using System.Speech.Synthesis; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ExtPlaneNet; + +namespace X_Plane_Voice_Control.Commands +{ + class LightsControl : ControlTemplate + { + private readonly string[] _lightStatusesStrings = { "off", "on" }; + private readonly string[] _lightTypeStrings = { "logo", "position", "beacon", "wing", "wheel" }; + public LightsControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) + { + var lightsControl = new GrammarBuilder(); + lightsControl.Append("please", 0, 1); + lightsControl.Append("set", 0, 1); + lightsControl.Append(new Choices(_lightTypeStrings)); + lightsControl.Append("lights"); + lightsControl.Append("to", 0, 1); + lightsControl.Append(new Choices(_lightStatusesStrings)); + lightsControl.Append("please", 0, 1); + Grammar = new Grammar(lightsControl); + RecognitionPattern = Constants.DeserializeRecognitionPattern(lightsControl.DebugShowPhrases); + } + + public sealed override Grammar Grammar { get; } + public override string RecognitionPattern { get; } + + public override void DataRefSubscribe() + { + } + + public override void OnTrigger(RecognitionResult rResult, string phrase) + { + var lightToSwitch = _lightTypeStrings.First(phrase.Contains); + var valueToSet = _lightStatusesStrings.First(phrase.Contains); + + if (lightToSwitch == _lightTypeStrings[1]) + { + if (valueToSet.Equals("off", StringComparison.CurrentCultureIgnoreCase)) + { + XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); + XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); + XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_down"); + } + else + { + XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); + XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); + } + } + else if (lightToSwitch == _lightTypeStrings[2]) + { + XPlaneInterface.SetExecutingCommand($"sim/lights/beacon_lights_{valueToSet}"); + } + else + { + XPlaneInterface.SetExecutingCommand($"laminar/B738/switch/{lightToSwitch}_light_{valueToSet}"); + } + SpeechSynthesizer.SpeakAsync($"{lightToSwitch} lights turned {valueToSet}"); + } + } +} diff --git a/X-Plane Voice Control/X-Plane Voice Control.csproj b/X-Plane Voice Control/X-Plane Voice Control.csproj index d207a9b..bb4687a 100644 --- a/X-Plane Voice Control/X-Plane Voice Control.csproj +++ b/X-Plane Voice Control/X-Plane Voice Control.csproj @@ -53,6 +53,7 @@ +