From dca7d5d7637a24dd712f21a8ec4ef7fec2c1116c Mon Sep 17 00:00:00 2001 From: David Date: Wed, 20 Jun 2018 22:08:36 +0200 Subject: [PATCH] Upda to V0.03 --- README.md | 12 ++- .../Commands/AirBleedControl.cs | 56 +++++++++++++ X-Plane Voice Control/Commands/PackControl.cs | 50 ++++++++++++ .../Commands/ProbeHeatControl.cs | 56 +++++++++++++ .../Commands/SmokingAndSeatbeltsControl.cs | 80 +++++++++++++++++++ X-Plane Voice Control/Commands/TaxiLights.cs | 19 ++--- .../Commands/WindowHeatControl.cs | 62 ++++++++++++++ .../X-Plane Voice Control.csproj | 5 ++ 8 files changed, 330 insertions(+), 10 deletions(-) create mode 100644 X-Plane Voice Control/Commands/AirBleedControl.cs create mode 100644 X-Plane Voice Control/Commands/PackControl.cs create mode 100644 X-Plane Voice Control/Commands/ProbeHeatControl.cs create mode 100644 X-Plane Voice Control/Commands/SmokingAndSeatbeltsControl.cs create mode 100644 X-Plane Voice Control/Commands/WindowHeatControl.cs diff --git a/README.md b/README.md index d61c89a..9f88e56 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,21 @@ You need ExtPlane Plugin installed ([Download](https://github.com/vranki/ExtPlan * Taxi lights control * __set [taxi lights on / taxi lights off]__ please * Engine control - * __[start / light up / kill / shut down] the engine number [one / two]]__ please + * __[start / light up / kill / shut down] the engine number [one / two]__ please * __introduce fuel [into / to] number engine [one / two]__ please * APU control * __[start / light up / stop / shutdown] APU__ please * __APU [on / off]__ please +* Probe heat + * set __probe heat [on/off]__ please +* Window heat + * set __window heat [on/off]__ please +* No Smoking / Seatbelts + * set __[no smoking / seatbelts] [off / auto / on]__ please +* Packs + * set __[left / right] pack to [off / auto / high]__ please +* Bleed air + * set __[apu / engine one / engine two] bleed air to [off / on]__ please __Cheat sheet:__ * __Needed__ diff --git a/X-Plane Voice Control/Commands/AirBleedControl.cs b/X-Plane Voice Control/Commands/AirBleedControl.cs new file mode 100644 index 0000000..d8c3339 --- /dev/null +++ b/X-Plane Voice Control/Commands/AirBleedControl.cs @@ -0,0 +1,56 @@ +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 AirBleedControl : ControlTemplate + { + private readonly string[] _bleedStatusStrings = { "off", "on" }; + private readonly string[] _bleedUnitsStrings = { "apu", "engine one", "engine two" }; + public AirBleedControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) + { + var airBleedGrammar = new GrammarBuilder(); + airBleedGrammar.Append("please", 0, 1); + airBleedGrammar.Append("set", 0, 1); + airBleedGrammar.Append(new Choices(_bleedUnitsStrings)); + airBleedGrammar.Append("bleed"); + airBleedGrammar.Append("air", 0, 1); + airBleedGrammar.Append("to", 0, 1); + airBleedGrammar.Append(new Choices(_bleedStatusStrings)); + airBleedGrammar.Append("please", 0, 1); + Grammar = new Grammar(airBleedGrammar); + RecognitionPattern = Constants.DeserializeRecognitionPattern(airBleedGrammar.DebugShowPhrases); + } + + public sealed override Grammar Grammar { get; } + public override string RecognitionPattern { get; } + + public override void DataRefSubscribe() + { + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/bleed_air_1_pos"); + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/bleed_air_2_pos"); + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/bleed_air_apu_pos"); + } + + public override void OnTrigger(RecognitionResult rResult, string phrase) + { + var stringUnit = _bleedUnitsStrings.First(phrase.Contains); + var stringValueToSet = _bleedStatusStrings.First(phrase.Contains); + var index = Array.IndexOf(_bleedStatusStrings, stringValueToSet); + var indexUnit = Array.IndexOf(_bleedUnitsStrings, stringUnit); + var unitToSet = "apu"; + if (indexUnit == 1 || indexUnit == 2) + unitToSet = indexUnit.ToString(); + XPlaneInterface.SetDataRef($"laminar/B738/toggle_switch/bleed_air_{unitToSet}_pos", index); + SpeechSynthesizer.SpeakAsync($"{stringUnit} bleed air set to {stringValueToSet}"); + } + } +} diff --git a/X-Plane Voice Control/Commands/PackControl.cs b/X-Plane Voice Control/Commands/PackControl.cs new file mode 100644 index 0000000..49d33af --- /dev/null +++ b/X-Plane Voice Control/Commands/PackControl.cs @@ -0,0 +1,50 @@ +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 PackControl : ControlTemplate + { + private readonly string[] _packStatutesStrings = { "off", "auto", "high" }; + private readonly string[] _packUnitsStrings = { "left", "right" }; + public PackControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) + { + var packControl = new GrammarBuilder(); + packControl.Append("please", 0, 1); + packControl.Append("set", 0, 1); + packControl.Append(new Choices(_packUnitsStrings)); + packControl.Append("pack"); + packControl.Append("to", 0, 1); + packControl.Append(new Choices(_packStatutesStrings)); + packControl.Append("please", 0, 1); + Grammar = new Grammar(packControl); + RecognitionPattern = Constants.DeserializeRecognitionPattern(packControl.DebugShowPhrases); + } + + public sealed override Grammar Grammar { get; } + public override string RecognitionPattern { get; } + + public override void DataRefSubscribe() + { + XPlaneInterface.Subscribe("laminar/B738/air/l_pack_pos"); + XPlaneInterface.Subscribe("laminar/B738/air/r_pack_pos"); + } + + public override void OnTrigger(RecognitionResult rResult, string phrase) + { + var stringPackSide = _packUnitsStrings.First(phrase.Contains); + var stringValueToSet = _packStatutesStrings.First(phrase.Contains); + var index = Array.IndexOf(_packStatutesStrings, stringValueToSet); + XPlaneInterface.SetDataRef($"laminar/B738/air/{stringPackSide[0]}_pack_pos", index); + SpeechSynthesizer.SpeakAsync($"{stringPackSide} pack set to {stringValueToSet}"); + } + } +} diff --git a/X-Plane Voice Control/Commands/ProbeHeatControl.cs b/X-Plane Voice Control/Commands/ProbeHeatControl.cs new file mode 100644 index 0000000..5621407 --- /dev/null +++ b/X-Plane Voice Control/Commands/ProbeHeatControl.cs @@ -0,0 +1,56 @@ +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 ProbeHeatControl : ControlTemplate + { + private readonly string[] _taxiLightsOnStrings = { "on" }; + private readonly string[] _taxiLightsOffStrings = { "off" }; + + public ProbeHeatControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) + { + var probeHeatGrammar = new GrammarBuilder(); + probeHeatGrammar.Append("please", 0, 1); + probeHeatGrammar.Append("set", 0, 1); + probeHeatGrammar.Append("probe heat"); + probeHeatGrammar.Append(new Choices(_taxiLightsOnStrings.Concat(_taxiLightsOffStrings).ToArray())); + probeHeatGrammar.Append("please", 0, 1); + Grammar = new Grammar(probeHeatGrammar); + RecognitionPattern = Constants.DeserializeRecognitionPattern(probeHeatGrammar.DebugShowPhrases); + } + + public sealed override Grammar Grammar { get; } + public override string RecognitionPattern { get; } + + public override void DataRefSubscribe() + { + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/capt_probes_pos"); + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/fo_probes_pos"); + } + + public override void OnTrigger(RecognitionResult rResult, string phrase) + { + if (phrase.Contains("on")) + { + XPlaneInterface.SetDataRef("laminar/B738/toggle_switch/capt_probes_pos", 1); + XPlaneInterface.SetDataRef("laminar/B738/toggle_switch/fo_probes_pos", 1); + SpeechSynthesizer.SpeakAsync("Probe heat on"); + } + else if (phrase.Contains("off")) + { + XPlaneInterface.SetDataRef("laminar/B738/toggle_switch/capt_probes_pos", 0); + XPlaneInterface.SetDataRef("laminar/B738/toggle_switch/fo_probes_pos", 0); + SpeechSynthesizer.SpeakAsync("Probe heat off"); + } + } + } +} diff --git a/X-Plane Voice Control/Commands/SmokingAndSeatbeltsControl.cs b/X-Plane Voice Control/Commands/SmokingAndSeatbeltsControl.cs new file mode 100644 index 0000000..e874e29 --- /dev/null +++ b/X-Plane Voice Control/Commands/SmokingAndSeatbeltsControl.cs @@ -0,0 +1,80 @@ +using System; +using System.Linq; +using System.Speech.Recognition; +using System.Speech.Synthesis; +using ExtPlaneNet; + +namespace X_Plane_Voice_Control.Commands +{ + class SmokingAndSeatbeltsControl : ControlTemplate + { + private readonly string[] _controlStateStrings = { "off", "auto", "on" }; + private readonly string[] _controlNamesStrings = { "no smoking", "seatbelts" }; + + public SmokingAndSeatbeltsControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) + { + var passangerControlGrammar = new GrammarBuilder(); + passangerControlGrammar.Append("please", 0, 1); + passangerControlGrammar.Append("set", 0, 1); + passangerControlGrammar.Append(new Choices(_controlNamesStrings)); + passangerControlGrammar.Append(new Choices(_controlStateStrings)); + passangerControlGrammar.Append("please", 0, 1); + Grammar = new Grammar(passangerControlGrammar); + RecognitionPattern = Constants.DeserializeRecognitionPattern(passangerControlGrammar.DebugShowPhrases); + } + + public sealed override Grammar Grammar { get; } + + public override string RecognitionPattern { get; } + + public override void DataRefSubscribe() + { + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/no_smoking_pos"); + XPlaneInterface.Subscribe("laminar/B738/toggle_switch/seatbelt_sign_pos"); + } + + public override void OnTrigger(RecognitionResult rResult, string phrase) + { + var actionString = _controlStateStrings.First(phrase.Contains); + var actionNumber = -1; + switch (actionString) + { + case "off": + actionNumber = 0; + break; + case "auto": + actionNumber = 1; + break; + case "on": + actionNumber = 2; + break; + } + if (phrase.Contains(_controlNamesStrings[0])) + { + XPlaneInterface.SetDataRef("laminar/B738/toggle_switch/no_smoking_pos", actionNumber); + SpeechSynthesizer.SpeakAsync($"No smoking set to {actionString}"); + } + else if (phrase.Contains(_controlNamesStrings[1])) + { + var seatBeltValue = XPlaneInterface.GetDataRef("laminar/B738/toggle_switch/seatbelt_sign_pos"); + int valueToAdd; + var actualValue = Convert.ToInt32(seatBeltValue.Value); + if (seatBeltValue.Value == actionNumber) + return; + else if (seatBeltValue.Value > actionNumber) + valueToAdd = -1; + else + valueToAdd = 1; + + while (actionNumber != actualValue) + { + actualValue += valueToAdd; + XPlaneInterface.SetExecutingCommand(valueToAdd > 0 + ? "laminar/B738/toggle_switch/seatbelt_sign_dn" + : "laminar/B738/toggle_switch/seatbelt_sign_up"); + }; + SpeechSynthesizer.SpeakAsync($"Seatbelts set to {actionString}"); + } + } + } +} diff --git a/X-Plane Voice Control/Commands/TaxiLights.cs b/X-Plane Voice Control/Commands/TaxiLights.cs index 5a43b2e..c75b0c9 100644 --- a/X-Plane Voice Control/Commands/TaxiLights.cs +++ b/X-Plane Voice Control/Commands/TaxiLights.cs @@ -13,18 +13,19 @@ namespace X_Plane_Voice_Control.Commands { class TaxiLights : ControlTemplate { - private readonly string[] _taxiLightsOnStrings = { "taxi lights on" }; - private readonly string[] _taxiLightsOffStrings = { "taxi lights off" }; + private readonly string[] _taxiLightsOnStrings = { "on" }; + private readonly string[] _taxiLightsOffStrings = { "off" }; public TaxiLights(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) { - var brakeGrammar = new GrammarBuilder(); - brakeGrammar.Append("please", 0, 1); - brakeGrammar.Append("set", 0, 1); - brakeGrammar.Append(new Choices(_taxiLightsOnStrings.Concat(_taxiLightsOffStrings).ToArray())); - brakeGrammar.Append("please", 0, 1); - Grammar = new Grammar(brakeGrammar); - RecognitionPattern = Constants.DeserializeRecognitionPattern(brakeGrammar.DebugShowPhrases); + var taxiLightGrammar = new GrammarBuilder(); + taxiLightGrammar.Append("please", 0, 1); + taxiLightGrammar.Append("set", 0, 1); + taxiLightGrammar.Append("taxi lights"); + taxiLightGrammar.Append(new Choices(_taxiLightsOnStrings.Concat(_taxiLightsOffStrings).ToArray())); + taxiLightGrammar.Append("please", 0, 1); + Grammar = new Grammar(taxiLightGrammar); + RecognitionPattern = Constants.DeserializeRecognitionPattern(taxiLightGrammar.DebugShowPhrases); } public sealed override Grammar Grammar { get; } diff --git a/X-Plane Voice Control/Commands/WindowHeatControl.cs b/X-Plane Voice Control/Commands/WindowHeatControl.cs new file mode 100644 index 0000000..aa457a7 --- /dev/null +++ b/X-Plane Voice Control/Commands/WindowHeatControl.cs @@ -0,0 +1,62 @@ +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 WindowHeatControl : ControlTemplate + { + private readonly string[] _taxiLightsOnStrings = { "on" }; + private readonly string[] _taxiLightsOffStrings = { "off" }; + + public WindowHeatControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) + { + var windowHeat = new GrammarBuilder(); + windowHeat.Append("please", 0, 1); + windowHeat.Append("set", 0, 1); + windowHeat.Append("window heat"); + windowHeat.Append(new Choices(_taxiLightsOnStrings.Concat(_taxiLightsOffStrings).ToArray())); + windowHeat.Append("please", 0, 1); + Grammar = new Grammar(windowHeat); + RecognitionPattern = Constants.DeserializeRecognitionPattern(windowHeat.DebugShowPhrases); + } + + public sealed override Grammar Grammar { get; } + public override string RecognitionPattern { get; } + + public override void DataRefSubscribe() + { + XPlaneInterface.Subscribe("laminar/B738/ice/window_heat_l_fwd_pos"); + XPlaneInterface.Subscribe("laminar/B738/ice/window_heat_l_side_pos"); + XPlaneInterface.Subscribe("laminar/B738/ice/window_heat_r_fwd_pos"); + XPlaneInterface.Subscribe("laminar/B738/ice/window_heat_r_side_pos"); + } + + public override void OnTrigger(RecognitionResult rResult, string phrase) + { + if (phrase.Contains("on")) + { + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_l_fwd_pos", 1); + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_l_side_pos", 1); + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_r_fwd_pos", 1); + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_r_side_pos", 1); + SpeechSynthesizer.SpeakAsync("Window heat on"); + } + else if (phrase.Contains("off")) + { + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_l_fwd_pos", 0); + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_l_side_pos", 0); + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_r_fwd_pos", 0); + XPlaneInterface.SetDataRef("laminar/B738/ice/window_heat_r_side_pos", 0); + SpeechSynthesizer.SpeakAsync("Window heat off"); + } + } + } +} diff --git a/X-Plane Voice Control/X-Plane Voice Control.csproj b/X-Plane Voice Control/X-Plane Voice Control.csproj index 6ab9e77..7a20048 100644 --- a/X-Plane Voice Control/X-Plane Voice Control.csproj +++ b/X-Plane Voice Control/X-Plane Voice Control.csproj @@ -52,12 +52,17 @@ + + + + +