Skip to content

Commit

Permalink
🐛 DeathAdder 3.5G: Fix the DPI presets.
Browse files Browse the repository at this point in the history
Index was still hardcoded at some palces, and active index returned was off by one after the previous changes.
  • Loading branch information
hexawyz committed Sep 17, 2024
1 parent 84be046 commit bdc8cf1
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ CancellationToken cancellationToken
_ => throw new NotImplementedException("This device requires a kernel driver to work."),
};

try
{
// Push the default settings to the device, so that we are in sync.
await transport.UpdateSettingsAsync(2, 1, 1, 3, cancellationToken).ConfigureAwait(false);
}
catch
{
await transport.DisposeAsync().ConfigureAwait(false);
throw;
}

var driver = new RazerDeathAdder35GDeviceDriver
(
transport,
Expand Down Expand Up @@ -174,7 +185,7 @@ CancellationToken cancellationToken

public override DeviceCategory DeviceCategory => DeviceCategory.Mouse;

private event Action<Driver, MouseDpiStatus> DpiChanged;
private event Action<Driver, MouseDpiStatus>? DpiChanged;

private RazerDeathAdder35GDeviceDriver
(
Expand All @@ -189,7 +200,7 @@ string topLevelDeviceName
_lock = new();
_versionNumber = versionNumber;
_lightingState = 0x0F;
_performanceState = 0x05;
_performanceState = 0x02;
_dpiPresets = dpiPresets;
_lightingZones = Array.AsReadOnly<ILightingZone>([new WheelLightingZone(this), new LogoLightingZone(this)]);
_genericFeatures = FeatureSet.Create<IGenericDeviceFeature, RazerDeathAdder35GDeviceDriver, IDeviceIdFeature>(this);
Expand Down Expand Up @@ -227,7 +238,7 @@ async ValueTask IMouseConfigurablePollingFrequencyFeature.SetPollingFrequencyAsy

async ValueTask IMouseDpiPresetsFeature.ChangeCurrentPresetAsync(byte activePresetIndex, CancellationToken cancellationToken)
{
if (activePresetIndex > 2) throw new ArgumentOutOfRangeException(nameof(activePresetIndex));
if (activePresetIndex > _dpiPresets.Length) throw new ArgumentOutOfRangeException(nameof(activePresetIndex));

byte newDpiState = (byte)(_dpiPresets.Length - 1 - activePresetIndex);

Expand Down Expand Up @@ -263,7 +274,7 @@ MouseDpiStatus IMouseDpiFeature.CurrentDpi
{
var state = Volatile.Read(ref _performanceState);

byte dpiIndex = (byte)(3 - ((state >> 2) & 3));
byte dpiIndex = (byte)(_dpiPresets.Length - 1 - ((state >> 2) & 3));

return new() { PresetIndex = dpiIndex, Dpi = _dpiPresets[dpiIndex] };
}
Expand Down

0 comments on commit bdc8cf1

Please sign in to comment.