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

Commit

Permalink
Added series of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Jun 24, 2018
1 parent 87a58a2 commit 2492f3b
Show file tree
Hide file tree
Showing 13 changed files with 649 additions and 9 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,25 @@ Latest build: [![Build status](https://ci.appveyor.com/api/projects/status/ejvcv
* Vertical speed set
* set __vertical speed__ to negative V thousand /& X hundred [fifty] [fpm / feet per minute / feet]
* __eg: set vertical speed to six thousand five hundred fifty; set vertical speed to six hundred; set vertical speed fifty__

* Altitude set
* set __altitude__ to XX thousand XX hundred feet
* set __altitude__ to __FL XXX__
* Vertical speed button
* __[select] / [de-select / toggle] vertical speed__ mode
* Approach button
* __[select] / [de-select / toggle] approach__ mode
* Altitude hold
* __[select] / [de-select] / toggle] altitude hold__ mode
* Localizer
* __[select] / [de-select] / toggle] localizer__ mode
* N1
* __[select] / [de-select] / toggle] n1__ mode
* Speed
* __[select] / [de-select] / toggle] speed__ mode
* Level change
* __[select] / [de-select] / toggle] level change__
* Heading select
* __[select / egnage / turn on / de-select / disengage / turn off / toggle] heading select__

__Cheat sheet:__
* __Bold text is Mandatory__
Expand All @@ -92,7 +110,7 @@ __Cheat sheet:__
* __T => [zero / one / two / three / four / fiver / six / seven]__
* __V => [zero / one / two / three / four / five / six]__

## Hard time speaking - train Windows to understand you better?
## Hard time speaking - train Windows to understand you better!
* Open Speech Recognition by clicking the Start button, clicking Control Panel, clicking Ease of Access, and then clicking Speech Recognition.
* Click “Train your computer to better understand you.”
* Follow the instructions on the screen.
Expand Down
71 changes: 71 additions & 0 deletions X-Plane Voice Control/Commands/AltitudeHoldControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Threading.Tasks;
using ExtPlaneNet;
using ExtPlaneNet.Commands;

namespace X_Plane_Voice_Control.Commands
{
class AltitudeHoldControl : ControlTemplate
{
private readonly string[] _lnavOnStrings = { "select" };
private readonly string[] _lnavOffStrings = { "de-select" };
public AltitudeHoldControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer)
{
var lnavGrammar = new GrammarBuilder();
var lnavGrammarOn = new GrammarBuilder();
lnavGrammarOn.Append(new Choices(_lnavOnStrings));
var lnavGrammarOff = new GrammarBuilder();
lnavGrammarOff.Append(new Choices(_lnavOffStrings));
lnavGrammar.Append(new Choices(lnavGrammarOn, lnavGrammarOff, "toggle"));
lnavGrammar.Append("altitude hold");
lnavGrammar.Append("mode", 0, 1);
Grammar = new Grammar(lnavGrammar);
RecognitionPattern = Constants.DeserializeRecognitionPattern(lnavGrammar.DebugShowPhrases);
}

public sealed override Grammar Grammar { get; }
public override string RecognitionPattern { get; }

public override void DataRefSubscribe()
{
XPlaneInterface.Subscribe<double>("laminar/B738/autopilot/alt_hld_status");
}

public override void OnTrigger(RecognitionResult rResult, string phrase)
{
if (phrase.Contains("toggle"))
{
PressButton();
SpeechSynthesizer.SpeakAsync("altitude hold toggled");
return;
}

var turnOn = !_lnavOffStrings.Any(phrase.Contains);
var lnavStatus = (int)XPlaneInterface.GetDataRef<double>("laminar/B738/autopilot/alt_hld_status").Value;
if (turnOn && lnavStatus == 0)
{
PressButton();
SpeechSynthesizer.SpeakAsync("altitude hold engaged");
}
else if (!turnOn && lnavStatus == 1)
{
PressButton();
SpeechSynthesizer.SpeakAsync("altitude hold disengaged");
}
}

private void PressButton()
{
Task.Run(() =>
{
XPlaneInterface.SetExecutingCommand("laminar/B738/autopilot/alt_hld_press", Command.CommandType.Begin);
Thread.Sleep(Constants.PushButtonReleaseDelay);
XPlaneInterface.SetExecutingCommand("laminar/B738/autopilot/alt_hld_press", Command.CommandType.End);
});
}
}
}
109 changes: 109 additions & 0 deletions X-Plane Voice Control/Commands/AltitudeMcpControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Threading.Tasks;
using ExtPlaneNet;

namespace X_Plane_Voice_Control.Commands
{
class AltitudeMcpControl : ControlTemplate
{

public AltitudeMcpControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer)
{
var mainAltitudeGrammar = new GrammarBuilder();

var thousandGrammar = new GrammarBuilder();
thousandGrammar.Append(Constants.AltitudeNumberChoices);
thousandGrammar.Append("thousand");

var hundredGrammar = new GrammarBuilder();
hundredGrammar.Append(Constants.ClassicNumberChoices);
hundredGrammar.Append("hundred");

var flGrammar = new GrammarBuilder();
flGrammar.Append("flight level");
flGrammar.Append(Constants.ClassicNumberChoices, 1, 3);



var altitudeGrammar = new GrammarBuilder();
altitudeGrammar.Append(thousandGrammar, 0, 1);
altitudeGrammar.Append(hundredGrammar, 0, 1);
altitudeGrammar.Append("feet", 0, 1);
mainAltitudeGrammar.Append("please", 0, 1);
mainAltitudeGrammar.Append("set", 0, 1);
mainAltitudeGrammar.Append("altitude");
mainAltitudeGrammar.Append("to", 0, 1);
mainAltitudeGrammar.Append(new Choices(altitudeGrammar, flGrammar));
mainAltitudeGrammar.Append("please", 0, 1);
Grammar = new Grammar(mainAltitudeGrammar);
RecognitionPattern = Constants.DeserializeRecognitionPattern(mainAltitudeGrammar.DebugShowPhrases);
}
public sealed override Grammar Grammar { get; }
public override string RecognitionPattern { get; }

public override void DataRefSubscribe()
{
XPlaneInterface.Subscribe<float>("sim/cockpit/autopilot/altitude");
}

public override void OnTrigger(RecognitionResult rResult, string phrase)
{
var currentAltitude = (int)XPlaneInterface.GetDataRef<float>("sim/cockpit/autopilot/altitude").Value;
var altitudeToSet = 0;
if (phrase.Contains("flight level"))
{
var flString = phrase.Split(new[]
{
"flight level "
}, StringSplitOptions.RemoveEmptyEntries)[1];

altitudeToSet = int.Parse(Constants.StringNumbersToDigits(flString).Replace(" ", "")) * 100;
}
var strinAltitude = Constants.StringNumbersToDigits(phrase);
try
{
var startingIndexNumber = Constants.NumbersInDigits40.First(strinAltitude.Contains);
var startingIndex = strinAltitude.IndexOf(startingIndexNumber, StringComparison.Ordinal);
strinAltitude = strinAltitude.Substring(startingIndex, strinAltitude.Length - startingIndex);
}
catch
{
// ignored
}

var splittedString = strinAltitude.Split(' ');
for (var i = 0; i < splittedString.Length; i += 2)
{
var nextIndex = i + 1;
if (nextIndex > splittedString.Length - 1)
break;
if (splittedString[i + 1] == "thousand")
{
altitudeToSet += int.Parse(splittedString[i]) * 1000;
}
if (splittedString[i + 1] == "hundred")
{
altitudeToSet += int.Parse(splittedString[i]) * 100;
}
}

var buttonCommand = currentAltitude > altitudeToSet ? "laminar/B738/autopilot/altitude_dn" : "laminar/B738/autopilot/altitude_up";
var rotation = currentAltitude > altitudeToSet ? -100 : 100;
Task.Run(() =>
{
while (currentAltitude != altitudeToSet)
{
currentAltitude += rotation;
XPlaneInterface.SetExecutingCommand(buttonCommand);
Thread.Sleep(20);
}
});
SpeechSynthesizer.SpeakAsync($"Setting altitude to {altitudeToSet} feet");
}

}
}
71 changes: 71 additions & 0 deletions X-Plane Voice Control/Commands/ApproachControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Threading.Tasks;
using ExtPlaneNet;
using ExtPlaneNet.Commands;

namespace X_Plane_Voice_Control.Commands
{
class ApproachControl : ControlTemplate
{
private readonly string[] _lnavOnStrings = { "select" };
private readonly string[] _lnavOffStrings = { "de-select" };
public ApproachControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer)
{
var lnavGrammar = new GrammarBuilder();
var lnavGrammarOn = new GrammarBuilder();
lnavGrammarOn.Append(new Choices(_lnavOnStrings));
var lnavGrammarOff = new GrammarBuilder();
lnavGrammarOff.Append(new Choices(_lnavOffStrings));
lnavGrammar.Append(new Choices(lnavGrammarOn, lnavGrammarOff, "toggle"));
lnavGrammar.Append("approach");
lnavGrammar.Append("mode", 0, 1);
Grammar = new Grammar(lnavGrammar);
RecognitionPattern = Constants.DeserializeRecognitionPattern(lnavGrammar.DebugShowPhrases);
}

public sealed override Grammar Grammar { get; }
public override string RecognitionPattern { get; }

public override void DataRefSubscribe()
{
XPlaneInterface.Subscribe<double>("laminar/B738/autopilot/app_status");
}

public override void OnTrigger(RecognitionResult rResult, string phrase)
{
if (phrase.Contains("toggle"))
{
PressButton();
SpeechSynthesizer.SpeakAsync("approach toggled");
return;
}

var turnOn = !_lnavOffStrings.Any(phrase.Contains);
var lnavStatus = (int)XPlaneInterface.GetDataRef<double>("laminar/B738/autopilot/app_status").Value;
if (turnOn && lnavStatus == 0)
{
PressButton();
SpeechSynthesizer.SpeakAsync("approach engaged");
}
else if (!turnOn && lnavStatus == 1)
{
PressButton();
SpeechSynthesizer.SpeakAsync("approach disengaged");
}
}

private void PressButton()
{
Task.Run(() =>
{
XPlaneInterface.SetExecutingCommand("laminar/B738/autopilot/app_press", Command.CommandType.Begin);
Thread.Sleep(Constants.PushButtonReleaseDelay);
XPlaneInterface.SetExecutingCommand("laminar/B738/autopilot/app_press", Command.CommandType.End);
});
}
}
}
71 changes: 71 additions & 0 deletions X-Plane Voice Control/Commands/LocalizerControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Threading.Tasks;
using ExtPlaneNet;
using ExtPlaneNet.Commands;

namespace X_Plane_Voice_Control.Commands
{
class LocalizerControl : ControlTemplate
{
private readonly string[] _lnavOnStrings = { "select" };
private readonly string[] _lnavOffStrings = { "de-select" };
public LocalizerControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer)
{
var lnavGrammar = new GrammarBuilder();
var lnavGrammarOn = new GrammarBuilder();
lnavGrammarOn.Append(new Choices(_lnavOnStrings));
var lnavGrammarOff = new GrammarBuilder();
lnavGrammarOff.Append(new Choices(_lnavOffStrings));
lnavGrammar.Append(new Choices(lnavGrammarOn, lnavGrammarOff, "toggle"));
lnavGrammar.Append("localizer");
lnavGrammar.Append("mode", 0, 1);
Grammar = new Grammar(lnavGrammar);
RecognitionPattern = Constants.DeserializeRecognitionPattern(lnavGrammar.DebugShowPhrases);
}

public sealed override Grammar Grammar { get; }
public override string RecognitionPattern { get; }

public override void DataRefSubscribe()
{
XPlaneInterface.Subscribe<double>("laminar/B738/autopilot/vorloc_status");
}

public override void OnTrigger(RecognitionResult rResult, string phrase)
{
if (phrase.Contains("toggle"))
{
PressButton();
SpeechSynthesizer.SpeakAsync("localizer toggled");
return;
}

var turnOn = !_lnavOffStrings.Any(phrase.Contains);
var lnavStatus = (int)XPlaneInterface.GetDataRef<double>("laminar/B738/autopilot/vorloc_status").Value;
if (turnOn && lnavStatus == 0)
{
PressButton();
SpeechSynthesizer.SpeakAsync("localizer engaged");
}
else if (!turnOn && lnavStatus == 1)
{
PressButton();
SpeechSynthesizer.SpeakAsync("localizer disengaged");
}
}

private void PressButton()
{
Task.Run(() =>
{
XPlaneInterface.SetExecutingCommand("laminar/B738/autopilot/vorloc_press", Command.CommandType.Begin);
Thread.Sleep(Constants.PushButtonReleaseDelay);
XPlaneInterface.SetExecutingCommand("laminar/B738/autopilot/vorloc_press", Command.CommandType.End);
});
}
}
}
Loading

0 comments on commit 2492f3b

Please sign in to comment.