mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
commit
e07b580bf9
@ -35,6 +35,11 @@ public class LogitechRGBDeviceInfo : IRGBDeviceInfo
|
||||
/// </summary>
|
||||
public int Zones { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the zone at which LEDs start being mapped
|
||||
/// </summary>
|
||||
public int ZoneOffset { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -46,12 +51,14 @@ public class LogitechRGBDeviceInfo : IRGBDeviceInfo
|
||||
/// <param name="model">The represented device model.</param>
|
||||
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
|
||||
/// <param name="zones">The amount of zones the device is able to control.</param>
|
||||
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, int zones)
|
||||
/// <param name="zoneOffset">The zone at which to start mapping LEDs.</param>
|
||||
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, int zones, int zoneOffset = 0)
|
||||
{
|
||||
this.DeviceType = deviceType;
|
||||
this.Model = model;
|
||||
this.DeviceCaps = deviceCaps;
|
||||
this.Zones = zones;
|
||||
this.ZoneOffset = zoneOffset;
|
||||
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
|
||||
@ -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,49 +116,57 @@ 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();
|
||||
|
||||
FapResponse response = new();
|
||||
|
||||
FapShortRequest getConnectedDevices = new();
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
|
||||
|
||||
stream.Write(getConnectedDevices.AsSpan());
|
||||
stream.Read(response.AsSpan());
|
||||
|
||||
bool wirelessNotifications = (response.Data01 & 1) == 1;
|
||||
if (!wirelessNotifications)
|
||||
try
|
||||
{
|
||||
response = new FapResponse();
|
||||
stream.ReadTimeout = LOGITECH_PROTOCOL_TIMEOUT;
|
||||
stream.WriteTimeout = LOGITECH_PROTOCOL_TIMEOUT;
|
||||
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
|
||||
getConnectedDevices.Data1 = 1;
|
||||
FapResponse response = new();
|
||||
|
||||
FapShortRequest getConnectedDevices = new();
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
|
||||
|
||||
stream.Write(getConnectedDevices.AsSpan());
|
||||
stream.Read(response.AsSpan());
|
||||
|
||||
if (getConnectedDevices.FeatureIndex == 0x8f)
|
||||
bool wirelessNotifications = (response.Data01 & 1) == 1;
|
||||
if (!wirelessNotifications)
|
||||
{
|
||||
//error??
|
||||
response = new FapResponse();
|
||||
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
|
||||
getConnectedDevices.Data1 = 1;
|
||||
|
||||
stream.Write(getConnectedDevices.AsSpan());
|
||||
stream.Read(response.AsSpan());
|
||||
|
||||
if (getConnectedDevices.FeatureIndex == 0x8f)
|
||||
{
|
||||
//error??
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response = new FapResponse();
|
||||
response = new FapResponse();
|
||||
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
|
||||
getConnectedDevices.FeatureCommand = 0x02;
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
|
||||
getConnectedDevices.FeatureCommand = 0x02;
|
||||
|
||||
stream.Write(getConnectedDevices.AsSpan());
|
||||
stream.Read(response.AsSpan());
|
||||
stream.Write(getConnectedDevices.AsSpan());
|
||||
stream.Read(response.AsSpan());
|
||||
int deviceCount = response.Data01;
|
||||
if (deviceCount <= 0)
|
||||
return map;
|
||||
|
||||
int deviceCount = response.Data01;
|
||||
if (deviceCount > 0)
|
||||
{
|
||||
//log "Faking a reconnect to get device list"
|
||||
//Add 1 to the device_count to include the receiver
|
||||
deviceCount++;
|
||||
|
||||
|
||||
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
|
||||
getConnectedDevices.FeatureCommand = 0x02;
|
||||
getConnectedDevices.Data0 = 0x02;
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -78,55 +78,55 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
|
||||
/// <summary>
|
||||
/// Gets the HID-definitions for wired per-zone-devices.
|
||||
/// </summary>
|
||||
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
|
||||
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones, int zoneOffset)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
|
||||
{
|
||||
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 5) },
|
||||
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 5, 0) },
|
||||
|
||||
{ 0xC092, RGBDeviceType.Mouse, "G203 Lightsync", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||
{ 0xC080, RGBDeviceType.Mouse, "G303", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC081, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC082, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC083, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC084, RGBDeviceType.Mouse, "G203", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||
{ 0xC085, RGBDeviceType.Mouse, "G Pro", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||
{ 0xC086, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC087, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC088, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC08B, RGBDeviceType.Mouse, "G502 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC08C, RGBDeviceType.Mouse, "G Pro Hero", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||
{ 0xC08D, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC08F, RGBDeviceType.Mouse, "G403 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC090, RGBDeviceType.Mouse, "G703 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC091, RGBDeviceType.Mouse, "G903 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC24A, RGBDeviceType.Mouse, "G600", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||
{ 0xC332, RGBDeviceType.Mouse, "G502", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0xC092, RGBDeviceType.Mouse, "G203 Lightsync", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 0) },
|
||||
{ 0xC080, RGBDeviceType.Mouse, "G303", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC081, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC082, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC083, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC084, RGBDeviceType.Mouse, "G203", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 0) },
|
||||
{ 0xC085, RGBDeviceType.Mouse, "G Pro", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 0) },
|
||||
{ 0xC086, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC087, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC088, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC08B, RGBDeviceType.Mouse, "G502 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC08C, RGBDeviceType.Mouse, "G Pro Hero", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 1) },
|
||||
{ 0xC08D, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC08F, RGBDeviceType.Mouse, "G403 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC090, RGBDeviceType.Mouse, "G703 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC091, RGBDeviceType.Mouse, "G903 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0xC24A, RGBDeviceType.Mouse, "G600", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 0) },
|
||||
{ 0xC332, RGBDeviceType.Mouse, "G502", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
|
||||
{ 0xC53A, RGBDeviceType.Mousepad, "POWERPLAY", LedMappings.ZoneMousepad, (LogitechDeviceType.Mousemat, 1) },
|
||||
{ 0xC53A, RGBDeviceType.Mousepad, "POWERPLAY", LedMappings.ZoneMousepad, (LogitechDeviceType.Mousemat, 1, 0) },
|
||||
|
||||
//G633 and G635 are wired headsets.
|
||||
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||
{ 0x0A89, RGBDeviceType.Headset, "G635", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
|
||||
{ 0x0A89, RGBDeviceType.Headset, "G635", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
|
||||
|
||||
//The other ones are wireless only. These PIDs correpond to the dongles.
|
||||
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
|
||||
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
|
||||
|
||||
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4) },
|
||||
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) },
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HID-definitions for wireless per-zone-devices.
|
||||
/// </summary>
|
||||
public static LightspeedHIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneWirelessDeviceDefinitions { get; } = new()
|
||||
public static LightspeedHIDLoader<int, (LogitechDeviceType deviceType, int zones, int zoneOffset)> PerZoneWirelessDeviceDefinitions { get; } = new()
|
||||
{
|
||||
{ 0x4053, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x405D, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x4067, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x4070, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x4079, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x407F, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x4086, RGBDeviceType.Mouse, "G703 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x4087, RGBDeviceType.Mouse, "G903 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
||||
{ 0x4053, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x405D, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x4067, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x4070, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x4079, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x407F, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x4086, RGBDeviceType.Mouse, "G703 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
{ 0x4087, RGBDeviceType.Mouse, "G903 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@ -219,14 +219,15 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
|
||||
|
||||
#region PerZone
|
||||
|
||||
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)>> wiredPerZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices().Select(x => x.definition);
|
||||
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)>> wirelessPerZoneDevices = PerZoneWirelessDeviceDefinitions.GetConnectedDevices();
|
||||
foreach (HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)> definition in wiredPerZoneDevices.Concat(wirelessPerZoneDevices)
|
||||
.GroupBy(x => x.CustomData.deviceType)
|
||||
.Select(group => group.First()))
|
||||
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones, int zoneOffset)>> wiredPerZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices().Select(x => x.definition);
|
||||
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones, int zoneOffset)>> wirelessPerZoneDevices = PerZoneWirelessDeviceDefinitions.GetConnectedDevices();
|
||||
foreach (HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones, int zoneOffset)> definition in wiredPerZoneDevices.Concat(wirelessPerZoneDevices)
|
||||
.GroupBy(x => x.CustomData.deviceType)
|
||||
.Select(group => group.First()))
|
||||
{
|
||||
LogitechZoneUpdateQueue updateQueue = new(GetUpdateTrigger(), definition.CustomData.deviceType);
|
||||
yield return new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, definition.CustomData.zones), updateQueue, definition.LedMapping);
|
||||
yield return new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, definition.CustomData.zones, definition.CustomData.zoneOffset),
|
||||
updateQueue, definition.LedMapping);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -32,10 +32,9 @@ public class LogitechZoneRGBDevice : LogitechRGBDevice<LogitechRGBDeviceInfo>, I
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
for (int i = 0; i < DeviceInfo.Zones; i++)
|
||||
for (int i = DeviceInfo.ZoneOffset; i < (DeviceInfo.ZoneOffset + DeviceInfo.Zones); i++)
|
||||
AddLed(_ledMapping[i], new Point(i * 10, 0), new Size(10, 10));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user