From 1ee406eb625c26768646b1b77d64b75a82db0801 Mon Sep 17 00:00:00 2001 From: hexawyz <8518235+hexawyz@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:17:36 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Razer=20rename=20lighting?= =?UTF-8?q?=20features=20into=20V1=20and=20V2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRazerProtocolTransport.cs | 16 ++--- ...athAdderV2ProBluetoothProtocolTransport.cs | 20 +++--- .../RazerDeviceDriver.BaseDevice.cs | 48 ++++++------- .../Exo.Devices.Razer/RazerDeviceFeature.cs | 4 +- .../RazerProtocolTransport.cs | 70 +++++++++---------- 5 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/Exo/Devices/Exo.Devices.Razer/IRazerProtocolTransport.cs b/src/Exo/Devices/Exo.Devices.Razer/IRazerProtocolTransport.cs index 42bdd0e..d6bfe9b 100644 --- a/src/Exo/Devices/Exo.Devices.Razer/IRazerProtocolTransport.cs +++ b/src/Exo/Devices/Exo.Devices.Razer/IRazerProtocolTransport.cs @@ -18,16 +18,16 @@ internal interface IRazerProtocolTransport : IDisposable ValueTask GetPollingFrequencyDivider(CancellationToken cancellationToken); Task SetPollingFrequencyDivider(byte divider, CancellationToken cancellationToken); - ValueTask GetSavedLegacyEffectAsync(CancellationToken cancellationToken); - Task SetLegacyEffectAsync(RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2, CancellationToken cancellationToken); - Task SetLegacyBrightnessAsync(byte value, CancellationToken cancellationToken); - ValueTask GetLegacyBrightnessAsync(CancellationToken cancellationToken); + ValueTask GetSavedEffectV1Async(CancellationToken cancellationToken); + Task SetEffectV1Async(RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2, CancellationToken cancellationToken); + Task SetBrightnessV1Async(byte value, CancellationToken cancellationToken); + ValueTask GetBrightnessV1Async(CancellationToken cancellationToken); ValueTask GetDeviceInformationXxxxxAsync(CancellationToken cancellationToken); - ValueTask GetBrightnessAsync(bool persisted, byte flag, CancellationToken cancellationToken); - Task SetBrightnessAsync(bool persist, byte value, CancellationToken cancellationToken); - ValueTask GetSavedEffectAsync(byte flag, CancellationToken cancellationToken); - Task SetEffectAsync(bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2, CancellationToken cancellationToken); + ValueTask GetBrightnessV2Async(bool persisted, byte flag, CancellationToken cancellationToken); + Task SetBrightnessV2Async(bool persist, byte value, CancellationToken cancellationToken); + ValueTask GetSavedEffectV2Async(byte flag, CancellationToken cancellationToken); + Task SetEffectV2Async(bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2, CancellationToken cancellationToken); ValueTask SetDynamicColorAsync(RgbColor color, CancellationToken cancellationToken); ValueTask GetIdleTimerAsync(CancellationToken cancellationToken); diff --git a/src/Exo/Devices/Exo.Devices.Razer/RazerDeathAdderV2ProBluetoothProtocolTransport.cs b/src/Exo/Devices/Exo.Devices.Razer/RazerDeathAdderV2ProBluetoothProtocolTransport.cs index 1128046..c7c0d05 100644 --- a/src/Exo/Devices/Exo.Devices.Razer/RazerDeathAdderV2ProBluetoothProtocolTransport.cs +++ b/src/Exo/Devices/Exo.Devices.Razer/RazerDeathAdderV2ProBluetoothProtocolTransport.cs @@ -155,7 +155,7 @@ private sealed class LightingEffectWaitState : WaitState { public LightingEffectWaitState(byte[] buffer, byte commandId) : base(buffer, commandId) { } - protected override ILightingEffect? ProcessData(ReadOnlySpan data) => RazerProtocolTransport.ParseEffect(data); + protected override ILightingEffect? ProcessData(ReadOnlySpan data) => RazerProtocolTransport.ParseV2Effect(data); } private sealed class DpiWaitState : WaitState @@ -287,7 +287,7 @@ static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharact // TODO: Should find a way to make this return the information that we nneed. The value is currently hardcoded. public ValueTask GetDeviceInformationXxxxxAsync(CancellationToken cancellationToken) => ValueTask.FromResult(4); - public async ValueTask GetSavedEffectAsync(byte flag, CancellationToken cancellationToken) + public async ValueTask GetSavedEffectV2Async(byte flag, CancellationToken cancellationToken) { static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharacteristicInformation writeCharacteristic, bool persisted, byte flag) { @@ -327,7 +327,7 @@ static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharact } - public async Task SetEffectAsync(bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) + public async Task SetEffectV2Async(bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) { static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharacteristicInformation writeCharacteristic, bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2) { @@ -342,7 +342,7 @@ static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharact *(ushort*)&((uint*)buffer)[2] = 0x_03_10; buffer[4 + 6] = persist ? (byte)1 : (byte)0; buffer[4 + 7] = 0; - uint length = (uint)RazerProtocolTransport.WriteEffect(new Span(&buffer[4 + 8 + 4], EffectBufferLength), effect, colorCount, color1, color2); + uint length = (uint)RazerProtocolTransport.WriteV2Effect(new Span(&buffer[4 + 8 + 4], EffectBufferLength), effect, colorCount, color1, color2); if (length > EffectBufferLength) throw new InvalidOperationException("Unsupported effect length"); buffer[4 + 1] = (byte)length; ((uint*)buffer)[3] = length; @@ -378,7 +378,7 @@ static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharact // TODO public ValueTask SetDynamicColorAsync(RgbColor color, CancellationToken cancellationToken) => throw new NotImplementedException(); - public async ValueTask GetBrightnessAsync(bool persisted, byte flag, CancellationToken cancellationToken) + public async ValueTask GetBrightnessV2Async(bool persisted, byte flag, CancellationToken cancellationToken) { static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharacteristicInformation writeCharacteristic, bool persisted, byte flag) { @@ -417,7 +417,7 @@ static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharact } } - public async Task SetBrightnessAsync(bool persist, byte value, CancellationToken cancellationToken) + public async Task SetBrightnessV2Async(bool persist, byte value, CancellationToken cancellationToken) { static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharacteristicInformation writeCharacteristic, bool persist, byte value) { @@ -879,8 +879,8 @@ static unsafe void WriteData(SafeFileHandle serviceHandle, in BluetoothLeCharact ValueTask IRazerProtocolTransport.GetDeviceInformationAsync(CancellationToken cancellationToken) => throw new NotSupportedException(); ValueTask IRazerProtocolTransport.GetDevicePairingInformationAsync(CancellationToken cancellationToken) => throw new NotSupportedException(); - ValueTask IRazerProtocolTransport.GetSavedLegacyEffectAsync(CancellationToken cancellationToken) => throw new NotSupportedException(); - Task IRazerProtocolTransport.SetLegacyEffectAsync(RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) => throw new NotSupportedException(); - Task IRazerProtocolTransport.SetLegacyBrightnessAsync(byte value, CancellationToken cancellationToken) => throw new NotSupportedException(); - ValueTask IRazerProtocolTransport.GetLegacyBrightnessAsync(CancellationToken cancellationToken) => throw new NotSupportedException(); + ValueTask IRazerProtocolTransport.GetSavedEffectV1Async(CancellationToken cancellationToken) => throw new NotSupportedException(); + Task IRazerProtocolTransport.SetEffectV1Async(RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) => throw new NotSupportedException(); + Task IRazerProtocolTransport.SetBrightnessV1Async(byte value, CancellationToken cancellationToken) => throw new NotSupportedException(); + ValueTask IRazerProtocolTransport.GetBrightnessV1Async(CancellationToken cancellationToken) => throw new NotSupportedException(); } diff --git a/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceDriver.BaseDevice.cs b/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceDriver.BaseDevice.cs index b7e31a4..4b852ae 100644 --- a/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceDriver.BaseDevice.cs +++ b/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceDriver.BaseDevice.cs @@ -189,15 +189,15 @@ await _transport.IsConnectedToExternalPowerAsync(cancellationToken).ConfigureAwa { if (!HasLightingV2) { - _currentBrightness = await _transport.GetLegacyBrightnessAsync(cancellationToken).ConfigureAwait(false); + _currentBrightness = await _transport.GetBrightnessV1Async(cancellationToken).ConfigureAwait(false); //_appliedEffect = await _transport.GetSavedLegacyEffectAsync(cancellationToken).ConfigureAwait(false) ?? DisabledEffect.SharedInstance; _appliedEffect = DisabledEffect.SharedInstance; } else { byte flag = await _transport.GetDeviceInformationXxxxxAsync(cancellationToken).ConfigureAwait(false); - _currentBrightness = await _transport.GetBrightnessAsync(true, flag, cancellationToken).ConfigureAwait(false); - _appliedEffect = await _transport.GetSavedEffectAsync(flag, cancellationToken).ConfigureAwait(false) ?? DisabledEffect.SharedInstance; + _currentBrightness = await _transport.GetBrightnessV2Async(true, flag, cancellationToken).ConfigureAwait(false); + _appliedEffect = await _transport.GetSavedEffectV2Async(flag, cancellationToken).ConfigureAwait(false) ?? DisabledEffect.SharedInstance; // Reapply the persisted effect. (In case it was overridden by a temporary effect) await ApplyEffectAsync(_appliedEffect, _currentBrightness, false, true, cancellationToken).ConfigureAwait(false); @@ -297,7 +297,7 @@ private async ValueTask ApplyChangesAsync(bool shouldPersist, CancellationToken } else if (!ReferenceEquals(_currentEffect, DisabledEffect.SharedInstance) && _appliedBrightness != _currentBrightness) { - await _transport.SetBrightnessAsync(shouldPersist, _currentBrightness, cancellationToken).ConfigureAwait(false); + await _transport.SetBrightnessV2Async(shouldPersist, _currentBrightness, cancellationToken).ConfigureAwait(false); } _appliedBrightness = _currentBrightness; } @@ -307,8 +307,8 @@ private async ValueTask ApplyLegacyEffectAsync(ILightingEffect effect, byte brig { if (ReferenceEquals(effect, DisabledEffect.SharedInstance)) { - await _transport.SetLegacyEffectAsync(0, 0, default, default, cancellationToken).ConfigureAwait(false); - await _transport.SetLegacyBrightnessAsync(0, cancellationToken); + await _transport.SetEffectV1Async(0, 0, default, default, cancellationToken).ConfigureAwait(false); + await _transport.SetBrightnessV1Async(0, cancellationToken); return; } @@ -316,31 +316,31 @@ private async ValueTask ApplyLegacyEffectAsync(ILightingEffect effect, byte brig // Otherwise, the device might restore to its saved effect. (e.g. Color Cycle) if (forceBrightnessUpdate) { - await _transport.SetLegacyBrightnessAsync(brightness, cancellationToken); + await _transport.SetBrightnessV1Async(brightness, cancellationToken); } switch (effect) { case StaticColorEffect staticColorEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.Static, 1, staticColorEffect.Color, staticColorEffect.Color, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.Static, 1, staticColorEffect.Color, staticColorEffect.Color, cancellationToken); break; case RandomColorPulseEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.Breathing, 3, default, default, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.Breathing, 3, default, default, cancellationToken); break; case ColorPulseEffect colorPulseEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.Breathing, 1, colorPulseEffect.Color, default, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.Breathing, 1, colorPulseEffect.Color, default, cancellationToken); break; case TwoColorPulseEffect twoColorPulseEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.Breathing, 2, twoColorPulseEffect.Color, twoColorPulseEffect.SecondColor, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.Breathing, 2, twoColorPulseEffect.Color, twoColorPulseEffect.SecondColor, cancellationToken); break; case SpectrumCycleEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.SpectrumCycle, 0, default, default, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.SpectrumCycle, 0, default, default, cancellationToken); break; case SpectrumWaveEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.Wave, 1, default, default, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.Wave, 1, default, default, cancellationToken); break; case ReactiveEffect reactiveEffect: - await _transport.SetLegacyEffectAsync(RazerLegacyLightingEffect.Reactive, 1, reactiveEffect.Color, default, cancellationToken); + await _transport.SetEffectV1Async(RazerLegacyLightingEffect.Reactive, 1, reactiveEffect.Color, default, cancellationToken); break; } } @@ -349,8 +349,8 @@ private async ValueTask ApplyEffectAsync(ILightingEffect effect, byte brightness { if (ReferenceEquals(effect, DisabledEffect.SharedInstance)) { - await _transport.SetEffectAsync(shouldPersist, 0, 0, default, default, cancellationToken).ConfigureAwait(false); - await _transport.SetBrightnessAsync(shouldPersist, 0, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, 0, 0, default, default, cancellationToken).ConfigureAwait(false); + await _transport.SetBrightnessV2Async(shouldPersist, 0, cancellationToken); return; } @@ -358,31 +358,31 @@ private async ValueTask ApplyEffectAsync(ILightingEffect effect, byte brightness // Otherwise, the device might restore to its saved effect. (e.g. Color Cycle) if (forceBrightnessUpdate) { - await _transport.SetBrightnessAsync(shouldPersist, brightness, cancellationToken); + await _transport.SetBrightnessV2Async(shouldPersist, brightness, cancellationToken); } switch (effect) { case StaticColorEffect staticColorEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.Static, 1, staticColorEffect.Color, staticColorEffect.Color, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.Static, 1, staticColorEffect.Color, staticColorEffect.Color, cancellationToken); break; case RandomColorPulseEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.Breathing, 0, default, default, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.Breathing, 0, default, default, cancellationToken); break; case ColorPulseEffect colorPulseEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.Breathing, 1, colorPulseEffect.Color, default, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.Breathing, 1, colorPulseEffect.Color, default, cancellationToken); break; case TwoColorPulseEffect twoColorPulseEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.Breathing, 2, twoColorPulseEffect.Color, twoColorPulseEffect.SecondColor, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.Breathing, 2, twoColorPulseEffect.Color, twoColorPulseEffect.SecondColor, cancellationToken); break; case SpectrumCycleEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.SpectrumCycle, 0, default, default, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.SpectrumCycle, 0, default, default, cancellationToken); break; case SpectrumWaveEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.Wave, 0, default, default, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.Wave, 0, default, default, cancellationToken); break; case ReactiveEffect reactiveEffect: - await _transport.SetEffectAsync(shouldPersist, RazerLightingEffect.Reactive, 1, reactiveEffect.Color, default, cancellationToken); + await _transport.SetEffectV2Async(shouldPersist, RazerLightingEffect.Reactive, 1, reactiveEffect.Color, default, cancellationToken); break; } } diff --git a/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceFeature.cs b/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceFeature.cs index a08ffb3..6216de3 100644 --- a/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceFeature.cs +++ b/src/Exo/Devices/Exo.Devices.Razer/RazerDeviceFeature.cs @@ -3,8 +3,8 @@ namespace Exo.Devices.Razer; public enum RazerDeviceFeature : byte { General = 0x00, - LightingLegacy = 0x03, + LightingV1 = 0x03, Mouse = 0x04, Power = 0x07, - Lighting = 0x0F, + LightingV2 = 0x0F, } diff --git a/src/Exo/Devices/Exo.Devices.Razer/RazerProtocolTransport.cs b/src/Exo/Devices/Exo.Devices.Razer/RazerProtocolTransport.cs index ccfb0a9..f6aa9ba 100644 --- a/src/Exo/Devices/Exo.Devices.Razer/RazerProtocolTransport.cs +++ b/src/Exo/Devices/Exo.Devices.Razer/RazerProtocolTransport.cs @@ -116,7 +116,7 @@ static void FillBuffer(Span buffer) } } - public async Task SetLegacyBrightnessAsync(byte value, CancellationToken cancellationToken) + public async Task SetBrightnessV1Async(byte value, CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -129,7 +129,7 @@ static void FillBuffer(Span buffer, byte value) buffer[2] = 0x1f; buffer[6] = 0x03; - buffer[7] = (byte)RazerDeviceFeature.LightingLegacy; + buffer[7] = (byte)RazerDeviceFeature.LightingV1; buffer[8] = 0x03; // Maybe persistence ? Or wired flag ? @@ -148,7 +148,7 @@ static void FillBuffer(Span buffer, byte value) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingLegacy, 0x03, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV1, 0x03, 0, cancellationToken).ConfigureAwait(false); } finally { @@ -158,7 +158,7 @@ static void FillBuffer(Span buffer, byte value) } } - public async ValueTask GetLegacyBrightnessAsync(CancellationToken cancellationToken) + public async ValueTask GetBrightnessV1Async(CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -171,7 +171,7 @@ static void FillBuffer(Span buffer) buffer[2] = 0x1f; buffer[6] = 0x01; - buffer[7] = (byte)RazerDeviceFeature.LightingLegacy; + buffer[7] = (byte)RazerDeviceFeature.LightingV1; buffer[8] = 0x83; UpdateChecksum(buffer); @@ -183,7 +183,7 @@ static void FillBuffer(Span buffer) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingLegacy, 0x83, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV1, 0x83, 0, cancellationToken).ConfigureAwait(false); return buffer.Span[11]; } @@ -195,7 +195,7 @@ static void FillBuffer(Span buffer) } } - public async Task SetBrightnessAsync(bool persist, byte value, CancellationToken cancellationToken) + public async Task SetBrightnessV2Async(bool persist, byte value, CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -208,7 +208,7 @@ static void FillBuffer(Span buffer, bool persist, byte value) buffer[2] = 0x1f; buffer[6] = 0x03; - buffer[7] = (byte)RazerDeviceFeature.Lighting; + buffer[7] = (byte)RazerDeviceFeature.LightingV2; buffer[8] = 0x04; buffer[9] = persist ? (byte)0x01 : (byte)0x00; @@ -224,7 +224,7 @@ static void FillBuffer(Span buffer, bool persist, byte value) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.Lighting, 0x04, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV2, 0x04, 0, cancellationToken).ConfigureAwait(false); } finally { @@ -234,7 +234,7 @@ static void FillBuffer(Span buffer, bool persist, byte value) } } - public async ValueTask GetBrightnessAsync(bool persisted, byte flag, CancellationToken cancellationToken) + public async ValueTask GetBrightnessV2Async(bool persisted, byte flag, CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -247,7 +247,7 @@ static void FillBuffer(Span buffer, bool persisted, byte flag) buffer[2] = 0x1f; buffer[6] = 0x01; - buffer[7] = (byte)RazerDeviceFeature.Lighting; + buffer[7] = (byte)RazerDeviceFeature.LightingV2; buffer[8] = 0x84; buffer[9] = persisted ? (byte)0x01 : (byte)0x00; @@ -262,7 +262,7 @@ static void FillBuffer(Span buffer, bool persisted, byte flag) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.Lighting, 0x84, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV2, 0x84, 0, cancellationToken).ConfigureAwait(false); return buffer.Span[11]; } @@ -507,7 +507,7 @@ static void FillBuffer(Span buffer) buffer[2] = 0x1f; buffer[6] = 0x32; - buffer[7] = (byte)RazerDeviceFeature.Lighting; + buffer[7] = (byte)RazerDeviceFeature.LightingV2; buffer[8] = 0x80; UpdateChecksum(buffer); @@ -519,7 +519,7 @@ static void FillBuffer(Span buffer) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.Lighting, 0x80, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV2, 0x80, 0, cancellationToken).ConfigureAwait(false); return buffer.Span[9]; } @@ -531,7 +531,7 @@ static void FillBuffer(Span buffer) } } - public static ILightingEffect? ParseLegacyEffect(ReadOnlySpan buffer) + public static ILightingEffect? ParseEffectV1Async(ReadOnlySpan buffer) { var effect = (RazerLegacyLightingEffect)buffer[0]; byte parameter = buffer[1]; @@ -556,7 +556,7 @@ static void FillBuffer(Span buffer) } // TODO: That was written a bit hastily. Because each effect actually requires a slightly different structure, rework this later. - public static byte WriteLegacyEffect(Span buffer, RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2) + public static byte WriteEffectV1Async(Span buffer, RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2) { buffer[0] = (byte)effect; @@ -592,7 +592,7 @@ public static byte WriteLegacyEffect(Span buffer, RazerLegacyLightingEffec } // NB: Reading does not seem to be actually possible ? - public async ValueTask GetSavedLegacyEffectAsync(CancellationToken cancellationToken) + public async ValueTask GetSavedEffectV1Async(CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -605,13 +605,13 @@ static void FillBuffer(Span buffer) buffer[2] = 0x1f; buffer[6] = 0x08; - buffer[7] = (byte)RazerDeviceFeature.LightingLegacy; + buffer[7] = (byte)RazerDeviceFeature.LightingV1; buffer[8] = 0x8a; UpdateChecksum(buffer); } - static ILightingEffect? ParseResponse(ReadOnlySpan buffer) => ParseEffect(buffer[9..]); + static ILightingEffect? ParseResponse(ReadOnlySpan buffer) => ParseV2Effect(buffer[9..]); try { @@ -619,7 +619,7 @@ static void FillBuffer(Span buffer) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingLegacy, 0x8a, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV1, 0x8a, 0, cancellationToken).ConfigureAwait(false); return ParseResponse(buffer.Span); } @@ -631,7 +631,7 @@ static void FillBuffer(Span buffer) } } - public async Task SetLegacyEffectAsync(RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) + public async Task SetEffectV1Async(RazerLegacyLightingEffect effect, byte parameter, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -643,10 +643,10 @@ static void FillBuffer(Span buffer, RazerLegacyLightingEffect effect, byte { buffer[2] = 0x1f; - buffer[7] = (byte)RazerDeviceFeature.LightingLegacy; + buffer[7] = (byte)RazerDeviceFeature.LightingV1; buffer[8] = 0x0a; - buffer[6] = WriteLegacyEffect(buffer[9..], effect, parameter, color1, color2); + buffer[6] = WriteEffectV1Async(buffer[9..], effect, parameter, color1, color2); UpdateChecksum(buffer); } @@ -657,7 +657,7 @@ static void FillBuffer(Span buffer, RazerLegacyLightingEffect effect, byte await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingLegacy, 0x0a, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV1, 0x0a, 0, cancellationToken).ConfigureAwait(false); } finally { @@ -667,7 +667,7 @@ static void FillBuffer(Span buffer, RazerLegacyLightingEffect effect, byte } } - public static ILightingEffect? ParseEffect(ReadOnlySpan buffer) + public static ILightingEffect? ParseV2Effect(ReadOnlySpan buffer) { byte colorCount = buffer[3]; RgbColor color1 = colorCount > 0 ? new(buffer[4], buffer[5], buffer[6]) : default; @@ -690,7 +690,7 @@ static void FillBuffer(Span buffer, RazerLegacyLightingEffect effect, byte }; } - public static int WriteEffect(Span buffer, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2) + public static int WriteV2Effect(Span buffer, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2) { buffer[0] = (byte)effect; buffer[1] = 0x01; @@ -715,7 +715,7 @@ public static int WriteEffect(Span buffer, RazerLightingEffect effect, byt return 3; } - public async ValueTask GetSavedEffectAsync(byte flag, CancellationToken cancellationToken) + public async ValueTask GetSavedEffectV2Async(byte flag, CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -728,7 +728,7 @@ static void FillBuffer(Span buffer, byte flag) buffer[2] = 0x1f; buffer[6] = 0x0c; - buffer[7] = (byte)RazerDeviceFeature.Lighting; + buffer[7] = (byte)RazerDeviceFeature.LightingV2; buffer[8] = 0x82; buffer[9] = 0x01; @@ -737,7 +737,7 @@ static void FillBuffer(Span buffer, byte flag) UpdateChecksum(buffer); } - static ILightingEffect? ParseResponse(ReadOnlySpan buffer) => ParseEffect(buffer[11..]); + static ILightingEffect? ParseResponse(ReadOnlySpan buffer) => ParseV2Effect(buffer[11..]); try { @@ -745,7 +745,7 @@ static void FillBuffer(Span buffer, byte flag) await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.Lighting, 0x82, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV2, 0x82, 0, cancellationToken).ConfigureAwait(false); return ParseResponse(buffer.Span); } @@ -757,7 +757,7 @@ static void FillBuffer(Span buffer, byte flag) } } - public async Task SetEffectAsync(bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) + public async Task SetEffectV2Async(bool persist, RazerLightingEffect effect, byte colorCount, RgbColor color1, RgbColor color2, CancellationToken cancellationToken) { var @lock = Volatile.Read(ref _lock); ObjectDisposedException.ThrowIf(@lock is null, typeof(RazerProtocolTransport)); @@ -770,13 +770,13 @@ static void FillBuffer(Span buffer, bool persist, RazerLightingEffect effe buffer[2] = 0x1f; buffer[6] = 0x0c; - buffer[7] = (byte)RazerDeviceFeature.Lighting; + buffer[7] = (byte)RazerDeviceFeature.LightingV2; buffer[8] = 0x02; buffer[9] = persist ? (byte)0x01 : (byte)0x00; buffer[10] = 0x00; - WriteEffect(buffer[11..], effect, colorCount, color1, color2); + WriteV2Effect(buffer[11..], effect, colorCount, color1, color2); UpdateChecksum(buffer); } @@ -787,7 +787,7 @@ static void FillBuffer(Span buffer, bool persist, RazerLightingEffect effe await SetFeatureAsync(buffer, cancellationToken).ConfigureAwait(false); - await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.Lighting, 0x02, 0, cancellationToken).ConfigureAwait(false); + await ReadResponseAsync(buffer, 0x1f, RazerDeviceFeature.LightingV2, 0x02, 0, cancellationToken).ConfigureAwait(false); } finally { @@ -810,7 +810,7 @@ static void FillBuffer(Span buffer, RgbColor color) buffer[2] = 0x1f; buffer[6] = 0x08; - buffer[7] = (byte)RazerDeviceFeature.Lighting; + buffer[7] = (byte)RazerDeviceFeature.LightingV2; buffer[8] = 0x03; buffer[14] = color.R;