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.
"logo", "position", "beacon", "wing", "wheel" lights added
David
committed
Jun 22, 2018
1 parent
47b89fc
commit 2ec5b74
Showing
2 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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 LightsControl : ControlTemplate | ||
{ | ||
private readonly string[] _lightStatusesStrings = { "off", "on" }; | ||
private readonly string[] _lightTypeStrings = { "logo", "position", "beacon", "wing", "wheel" }; | ||
public LightsControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) | ||
{ | ||
var lightsControl = new GrammarBuilder(); | ||
lightsControl.Append("please", 0, 1); | ||
lightsControl.Append("set", 0, 1); | ||
lightsControl.Append(new Choices(_lightTypeStrings)); | ||
lightsControl.Append("lights"); | ||
lightsControl.Append("to", 0, 1); | ||
lightsControl.Append(new Choices(_lightStatusesStrings)); | ||
lightsControl.Append("please", 0, 1); | ||
Grammar = new Grammar(lightsControl); | ||
RecognitionPattern = Constants.DeserializeRecognitionPattern(lightsControl.DebugShowPhrases); | ||
} | ||
|
||
public sealed override Grammar Grammar { get; } | ||
public override string RecognitionPattern { get; } | ||
|
||
public override void DataRefSubscribe() | ||
{ | ||
} | ||
|
||
public override void OnTrigger(RecognitionResult rResult, string phrase) | ||
{ | ||
var lightToSwitch = _lightTypeStrings.First(phrase.Contains); | ||
var valueToSet = _lightStatusesStrings.First(phrase.Contains); | ||
|
||
if (lightToSwitch == _lightTypeStrings[1]) | ||
{ | ||
if (valueToSet.Equals("off", StringComparison.CurrentCultureIgnoreCase)) | ||
{ | ||
XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); | ||
XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); | ||
XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_down"); | ||
} | ||
else | ||
{ | ||
XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); | ||
XPlaneInterface.SetExecutingCommand("laminar/B738/toggle_switch/position_light_up"); | ||
} | ||
} | ||
else if (lightToSwitch == _lightTypeStrings[2]) | ||
{ | ||
XPlaneInterface.SetExecutingCommand($"sim/lights/beacon_lights_{valueToSet}"); | ||
} | ||
else | ||
{ | ||
XPlaneInterface.SetExecutingCommand($"laminar/B738/switch/{lightToSwitch}_light_{valueToSet}"); | ||
} | ||
SpeechSynthesizer.SpeakAsync($"{lightToSwitch} lights turned {valueToSet}"); | ||
} | ||
} | ||
} |
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