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 23, 2018
1 parent
e3811a3
commit 39e23d6
Showing
8 changed files
with
210 additions
and
8 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,80 @@ | ||
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 HeadingMCPControl : ControlTemplate | ||
{ | ||
|
||
public HeadingMCPControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) | ||
{ | ||
var headingGrammar = new GrammarBuilder(); | ||
headingGrammar.Append("please", 0, 1); | ||
headingGrammar.Append("set", 0, 1); | ||
headingGrammar.Append("heading"); | ||
headingGrammar.Append("to", 0, 1); | ||
headingGrammar.Append(Constants.NumberChoices, 3, 3); | ||
headingGrammar.Append("please", 0, 1); | ||
Grammar = new Grammar(headingGrammar); | ||
RecognitionPattern = Constants.DeserializeRecognitionPattern(headingGrammar.DebugShowPhrases); | ||
} | ||
public sealed override Grammar Grammar { get; } | ||
public override string RecognitionPattern { get; } | ||
|
||
public override void DataRefSubscribe() | ||
{ | ||
XPlaneInterface.Subscribe<double>("laminar/B738/autopilot/mcp_hdg_dial"); | ||
} | ||
|
||
public override void OnTrigger(RecognitionResult rResult, string phrase) | ||
{ | ||
var presentHeading = (int)XPlaneInterface.GetDataRef<double>("laminar/B738/autopilot/mcp_hdg_dial").Value; | ||
var stringHeading = Constants.StringNumbersToDigits(phrase); | ||
stringHeading = stringHeading.Substring(stringHeading.Length - 5, 5); | ||
var requestedHeading = int.Parse(stringHeading.Replace(" ", "")); | ||
if (requestedHeading > 360) | ||
{ | ||
SpeechSynthesizer.SpeakAsync("Cannot set heading bigger than 360"); | ||
return; | ||
} | ||
|
||
if (requestedHeading == 360) | ||
requestedHeading = 0; | ||
|
||
int wayToRotate; | ||
if (presentHeading < requestedHeading) | ||
{ | ||
var x = requestedHeading - presentHeading; | ||
var y = presentHeading + (360 - requestedHeading); | ||
wayToRotate = x <= y ? 1 : -1; | ||
} | ||
else | ||
{ | ||
var x = (360 - presentHeading) + requestedHeading; | ||
var y = presentHeading - requestedHeading; | ||
wayToRotate = x <= y ? 1 : -1; | ||
} | ||
|
||
Task.Run(() => | ||
{ | ||
while (presentHeading != requestedHeading) | ||
{ | ||
presentHeading += wayToRotate; | ||
if (presentHeading == 360) | ||
presentHeading = 0; | ||
if (presentHeading == -1) | ||
presentHeading = 359; | ||
XPlaneInterface.SetDataRef("laminar/B738/autopilot/mcp_hdg_dial", presentHeading); | ||
Thread.Sleep(2); | ||
} | ||
}); | ||
SpeechSynthesizer.SpeakAsync($"Setting heading to {stringHeading}"); | ||
} | ||
|
||
} | ||
} |
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,88 @@ | ||
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 VerticalSpeedMCPControl : ControlTemplate | ||
{ | ||
|
||
public VerticalSpeedMCPControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) | ||
{ | ||
var headingGrammar = new GrammarBuilder(); | ||
|
||
var thousandGrammar = new GrammarBuilder(); | ||
thousandGrammar.Append(Constants.VerticalSpeedNumberChoices); | ||
thousandGrammar.Append("thousand"); | ||
|
||
var hundredGrammar = new GrammarBuilder(); | ||
hundredGrammar.Append(Constants.ClassicNumberChoices); | ||
hundredGrammar.Append("hundred"); | ||
|
||
var altitudeGrammar = new GrammarBuilder(); | ||
altitudeGrammar.Append(thousandGrammar, 0, 1); | ||
altitudeGrammar.Append(hundredGrammar, 0, 1); | ||
headingGrammar.Append("please", 0, 1); | ||
headingGrammar.Append("set", 0, 1); | ||
headingGrammar.Append("vertical speed"); | ||
headingGrammar.Append("to", 0, 1); | ||
headingGrammar.Append("negative", 0, 1); | ||
headingGrammar.Append(altitudeGrammar); | ||
headingGrammar.Append("fifty", 0, 1); | ||
headingGrammar.Append(new Choices("fpm", "feet per minute", "feet"), 0, 1); | ||
headingGrammar.Append("please", 0, 1); | ||
Grammar = new Grammar(headingGrammar); | ||
RecognitionPattern = Constants.DeserializeRecognitionPattern(headingGrammar.DebugShowPhrases); | ||
} | ||
public sealed override Grammar Grammar { get; } | ||
public override string RecognitionPattern { get; } | ||
|
||
public override void DataRefSubscribe() | ||
{ | ||
XPlaneInterface.Subscribe<float>("sim/cockpit/autopilot/vertical_velocity"); | ||
} | ||
|
||
public override void OnTrigger(RecognitionResult rResult, string phrase) | ||
{ | ||
var stringHeading = Constants.StringNumbersToDigits(phrase); | ||
try | ||
{ | ||
var startingIndexNumber = Constants.NumbersInDigits.First(stringHeading.Contains); | ||
var startingIndex = stringHeading.IndexOf(startingIndexNumber, StringComparison.Ordinal); | ||
stringHeading = stringHeading.Substring(startingIndex, stringHeading.Length - startingIndex); | ||
} | ||
catch { } | ||
|
||
var splittedString = stringHeading.Split(' '); | ||
float verticalSpeedToSet = 0; | ||
for (var i = 0; i < splittedString.Length; i += 2) | ||
{ | ||
var nextIndex = i + 1; | ||
if (nextIndex > splittedString.Length - 1) | ||
break; | ||
if (splittedString[i + 1] == "thousand") | ||
{ | ||
verticalSpeedToSet += int.Parse(splittedString[i]) * 1000; | ||
} | ||
if (splittedString[i + 1] == "hundred") | ||
{ | ||
verticalSpeedToSet += int.Parse(splittedString[i]) * 100; | ||
} | ||
} | ||
|
||
if (phrase.Contains("fifty") && verticalSpeedToSet < 1000 && verticalSpeedToSet > -1000) | ||
verticalSpeedToSet += 50; | ||
|
||
if (phrase.Contains("negative")) | ||
verticalSpeedToSet *= -1; | ||
XPlaneInterface.SetDataRef("sim/cockpit/autopilot/vertical_velocity", verticalSpeedToSet); | ||
|
||
|
||
} | ||
|
||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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