This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David
committed
Jun 20, 2018
1 parent
b7a094e
commit dca7d5d
Showing
8 changed files
with
330 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
80
X-Plane Voice Control/Commands/SmokingAndSeatbeltsControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters