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 24, 2018
1 parent
87a58a2
commit 2492f3b
Showing
13 changed files
with
649 additions
and
9 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,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); | ||
}); | ||
} | ||
} | ||
} |
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,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"); | ||
} | ||
|
||
} | ||
} |
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,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); | ||
}); | ||
} | ||
} | ||
} |
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,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); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.