Skip to content

Commit

Permalink
Add Airspeed mode for +/- button
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenquyhy committed Oct 19, 2020
1 parent 70f56a7 commit d4e1465
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
2 changes: 2 additions & 0 deletions FlightStreamDeck.AddOn/PropertyInspector/PresetChange.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<option value="Heading">Heading</option>
<option value="Altitude">Altitude</option>
<option value="VerticalSpeed">Vertical Speed</option>
<option value="AirSpeed">Air Speed</option>
<option value="VerticalSpeedAirSpeed">Vertical Speed/Air Speed</option>
</select>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
namespace FlightStreamDeck.Logics.Actions
{
#region Action Registration

[StreamDeckAction("tech.flighttracker.streamdeck.preset.increase")]
public class ValueIncreaseAction : ValueChangeAction
public class ValueIncreaseAction : PresetChangeAction
{
public ValueIncreaseAction(ILogger<ValueIncreaseAction> logger, IFlightConnector flightConnector)
: base(logger, flightConnector) { }
}
[StreamDeckAction("tech.flighttracker.streamdeck.preset.decrease")]
public class ValueDecreaseAction : ValueChangeAction
public class ValueDecreaseAction : PresetChangeAction
{
public ValueDecreaseAction(ILogger<ValueDecreaseAction> logger, IFlightConnector flightConnector)
: base(logger, flightConnector) { }
Expand All @@ -31,14 +31,16 @@ public class ValueChangeFunction
public const string Heading = "Heading";
public const string Altitude = "Altitude";
public const string VerticalSpeed = "VerticalSpeed";
public const string AirSpeed = "AirSpeed";
public const string VerticalSpeedAirSpeed = "VerticalSpeedAirSpeed";
}

public class ValueChangeSettings
{
public string Type { get; set; }
}

public abstract class ValueChangeAction : StreamDeckAction
public abstract class PresetChangeAction : StreamDeckAction
{
private readonly ILogger logger;
private readonly IFlightConnector flightConnector;
Expand All @@ -50,7 +52,7 @@ public abstract class ValueChangeAction : StreamDeckAction
private AircraftStatus status;
private ValueChangeSettings settings;

public ValueChangeAction(ILogger logger, IFlightConnector flightConnector)
public PresetChangeAction(ILogger logger, IFlightConnector flightConnector)
{
this.logger = logger;
this.flightConnector = flightConnector;
Expand All @@ -75,7 +77,7 @@ private void Process(bool isUp)
{
return;
}

var change = actions[^1];
var sign = change == "increase" ? 1 : -1;
var increment = isUp ? 1 : 10;
Expand All @@ -91,6 +93,8 @@ private void Process(bool isUp)
ValueChangeFunction.Heading => (uint)status.ApHeading,
ValueChangeFunction.Altitude => (uint)status.ApAltitude,
ValueChangeFunction.VerticalSpeed => (uint)status.ApVs,
ValueChangeFunction.AirSpeed => (uint)status.IndicatedAirSpeed,
ValueChangeFunction.VerticalSpeedAirSpeed => status.IsApFlcOn ? (uint)status.IndicatedAirSpeed : (uint)status.ApVs,
_ => throw new NotImplementedException($"Value type: {buttonType}")
};

Expand All @@ -107,9 +111,24 @@ private void Process(bool isUp)
break;

case ValueChangeFunction.VerticalSpeed:
originalValue = (uint)(originalValue + 100 * sign);
flightConnector.ApVsSet(originalValue.Value);
ChangeVerticalSpeed(sign);
break;

case ValueChangeFunction.AirSpeed:
ChangeAirSpeed(sign);
break;

case ValueChangeFunction.VerticalSpeedAirSpeed:
if (status.IsApFlcOn)
{
ChangeAirSpeed(sign);
}
else
{
ChangeVerticalSpeed(sign);
}
break;

}
}

Expand Down Expand Up @@ -157,5 +176,23 @@ protected override Task OnSendToPlugin(ActionEventArgs<JObject> args)
this.settings = args.Payload.ToObject<ValueChangeSettings>();
return Task.CompletedTask;
}

private void ChangeVerticalSpeed(int sign)
{
originalValue = (uint)(originalValue + 100 * sign);
flightConnector.ApVsSet(originalValue.Value);
}

private void ChangeAirSpeed(int sign)
{
if (sign == 1)
{
flightConnector.ApAirSpeedInc();
}
else
{
flightConnector.ApAirSpeedDec();
}
}
}
}
4 changes: 2 additions & 2 deletions FlightStreamDeck.Logics/Actions/PresetToggleAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private async void FlightConnector_AircraftStatusUpdated(object sender, Aircraft
}
break;
case PresetFunction.FLC:
if (e.AircraftStatus.IsApFlcOn != lastStatus?.IsApFlcOn)
if (e.AircraftStatus.ApAirspeed != lastStatus?.ApAirspeed || e.AircraftStatus.IsApFlcOn != lastStatus?.IsApFlcOn)
{
logger.LogInformation("Received FLC update: {IsApFlcOn}", e.AircraftStatus.IsApFlcOn);
await UpdateImage();
Expand Down Expand Up @@ -216,7 +216,7 @@ protected override Task OnKeyUp(ActionEventArgs<KeyPayload> args)
}
else
{
flightConnector.ApAirspeedSet((uint)Math.Round(currentStatus.IndicatedAirSpeed));
flightConnector.ApAirSpeedSet((uint)Math.Round(currentStatus.IndicatedAirSpeed));
flightConnector.ApFlcOn();
}
break;
Expand Down
4 changes: 3 additions & 1 deletion FlightStreamDeck.Logics/IFlightConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public interface IFlightConnector
/// <param name="speed">In Feet per min</param>
void ApVsSet(uint speed);

void ApAirspeedSet(uint speed);
void ApAirSpeedSet(uint speed);
void ApAirSpeedInc();
void ApAirSpeedDec();

void AvMasterToggle(uint state);

Expand Down
14 changes: 13 additions & 1 deletion FlightStreamDeck.SimConnectFSX/SimConnectFlightConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public void Initialize(IntPtr Handle)
simconnect.MapClientEventToSimEvent(EVENTS.AP_VS_DEC, "AP_VS_VAR_DEC");

simconnect.MapClientEventToSimEvent(EVENTS.AP_AIRSPEED_SET, "AP_SPD_VAR_SET");
simconnect.MapClientEventToSimEvent(EVENTS.AP_AIRSPEED_INC, "AP_SPD_VAR_INC");
simconnect.MapClientEventToSimEvent(EVENTS.AP_AIRSPEED_DEC, "AP_SPD_VAR_DEC");

simconnect.MapClientEventToSimEvent(EVENTS.AVIONICS_TOGGLE, "AVIONICS_MASTER_SET");

Expand Down Expand Up @@ -219,11 +221,21 @@ public void ApVsSet(uint speed)
SendCommand(EVENTS.AP_VS_SET, speed);
}

public void ApAirspeedSet(uint speed)
public void ApAirSpeedSet(uint speed)
{
SendCommand(EVENTS.AP_AIRSPEED_SET, speed);
}

public void ApAirSpeedInc()
{
SendCommand(EVENTS.AP_AIRSPEED_INC);
}

public void ApAirSpeedDec()
{
SendCommand(EVENTS.AP_AIRSPEED_DEC);
}

public void AvMasterToggle(uint state)
{
SendCommand(EVENTS.AVIONICS_TOGGLE, state);
Expand Down
2 changes: 2 additions & 0 deletions FlightStreamDeck.SimConnectFSX/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public enum EVENTS
AP_VS_INC,
AP_VS_DEC,
AP_AIRSPEED_SET,
AP_AIRSPEED_INC,
AP_AIRSPEED_DEC,
AVIONICS_TOGGLE
}

Expand Down

0 comments on commit d4e1465

Please sign in to comment.