Skip to content

Commit

Permalink
✨ DA3.5G: Read the FW version upon startup.
Browse files Browse the repository at this point in the history
This is not used yet, but at some point, we want to display this information in the UI for all devices.
  • Loading branch information
hexawyz committed Sep 17, 2024
1 parent bdc8cf1 commit 8197082
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Immutable;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using DeviceTools;
using DeviceTools.HumanInterfaceDevices;
Expand Down Expand Up @@ -139,6 +140,11 @@ CancellationToken cancellationToken

try
{
if (driverType is KernelDriverType.DeathAdderNew)
{
var (major, minor) = await transport.GetFirmwareVersionAsync(cancellationToken).ConfigureAwait(false);
}

// Push the default settings to the device, so that we are in sync.
await transport.UpdateSettingsAsync(2, 1, 1, 3, cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -367,10 +373,14 @@ internal abstract class DeathAdderTransport : IAsyncDisposable
public virtual ValueTask DisposeAsync() => _controlDevice.DisposeAsync();

public abstract Task UpdateSettingsAsync(byte pollingRate, byte dpiIndex, byte profileIndex, byte lightingState, CancellationToken cancellationToken);

public virtual Task<(byte Major, byte Minor)> GetFirmwareVersionAsync(CancellationToken cancellationToken)
=> Task.FromException<(byte, byte)>(ExceptionDispatchInfo.SetCurrentStackTrace(new NotSupportedException()));
}

internal sealed class DeathAdderNewTransport : DeathAdderTransport
{
private const int ReadFirmwareVersionIoControlCode = 0x222510;
private const int UpdateSettingsIoControlCode = 0x222528;

private readonly byte[] _buffer;
Expand All @@ -388,6 +398,13 @@ public override async Task UpdateSettingsAsync(byte pollingRate, byte dpiIndex,
_buffer[3] = lightingState;
await ControlDevice.IoControlAsync(UpdateSettingsIoControlCode, (ReadOnlyMemory<byte>)MemoryMarshal.CreateFromPinnedArray(_buffer, 0, 4), cancellationToken).ConfigureAwait(false);
}

public override async Task<(byte Major, byte Minor)> GetFirmwareVersionAsync(CancellationToken cancellationToken)
{
Array.Clear(_buffer);
await ControlDevice.IoControlAsync(ReadFirmwareVersionIoControlCode, MemoryMarshal.CreateFromPinnedArray(_buffer, 0, 2), cancellationToken).ConfigureAwait(false);
return (_buffer[0], _buffer[1]);
}
}

internal sealed class RzUddTransport : DeathAdderTransport
Expand Down

0 comments on commit 8197082

Please sign in to comment.