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

Commit

Permalink
Added support for lights
Browse files Browse the repository at this point in the history
"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.
69 changes: 69 additions & 0 deletions X-Plane Voice Control/Commands/LightsControl.cs
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}");
}
}
}
1 change: 1 addition & 0 deletions X-Plane Voice Control/X-Plane Voice Control.csproj
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\BusPowerControl.cs" />
<Compile Include="Commands\LightsControl.cs" />
<Compile Include="Commands\PackControl.cs" />
<Compile Include="Commands\ComSwapControl.cs" />
<Compile Include="Commands\EngineFuelControl.cs" />

0 comments on commit 2ec5b74

Please sign in to comment.