Skip to content

Commit

Permalink
Support winwing fcu firmware v1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Koseng committed Jun 17, 2024
1 parent 467cc37 commit 3665667
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions MobiFlight/Joysticks/WinwingFcu/WinwingFcu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ 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 () =>
{
Expand Down
38 changes: 31 additions & 7 deletions MobiFlight/Joysticks/WinwingFcu/WinwingFcuReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,53 @@ 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)
{
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 3665667

Please sign in to comment.