Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
Upda to V0.03
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Jun 20, 2018
1 parent b7a094e commit dca7d5d
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 10 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
56 changes: 56 additions & 0 deletions X-Plane Voice Control/Commands/AirBleedControl.cs
Original file line number Diff line number Diff line change
@@ -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<int>("laminar/B738/toggle_switch/bleed_air_1_pos");
XPlaneInterface.Subscribe<int>("laminar/B738/toggle_switch/bleed_air_2_pos");
XPlaneInterface.Subscribe<int>("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}");
}
}
}
50 changes: 50 additions & 0 deletions X-Plane Voice Control/Commands/PackControl.cs
Original file line number Diff line number Diff line change
@@ -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<int>("laminar/B738/air/l_pack_pos");
XPlaneInterface.Subscribe<int>("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}");
}
}
}
56 changes: 56 additions & 0 deletions X-Plane Voice Control/Commands/ProbeHeatControl.cs
Original file line number Diff line number Diff line change
@@ -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<double>("laminar/B738/toggle_switch/capt_probes_pos");
XPlaneInterface.Subscribe<double>("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");
}
}
}
}
80 changes: 80 additions & 0 deletions X-Plane Voice Control/Commands/SmokingAndSeatbeltsControl.cs
Original file line number Diff line number Diff line change
@@ -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<double>("laminar/B738/toggle_switch/no_smoking_pos");
XPlaneInterface.Subscribe<double>("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<double>("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}");
}
}
}
}
19 changes: 10 additions & 9 deletions X-Plane Voice Control/Commands/TaxiLights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
62 changes: 62 additions & 0 deletions X-Plane Voice Control/Commands/WindowHeatControl.cs
Original file line number Diff line number Diff line change
@@ -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<double>("laminar/B738/ice/window_heat_l_fwd_pos");
XPlaneInterface.Subscribe<double>("laminar/B738/ice/window_heat_l_side_pos");
XPlaneInterface.Subscribe<double>("laminar/B738/ice/window_heat_r_fwd_pos");
XPlaneInterface.Subscribe<double>("laminar/B738/ice/window_heat_r_side_pos");
}

public override void OnTrigger(RecognitionResult rResult, string phrase)
{
if (phrase.Contains("on"))
{
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_l_fwd_pos", 1);
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_l_side_pos", 1);
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_r_fwd_pos", 1);
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_r_side_pos", 1);
SpeechSynthesizer.SpeakAsync("Window heat on");
}
else if (phrase.Contains("off"))
{
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_l_fwd_pos", 0);
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_l_side_pos", 0);
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_r_fwd_pos", 0);
XPlaneInterface.SetDataRef<double>("laminar/B738/ice/window_heat_r_side_pos", 0);
SpeechSynthesizer.SpeakAsync("Window heat off");
}
}
}
}
5 changes: 5 additions & 0 deletions X-Plane Voice Control/X-Plane Voice Control.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\PackControl.cs" />
<Compile Include="Commands\ComSwapControl.cs" />
<Compile Include="Commands\EngineFuelControl.cs" />
<Compile Include="Commands\FlapControl.cs" />
<Compile Include="Commands\LandingLights.cs" />
<Compile Include="Commands\EngineStartUp.cs" />
<Compile Include="Commands\ApuControl.cs" />
<Compile Include="Commands\SmokingAndSeatbeltsControl.cs" />
<Compile Include="Commands\AirBleedControl.cs" />
<Compile Include="Commands\WindowHeatControl.cs" />
<Compile Include="Commands\ProbeHeatControl.cs" />
<Compile Include="Commands\TaxiLights.cs" />
<Compile Include="Commands\GearControl.cs" />
<Compile Include="Commands\ControlTemplate.cs" />
Expand Down

0 comments on commit dca7d5d

Please sign in to comment.