mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Logitech - Added retry mechanism to Lightspeed detector
This commit is contained in:
parent
35d61e1496
commit
1f3cef94c8
@ -1,4 +1,4 @@
|
||||
using HidSharp;
|
||||
using HidSharp;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.HID;
|
||||
using System;
|
||||
@ -18,6 +18,7 @@ public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const int LOGITECH_PROTOCOL_TIMEOUT = 300;
|
||||
private const int VENDOR_ID = 0x046D;
|
||||
|
||||
// ReSharper disable once StaticMemberInGenericType - This is used like a const
|
||||
@ -115,9 +116,17 @@ public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<
|
||||
|
||||
Dictionary<int, byte> map = new();
|
||||
|
||||
if (deviceUsages.TryGetValue(1, out HidDevice? device))
|
||||
if (!deviceUsages.TryGetValue(1, out HidDevice? device) || !device.TryOpen(out HidStream stream))
|
||||
return map;
|
||||
|
||||
int tries = 0;
|
||||
const int maxTries = 5;
|
||||
while (tries < maxTries)
|
||||
{
|
||||
HidStream? stream = device.Open();
|
||||
try
|
||||
{
|
||||
stream.ReadTimeout = LOGITECH_PROTOCOL_TIMEOUT;
|
||||
stream.WriteTimeout = LOGITECH_PROTOCOL_TIMEOUT;
|
||||
|
||||
FapResponse response = new();
|
||||
|
||||
@ -151,11 +160,11 @@ public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<
|
||||
|
||||
stream.Write(getConnectedDevices.AsSpan());
|
||||
stream.Read(response.AsSpan());
|
||||
|
||||
int deviceCount = response.Data01;
|
||||
if (deviceCount > 0)
|
||||
{
|
||||
//log "Faking a reconnect to get device list"
|
||||
if (deviceCount <= 0)
|
||||
return map;
|
||||
|
||||
//Add 1 to the device_count to include the receiver
|
||||
deviceCount++;
|
||||
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
|
||||
@ -171,6 +180,14 @@ public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<
|
||||
if (devices.DeviceIndex != 0xff)
|
||||
map.Add(wirelessPid, devices.DeviceIndex);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
catch
|
||||
{
|
||||
tries++;
|
||||
//This might timeout if LGS or GHUB interfere.
|
||||
//Retry.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user