Skip to content

Commit

Permalink
Support Winwing FCU Firmware v1.16 (#1791)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koseng authored Jun 18, 2024
1 parent 467cc37 commit 5de2ac5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
17 changes: 13 additions & 4 deletions MobiFlight/Joysticks/WinwingFcu/WinwingFcu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,22 @@ public async override void Connect(IntPtr handle)
Device = (IHidDevice)await hidFactory.GetDeviceAsync(deviceDefinitions.First()).ConfigureAwait(false);
await Device.InitializeAsync().ConfigureAwait(false);
DoReadHidReports = true;
DisplayControl.SendRequestFirmware();

await Task.Run(async () =>
{
while (DoReadHidReports)
{
HidDataBuffer.HidReport = await Device.ReadReportAsync().ConfigureAwait(false);
InputReportReceived(HidDataBuffer);
{
try
{
HidDataBuffer.HidReport = await Device.ReadReportAsync().ConfigureAwait(false);
InputReportReceived(HidDataBuffer);
}
catch
{
// Exception when disconnecting fcu while mobiflight is running.
Shutdown();
}
}
});
}
Expand All @@ -113,7 +122,7 @@ protected override void EnumerateDevices()
{
EncoderButtonsToTrigger[input.Id] = device;
}
Log.Instance.log($"Added WINGWING FCU Id: {input.Id} Axis: {input.Name} Label: {input.Label}.", LogSeverity.Debug);
Log.Instance.log($"Added WINWING FCU Id: {input.Id} Axis: {input.Name} Label: {input.Label}.", LogSeverity.Debug);
}
}

Expand Down
39 changes: 32 additions & 7 deletions MobiFlight/Joysticks/WinwingFcu/WinwingFcuReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,54 @@ internal class WinwingFcuReport
public ushort VsEncoderValue { get; set; }

private const uint BUTTONS_REPORT = 1;

private const uint DEVICE_REPORT = 2;
private bool IsFirmwareGreaterOrEqual_1_16 = true;

public void CopyTo(WinwingFcuReport targetReport)
{
targetReport.ReportId = this.ReportId;
targetReport.ButtonState = this.ButtonState;
targetReport.SpdEncoderValue = this.SpdEncoderValue;
targetReport.AltEncoderValue = this.AltEncoderValue;
targetReport.HdgEncoderValue = this.HdgEncoderValue;
targetReport.VsEncoderValue = this.VsEncoderValue;
targetReport.VsEncoderValue = this.VsEncoderValue;
}

public void ParseReport(HidBuffer hidBuffer)
{
byte[] data = hidBuffer.HidReport.TransferResult.Data;
byte[] data = hidBuffer.HidReport.TransferResult.Data;
ReportId = hidBuffer.HidReport.ReportId;
if (ReportId == BUTTONS_REPORT)
{
// get 32 bit Button report field - First 4 bytes: uint: [3][2][1][0]
ButtonState = ((uint)data[0] + ((uint)data[1] << 8) + ((uint)data[2] << 16) + ((uint)data[3] << 24));
SpdEncoderValue = (ushort)(data[12] | (data[13] << 8)); // create an ushort from bytes 13 and 14
HdgEncoderValue = (ushort)(data[14] | (data[15] << 8));
AltEncoderValue = (ushort)(data[16] | (data[17] << 8));
VsEncoderValue = (ushort)(data[18] | (data[19] << 8));

if (IsFirmwareGreaterOrEqual_1_16) // Since firmware v1.16
{
SpdEncoderValue = (ushort)(data[28] | (data[29] << 8)); // create an ushort from bytes 28 and 29
HdgEncoderValue = (ushort)(data[30] | (data[31] << 8));
AltEncoderValue = (ushort)(data[32] | (data[33] << 8));
VsEncoderValue = (ushort)(data[34] | (data[35] << 8));
}
else // old firmware
{
SpdEncoderValue = (ushort)(data[12] | (data[13] << 8)); // create an ushort from bytes 13 and 14
HdgEncoderValue = (ushort)(data[14] | (data[15] << 8));
AltEncoderValue = (ushort)(data[16] | (data[17] << 8));
VsEncoderValue = (ushort)(data[18] | (data[19] << 8));
}
}
else if (ReportId == DEVICE_REPORT)
{
// Is firmware report
if (data[5] == 0x02 && data[4] == 0x05 && data[0] == 0x10)
{
Log.Instance.log($"WINWING FCU Firmware: v{data[9].ToString("X2")}.{data[8].ToString("X2")}", LogSeverity.Debug);
if (data[9] == 1 && data[8] < 0x16)
{
IsFirmwareGreaterOrEqual_1_16 = false;
}
}
}
}
}
Expand Down
Binary file modified lib/MobiFlightWwFcu.dll
Binary file not shown.

0 comments on commit 5de2ac5

Please sign in to comment.