mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Logitech - Added wireless device detection
This commit is contained in:
parent
5fc2e34f28
commit
412dc9785c
49
RGB.NET.Devices.Logitech/HID/Extensions.cs
Normal file
49
RGB.NET.Devices.Logitech/HID/Extensions.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using HidSharp;
|
||||||
|
using HidSharp.Reports.Encodings;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Logitech.HID
|
||||||
|
{
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
public static Span<byte> AsSpan<T>(this ref T val) where T : unmanaged
|
||||||
|
{
|
||||||
|
Span<T> valSpan = MemoryMarshal.CreateSpan(ref val, 1);
|
||||||
|
return MemoryMarshal.Cast<T, byte>(valSpan);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint GetUsagePage(this HidDevice device)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var descriptor = device.GetRawReportDescriptor();
|
||||||
|
var decodedItems = EncodedItem.DecodeItems(descriptor, 0, descriptor.Length);
|
||||||
|
var usefulItems = decodedItems.Where(de => de.TagForLocal == LocalItemTag.Usage && de.TagForGlobal == GlobalItemTag.UsagePage);
|
||||||
|
var usagePage = usefulItems.FirstOrDefault(de => de.ItemType == ItemType.Global);
|
||||||
|
return usagePage.DataValue;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return uint.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint GetUsage(this HidDevice device)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var descriptor = device.GetRawReportDescriptor();
|
||||||
|
var decodedItems = EncodedItem.DecodeItems(descriptor, 0, descriptor.Length);
|
||||||
|
var usefulItems = decodedItems.Where(de => de.TagForLocal == LocalItemTag.Usage && de.TagForGlobal == GlobalItemTag.UsagePage);
|
||||||
|
var usage = usefulItems.FirstOrDefault(de => de.ItemType == ItemType.Local);
|
||||||
|
return usage.DataValue;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return uint.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
73
RGB.NET.Devices.Logitech/HID/FapResponse.cs
Normal file
73
RGB.NET.Devices.Logitech/HID/FapResponse.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Logitech.HID
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 64)]
|
||||||
|
public struct FapResponse
|
||||||
|
{
|
||||||
|
public byte Command;
|
||||||
|
public byte DeviceIndex;
|
||||||
|
public byte FeatureIndex;
|
||||||
|
public byte FeatureCommand;
|
||||||
|
public byte Data00;
|
||||||
|
public byte Data01;
|
||||||
|
public byte Data02;
|
||||||
|
public byte Data03;
|
||||||
|
public byte Data04;
|
||||||
|
public byte Data05;
|
||||||
|
public byte Data06;
|
||||||
|
public byte Data07;
|
||||||
|
public byte Data08;
|
||||||
|
public byte Data09;
|
||||||
|
public byte Data10;
|
||||||
|
public byte Data11;
|
||||||
|
public byte Data12;
|
||||||
|
public byte Data13;
|
||||||
|
public byte Data14;
|
||||||
|
public byte Data15;
|
||||||
|
public byte Data16;
|
||||||
|
public byte Data17;
|
||||||
|
public byte Data18;
|
||||||
|
public byte Data19;
|
||||||
|
public byte Data20;
|
||||||
|
public byte Data21;
|
||||||
|
public byte Data22;
|
||||||
|
public byte Data23;
|
||||||
|
public byte Data24;
|
||||||
|
public byte Data25;
|
||||||
|
public byte Data26;
|
||||||
|
public byte Data27;
|
||||||
|
public byte Data28;
|
||||||
|
public byte Data29;
|
||||||
|
public byte Data30;
|
||||||
|
public byte Data31;
|
||||||
|
public byte Data32;
|
||||||
|
public byte Data33;
|
||||||
|
public byte Data34;
|
||||||
|
public byte Data35;
|
||||||
|
public byte Data36;
|
||||||
|
public byte Data37;
|
||||||
|
public byte Data38;
|
||||||
|
public byte Data39;
|
||||||
|
public byte Data40;
|
||||||
|
public byte Data41;
|
||||||
|
public byte Data42;
|
||||||
|
public byte Data43;
|
||||||
|
public byte Data44;
|
||||||
|
public byte Data45;
|
||||||
|
public byte Data46;
|
||||||
|
public byte Data47;
|
||||||
|
public byte Data48;
|
||||||
|
public byte Data49;
|
||||||
|
public byte Data50;
|
||||||
|
public byte Data51;
|
||||||
|
public byte Data52;
|
||||||
|
public byte Data53;
|
||||||
|
public byte Data54;
|
||||||
|
public byte Data55;
|
||||||
|
public byte Data56;
|
||||||
|
public byte Data57;
|
||||||
|
public byte Data58;
|
||||||
|
public byte Data59;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
RGB.NET.Devices.Logitech/HID/FapShortRequest.cs
Normal file
29
RGB.NET.Devices.Logitech/HID/FapShortRequest.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Logitech.HID
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 7)]
|
||||||
|
public struct FapShortRequest
|
||||||
|
{
|
||||||
|
const byte LOGITECH_SHORT_MESSAGE = 0x10;
|
||||||
|
|
||||||
|
public byte ReportId;
|
||||||
|
public byte DeviceIndex;
|
||||||
|
public byte FeatureIndex;
|
||||||
|
public byte FeatureCommand;
|
||||||
|
public byte Data0;
|
||||||
|
public byte Data1;
|
||||||
|
public byte Data2;
|
||||||
|
|
||||||
|
public void Init(byte deviceIndex, byte featureIndex)
|
||||||
|
{
|
||||||
|
ReportId = LOGITECH_SHORT_MESSAGE;
|
||||||
|
DeviceIndex = deviceIndex;
|
||||||
|
FeatureIndex = featureIndex;
|
||||||
|
FeatureCommand = 0;
|
||||||
|
Data0 = 0;
|
||||||
|
Data1 = 0;
|
||||||
|
Data2 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
191
RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs
Normal file
191
RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
using HidSharp;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
using RGB.NET.HID;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Logitech.HID
|
||||||
|
{
|
||||||
|
public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<TLed, TData>>
|
||||||
|
where TLed : notnull
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the vendor id used for this loader.
|
||||||
|
/// </summary>
|
||||||
|
public int VendorId => 0x046d;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the filter used to determine which devices should be loaded.
|
||||||
|
/// </summary>
|
||||||
|
public RGBDeviceType LoadFilter { get; set; } = RGBDeviceType.All;
|
||||||
|
|
||||||
|
private static List<int> ReceiverPids { get; } = new()
|
||||||
|
{
|
||||||
|
0xC539,
|
||||||
|
0xC53A,
|
||||||
|
0xC541,
|
||||||
|
0xC545
|
||||||
|
};
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a new <see cref="HIDDeviceDefinition{TLed,TData}"/> to this loader.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="virtualPid">The virtual product id of the HID-device.</param>
|
||||||
|
/// <param name="deviceType">The type of the device.</param>
|
||||||
|
/// <param name="name">The name of the device.</param>
|
||||||
|
/// <param name="ledMapping">The mapping of the leds of the device.</param>
|
||||||
|
/// <param name="customData">Some custom data to attach to the device.</param>
|
||||||
|
public void Add(int virtualPid, RGBDeviceType deviceType, string name, LedMapping<TLed> ledMapping, TData customData)
|
||||||
|
=> _deviceDefinitions.Add(virtualPid, new HIDDeviceDefinition<TLed, TData>(virtualPid, deviceType, name, ledMapping, customData));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a enumerable containing all devices from the definition-list that are connected and match the <see cref="LoadFilter"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The enumerable containing the connected devices.</returns>
|
||||||
|
public IEnumerable<HIDDeviceDefinition<TLed, TData>> GetConnectedDevices()
|
||||||
|
{
|
||||||
|
foreach (var device in Detect())
|
||||||
|
{
|
||||||
|
if (_deviceDefinitions.TryGetValue(device, out HIDDeviceDefinition<TLed, TData>? definition))
|
||||||
|
if (LoadFilter.HasFlag(definition.DeviceType))
|
||||||
|
yield return definition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a enumerable containing all the first device of each group of devices from the definition-list that are connected and match the <see cref="LoadFilter"/>.
|
||||||
|
/// The grouping is done by the specified function.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey">The type of the key used to group the devices.</typeparam>
|
||||||
|
/// <param name="groupBy">The function grouping the devices.</param>
|
||||||
|
/// <returns>The enumerable containing the selected devices.</returns>
|
||||||
|
public IEnumerable<HIDDeviceDefinition<TLed, TData>> GetConnectedDevices<TKey>(Func<HIDDeviceDefinition<TLed, TData>, TKey> groupBy)
|
||||||
|
=> GetConnectedDevices().GroupBy(x => groupBy(x))
|
||||||
|
.Select(group => group.First());
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IEnumerator<HIDDeviceDefinition<TLed, TData>> GetEnumerator() => _deviceDefinitions.Values.GetEnumerator();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private IEnumerable<int> Detect()
|
||||||
|
{
|
||||||
|
foreach (var receiverPid in ReceiverPids)
|
||||||
|
{
|
||||||
|
foreach (var wirelessPid in Detect(receiverPid))
|
||||||
|
{
|
||||||
|
yield return wirelessPid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<int> Detect(int pid)
|
||||||
|
{
|
||||||
|
var receiverDevices = DeviceList.Local.GetHidDevices(VendorId, pid);
|
||||||
|
var interfaceTwo = receiverDevices.Where(d => d.DevicePath.Contains("mi_02"));
|
||||||
|
//this is terrible but i don't know how else to filter interfaces
|
||||||
|
|
||||||
|
Dictionary<byte, HidDevice> deviceUsages = new();
|
||||||
|
foreach (var item in interfaceTwo)
|
||||||
|
{
|
||||||
|
deviceUsages.Add((byte)item.GetUsage(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ((var wirelessPid, var deviceIndex) in GetWirelessDevices(deviceUsages))
|
||||||
|
{
|
||||||
|
yield return wirelessPid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, byte> GetWirelessDevices(Dictionary<byte, HidDevice> device_usages)
|
||||||
|
{
|
||||||
|
const byte LOGITECH_RECEIVER_ADDRESS = 0xFF;
|
||||||
|
const byte LOGITECH_SET_REGISTER_REQUEST = 0x80;
|
||||||
|
const byte LOGITECH_GET_REGISTER_REQUEST = 0x81;
|
||||||
|
|
||||||
|
Dictionary<int, byte> map = new();
|
||||||
|
|
||||||
|
if (device_usages.TryGetValue(1, out var device))
|
||||||
|
{
|
||||||
|
var stream = device.Open();
|
||||||
|
|
||||||
|
var response = new FapResponse();
|
||||||
|
|
||||||
|
var getConnectedDevices = new FapShortRequest();
|
||||||
|
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
|
||||||
|
|
||||||
|
stream.Write(getConnectedDevices.AsSpan());
|
||||||
|
stream.Read(response.AsSpan());
|
||||||
|
|
||||||
|
bool wireless_notifications = (response.Data01 & 1) == 1;
|
||||||
|
if (!wireless_notifications)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
|
||||||
|
getConnectedDevices.FeatureCommand = 0x02;
|
||||||
|
|
||||||
|
stream.Write(getConnectedDevices.AsSpan());
|
||||||
|
stream.Read(response.AsSpan());
|
||||||
|
|
||||||
|
int deviceCount = response.Data01;
|
||||||
|
if (deviceCount > 0)
|
||||||
|
{
|
||||||
|
//log "Faking a reconnect to get device list"
|
||||||
|
deviceCount++;
|
||||||
|
|
||||||
|
response = new FapResponse();
|
||||||
|
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
|
||||||
|
getConnectedDevices.FeatureCommand = 0x02;
|
||||||
|
getConnectedDevices.Data0 = 0x02;
|
||||||
|
stream.Write(getConnectedDevices.AsSpan());
|
||||||
|
|
||||||
|
for (int i = 0; i < deviceCount; i++)
|
||||||
|
{
|
||||||
|
var devices = new FapResponse();
|
||||||
|
stream.Read(devices.AsSpan());
|
||||||
|
int wirelessPid = (devices.Data02 << 8) | devices.Data01;
|
||||||
|
if (devices.DeviceIndex != 0xff)
|
||||||
|
{
|
||||||
|
map.Add(wirelessPid, devices.DeviceIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using HidSharp;
|
using HidSharp;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Devices.Logitech.Native;
|
using RGB.NET.Devices.Logitech.Native;
|
||||||
|
using RGB.NET.Devices.Logitech.HID;
|
||||||
using RGB.NET.HID;
|
using RGB.NET.HID;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Logitech
|
namespace RGB.NET.Devices.Logitech
|
||||||
@ -43,51 +44,93 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
private const int VENDOR_ID = 0x046D;
|
private const int VENDOR_ID = 0x046D;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the HID-definitions for per-key-devices.
|
/// Gets the HID-definitions for wired per-key-devices.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static HIDLoader<LogitechLedId, int> PerKeyDeviceDefinitions { get; } = new(VENDOR_ID)
|
public static HIDLoader<LogitechLedId, int> PerKeyDeviceDefinitions { get; } = new(VENDOR_ID)
|
||||||
{
|
{
|
||||||
{ 0xC32B, RGBDeviceType.Keyboard, "G910", LedMappings.PerKey, 0 },
|
{ 0xC32B, RGBDeviceType.Keyboard, "G910", LedMappings.PerKey, 0 },
|
||||||
{ 0xC335, RGBDeviceType.Keyboard, "G910v2", LedMappings.PerKey, 0 },
|
{ 0xC330, RGBDeviceType.Keyboard, "G410", LedMappings.PerKey, 0 },
|
||||||
{ 0xC541, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC33F, RGBDeviceType.Keyboard, "G815", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC337, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC331, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
|
{ 0xC331, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC335, RGBDeviceType.Keyboard, "G910v2", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC337, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC339, RGBDeviceType.Keyboard, "Pro", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC33C, RGBDeviceType.Keyboard, "G513", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC33E, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC33F, RGBDeviceType.Keyboard, "G815", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC342, RGBDeviceType.Keyboard, "G512", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC343, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 },
|
||||||
|
{ 0xC541, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
|
||||||
|
|
||||||
|
//non-rgb
|
||||||
{ 0xC333, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
|
{ 0xC333, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
|
||||||
{ 0xC338, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
|
{ 0xC338, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
|
||||||
{ 0xC342, RGBDeviceType.Keyboard, "G512 SE", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC33C, RGBDeviceType.Keyboard, "G513 Carbon", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC330, RGBDeviceType.Keyboard, "G410", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC339, RGBDeviceType.Keyboard, "Pro", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC343, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 },
|
|
||||||
{ 0xC545, RGBDeviceType.Keyboard, "Lightspeed Keyboard Dongle", LedMappings.PerKey, 0 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the HID-definitions for per-zone-devices.
|
/// Gets the HID-definitions for wireless per-key-devices.
|
||||||
|
/// </summary>
|
||||||
|
public static LightspeedHIDLoader<LogitechLedId, int> PerKeyWirelessDeviceDefinitions { get; } = new()
|
||||||
|
{
|
||||||
|
{ 0x407C, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
|
||||||
|
{ 0x408E, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HID-definitions for wired per-zone-devices.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
|
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
|
||||||
{
|
{
|
||||||
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 2) },
|
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 5) },
|
||||||
{ 0xC086, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC081, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
{ 0xC092, RGBDeviceType.Mouse, "G203 LIGHTSYNC", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||||
{ 0xC539, RGBDeviceType.Mouse, "Lightspeed Mouse Dongle", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC087, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC08B, RGBDeviceType.Mouse, "G502 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC08D, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC332, RGBDeviceType.Mouse, "G502", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC083, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
|
||||||
{ 0xC080, RGBDeviceType.Mouse, "G303", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
|
{ 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) },
|
{ 0xC084, RGBDeviceType.Mouse, "G203", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
|
||||||
{ 0xC085, RGBDeviceType.Mouse, "G Pro", 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) },
|
{ 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) },
|
{ 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) },
|
||||||
|
|
||||||
|
{ 0xC53A, RGBDeviceType.Mousepad, "POWERPLAY", LedMappings.Device, (LogitechDeviceType.Mousemat, 1) },
|
||||||
|
|
||||||
|
//G633 and G635 are wired headsets.
|
||||||
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||||
|
{ 0x0A89, RGBDeviceType.Headset, "G635", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||||
|
|
||||||
|
//The other 3 are wireless. These PIDs correpond to the dongles. They cannot be used wired.
|
||||||
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||||
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
|
||||||
|
{ 0x0AB5, RGBDeviceType.Headset, "G733", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },//fix
|
||||||
|
|
||||||
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4) },
|
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4) },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HID-definitions for wireless per-zone-devices.
|
||||||
|
/// </summary>
|
||||||
|
public static LightspeedHIDLoader<int, (LogitechDeviceType deviceType, int zones)> 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) },
|
||||||
|
{ 0x405F, RGBDeviceType.Mousepad, "POWERPLAY", LedMappings.ZoneMousepad,(LogitechDeviceType.Mousemat, 1) },
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the HID-definitions for per-device-devices.
|
/// Gets the HID-definitions for per-device-devices.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -105,9 +148,14 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
{ 0xC248, RGBDeviceType.Keyboard, "G105", LedMappings.Device, 0 },
|
{ 0xC248, RGBDeviceType.Keyboard, "G105", LedMappings.Device, 0 },
|
||||||
{ 0xC222, RGBDeviceType.Keyboard, "G15", LedMappings.Device, 0 },
|
{ 0xC222, RGBDeviceType.Keyboard, "G15", LedMappings.Device, 0 },
|
||||||
{ 0xC225, RGBDeviceType.Keyboard, "G11", LedMappings.Device, 0 },
|
{ 0xC225, RGBDeviceType.Keyboard, "G11", LedMappings.Device, 0 },
|
||||||
{ 0x0AB5, RGBDeviceType.Headset, "G733", LedMappings.Device, 0 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = new()
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -147,29 +195,31 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
|
|
||||||
return base.GetLoadedDevices(loadFilter);
|
return base.GetLoadedDevices(loadFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||||
{
|
{
|
||||||
(HIDDeviceDefinition<LogitechLedId, int> definition, HidDevice device) perKeyDevice = PerKeyDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
|
HIDDeviceDefinition<LogitechLedId, int>? perKeyDeviceDefinition = PerKeyDeviceDefinitions.GetConnectedDevices().FirstOrDefault().definition ??
|
||||||
if ((_perKeyUpdateQueue != null) && (perKeyDevice != default))
|
PerKeyWirelessDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
|
||||||
|
if ((_perKeyUpdateQueue != null) && (perKeyDeviceDefinition != default))
|
||||||
{
|
{
|
||||||
(HIDDeviceDefinition<LogitechLedId, int> definition, _) = perKeyDevice;
|
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(perKeyDeviceDefinition.DeviceType, perKeyDeviceDefinition.Name, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue, perKeyDeviceDefinition.LedMapping);
|
||||||
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue, definition.LedMapping);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<(HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)> definition, HidDevice device)> perZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices(x => x.CustomData.deviceType);
|
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)>> wiredPerZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices().Select(x => x.definition);
|
||||||
foreach ((HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)> definition, _) in perZoneDevices)
|
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)>> wirelessPerZoneDevices = PerZoneWirelessDeviceDefinitions.GetConnectedDevices();
|
||||||
|
var wiredAndWirelessPerZoneDevices = wiredPerZoneDevices.Concat(wirelessPerZoneDevices);
|
||||||
|
foreach (HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)> definition in wiredAndWirelessPerZoneDevices.GroupBy(x => x.CustomData.deviceType).Select(group => group.First()))
|
||||||
{
|
{
|
||||||
LogitechZoneUpdateQueue updateQueue = new(GetUpdateTrigger(), definition.CustomData.deviceType);
|
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), updateQueue, definition.LedMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
(HIDDeviceDefinition<int, int> definition, HidDevice device) perDeviceDevice = PerDeviceDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
|
HIDDeviceDefinition<int, int>? perDeviceDeviceDefinition = PerDeviceDeviceDefinitions.GetConnectedDevices().FirstOrDefault().definition ??
|
||||||
if ((_perDeviceUpdateQueue != null) && (perDeviceDevice != default))
|
PerDeviceWirelessDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
|
||||||
|
if ((_perDeviceUpdateQueue != null) && (perDeviceDeviceDefinition != default))
|
||||||
{
|
{
|
||||||
(HIDDeviceDefinition<int, int> definition, _) = perDeviceDevice;
|
yield return new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(perDeviceDeviceDefinition.DeviceType, perDeviceDeviceDefinition.Name, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue, perDeviceDeviceDefinition.LedMapping);
|
||||||
yield return new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue, definition.LedMapping);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user