mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Changed logitech devices to better fit the sdk-design. This allows to easily plug in new devices as soon as the hid-id is known
This commit is contained in:
parent
4f48c63ae2
commit
c3edd506cb
@ -18,8 +18,8 @@ namespace RGB.NET.Core
|
|||||||
Key = 1,
|
Key = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="IRGBDevice"/> supports per-keyboard-lightning.
|
/// The <see cref="IRGBDevice"/> supports per-device-lightning.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Keyboard = 2,
|
Device = 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,5 +132,7 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
G_9 = 0xFFF9,
|
G_9 = 0xFFF9,
|
||||||
G_LOGO = 0xFFFF1,
|
G_LOGO = 0xFFFF1,
|
||||||
G_BADGE = 0xFFFF2,
|
G_BADGE = 0xFFFF2,
|
||||||
|
|
||||||
|
DEVICE = 0xFFFFFFF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Core.Layout;
|
using RGB.NET.Core.Layout;
|
||||||
using RGB.NET.Devices.Logitech.Native;
|
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Logitech
|
namespace RGB.NET.Devices.Logitech
|
||||||
{
|
{
|
||||||
@ -56,7 +54,14 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
|
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void InitializeLayout();
|
protected virtual void InitializeLayout()
|
||||||
|
{
|
||||||
|
if (!(DeviceInfo is LogitechRGBDeviceInfo info)) return;
|
||||||
|
string basePath = info.ImageBasePath;
|
||||||
|
string layout = info.ImageLayout;
|
||||||
|
string layoutPath = info.LayoutPath;
|
||||||
|
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Logitech\{basePath}\{layoutPath}.xml"), layout, PathHelper.GetAbsolutePath($@"Images\Logitech\{basePath}"));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the given layout.
|
/// Applies the given layout.
|
||||||
@ -99,35 +104,6 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
|
||||||
{
|
|
||||||
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
|
|
||||||
|
|
||||||
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
|
|
||||||
|
|
||||||
byte[] bitmap = null;
|
|
||||||
foreach (Led led in leds)
|
|
||||||
{
|
|
||||||
//TODO DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
|
|
||||||
if (BitmapMapping.BitmapOffset.TryGetValue(((LogitechLedId)led.Id).LedId, out int bitmapOffset))
|
|
||||||
{
|
|
||||||
if (bitmap == null)
|
|
||||||
bitmap = BitmapMapping.CreateBitmap();
|
|
||||||
|
|
||||||
BitmapMapping.SetColor(ref bitmap, bitmapOffset, led.Color);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)((LogitechLedId)led.Id).LedId,
|
|
||||||
(int)Math.Round(led.Color.RPercent * 100),
|
|
||||||
(int)Math.Round(led.Color.GPercent * 100),
|
|
||||||
(int)Math.Round(led.Color.BPercent * 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bitmap != null)
|
|
||||||
_LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
return RGBDeviceLighting.Key;
|
return RGBDeviceLighting.Key;
|
||||||
|
|
||||||
if (DeviceCaps.HasFlag(LogitechDeviceCaps.DeviceRGB))
|
if (DeviceCaps.HasFlag(LogitechDeviceCaps.DeviceRGB))
|
||||||
return RGBDeviceLighting.Keyboard;
|
return RGBDeviceLighting.Device;
|
||||||
|
|
||||||
return RGBDeviceLighting.None;
|
return RGBDeviceLighting.None;
|
||||||
}
|
}
|
||||||
@ -43,6 +43,21 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public LogitechDeviceCaps DeviceCaps { get; }
|
public LogitechDeviceCaps DeviceCaps { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base of the image path used to load device-images.
|
||||||
|
/// </summary>
|
||||||
|
internal string ImageBasePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the layout used to decide which images to load.
|
||||||
|
/// </summary>
|
||||||
|
internal string ImageLayout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path/name of the layout-file.
|
||||||
|
/// </summary>
|
||||||
|
internal string LayoutPath { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -53,11 +68,20 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||||
/// <param name="model">The represented device model.</param>
|
/// <param name="model">The represented device model.</param>
|
||||||
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
|
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
|
||||||
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps)
|
/// <param name="imageBasePath">The base of the image path used to load device-images.</param>
|
||||||
|
/// <param name="imageLayout">The layout used to decide which images to load.</param>
|
||||||
|
/// <param name="layoutPath">The path/name of the layout-file.</param>
|
||||||
|
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps,
|
||||||
|
string imageBasePath, string imageLayout, string layoutPath)
|
||||||
{
|
{
|
||||||
this.DeviceType = deviceType;
|
this.DeviceType = deviceType;
|
||||||
this.Model = model;
|
this.Model = model;
|
||||||
this.DeviceCaps = deviceCaps;
|
this.DeviceCaps = deviceCaps;
|
||||||
|
this.ImageBasePath = imageBasePath;
|
||||||
|
this.ImageLayout = imageLayout;
|
||||||
|
this.LayoutPath = layoutPath;
|
||||||
|
|
||||||
|
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Logitech\{LayoutPath}.png"), UriKind.Absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using HidSharp;
|
using HidSharp;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Logitech.HID
|
namespace RGB.NET.Devices.Logitech.HID
|
||||||
{
|
{
|
||||||
@ -8,31 +10,31 @@ namespace RGB.NET.Devices.Logitech.HID
|
|||||||
{
|
{
|
||||||
#region Constants
|
#region Constants
|
||||||
|
|
||||||
//TODO DarthAffe 04.02.2017: Add IDs
|
|
||||||
private const int VENDOR_ID = 0x046D;
|
private const int VENDOR_ID = 0x046D;
|
||||||
private const int G910_ID = 0xC32B;
|
|
||||||
private const int G810_ID = 0x0;
|
//TODO DarthAffe 14.11.2017: Add devices
|
||||||
private const int G610_ID = 0xC333;
|
private static readonly List<(string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath)> PER_KEY_DEVICES
|
||||||
|
= new List<(string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath)>
|
||||||
|
{
|
||||||
|
("G910", RGBDeviceType.Keyboard, 0xC32B, "", "", ""),
|
||||||
|
("G910", RGBDeviceType.Keyboard, 0xC333, "", "", ""),
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly List<(string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath)> PER_DEVICE_DEVICES
|
||||||
|
= new List<(string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath)>
|
||||||
|
{
|
||||||
|
("G403", RGBDeviceType.Mouse, 0xC083, "", "", ""),
|
||||||
|
};
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
public static string ConnectedDeviceModel
|
public static bool IsPerKeyDeviceConnected { get; private set; }
|
||||||
{
|
public static (string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath) PerKeyDeviceData { get; private set; }
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsG910Connected) return "G910";
|
|
||||||
if (IsG810Connected) return "G810";
|
|
||||||
if (IsG610Connected) return "G610";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsDeviceConnected => IsG910Connected || IsG810Connected || IsG610Connected;
|
public static bool IsPerDeviceDeviceConnected { get; private set; }
|
||||||
public static bool IsG910Connected { get; private set; }
|
public static (string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath) PerDeviceDeviceData { get; private set; }
|
||||||
public static bool IsG810Connected { get; private set; }
|
|
||||||
public static bool IsG610Connected { get; private set; }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -40,21 +42,23 @@ namespace RGB.NET.Devices.Logitech.HID
|
|||||||
|
|
||||||
internal static void LoadDeviceList()
|
internal static void LoadDeviceList()
|
||||||
{
|
{
|
||||||
IsG910Connected = false;
|
|
||||||
IsG810Connected = false;
|
|
||||||
IsG610Connected = false;
|
|
||||||
|
|
||||||
HidDeviceLoader loader = new HidDeviceLoader();
|
HidDeviceLoader loader = new HidDeviceLoader();
|
||||||
IEnumerable<HidDevice> devices = loader.GetDevices();
|
List<int> ids = loader.GetDevices(VENDOR_ID).Select(x => x.ProductID).Distinct().ToList();
|
||||||
foreach (HidDevice hidDevice in devices)
|
|
||||||
if (hidDevice.VendorID == VENDOR_ID)
|
foreach ((string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath) deviceData in PER_KEY_DEVICES)
|
||||||
|
if (ids.Contains(deviceData.id))
|
||||||
{
|
{
|
||||||
if (hidDevice.ProductID == G910_ID)
|
IsPerKeyDeviceConnected = true;
|
||||||
IsG910Connected = true;
|
PerKeyDeviceData = deviceData;
|
||||||
else if (hidDevice.ProductID == G810_ID)
|
break;
|
||||||
IsG810Connected = true;
|
}
|
||||||
else if (hidDevice.ProductID == G610_ID)
|
|
||||||
IsG610Connected = true;
|
foreach ((string model, RGBDeviceType deviceType, int id, string imageBasePath, string imageLayout, string layoutPath) deviceData in PER_DEVICE_DEVICES)
|
||||||
|
if (ids.Contains(deviceData.id))
|
||||||
|
{
|
||||||
|
IsPerDeviceDeviceConnected = true;
|
||||||
|
PerDeviceDeviceData = deviceData;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -153,10 +153,7 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static byte[] CreateBitmap()
|
internal static byte[] CreateBitmap() => new byte[BITMAP_SIZE];
|
||||||
{
|
|
||||||
return new byte[BITMAP_SIZE];
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static void SetColor(ref byte[] bitmap, int offset, Color color)
|
internal static void SetColor(ref byte[] bitmap, int offset, Color color)
|
||||||
|
|||||||
@ -1,51 +0,0 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
|
||||||
// ReSharper disable UnusedMember.Global
|
|
||||||
|
|
||||||
using RGB.NET.Core;
|
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Logitech
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a logitech keyboard.
|
|
||||||
/// </summary>
|
|
||||||
public class LogitechKeyboardRGBDevice : LogitechRGBDevice
|
|
||||||
{
|
|
||||||
#region Properties & Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets information about the <see cref="LogitechKeyboardRGBDevice"/>.
|
|
||||||
/// </summary>
|
|
||||||
public LogitechKeyboardRGBDeviceInfo KeyboardDeviceInfo { get; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechKeyboardRGBDevice" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="info">The specific information provided by logitech for the keyboard</param>
|
|
||||||
internal LogitechKeyboardRGBDevice(LogitechKeyboardRGBDeviceInfo info)
|
|
||||||
: base(info)
|
|
||||||
{
|
|
||||||
this.KeyboardDeviceInfo = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void InitializeLayout()
|
|
||||||
{
|
|
||||||
string model = KeyboardDeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
|
||||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
|
||||||
$@"Layouts\Logitech\Keyboards\{model}\{KeyboardDeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"),
|
|
||||||
KeyboardDeviceInfo.LogicalLayout.ToString(), PathHelper.GetAbsolutePath(@"Images\Logitech\Keyboards"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
|
||||||
// ReSharper disable UnusedMember.Global
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using RGB.NET.Core;
|
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Logitech
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Logitech.LogitechKeyboardRGBDevice" />.
|
|
||||||
/// </summary>
|
|
||||||
public class LogitechKeyboardRGBDeviceInfo : LogitechRGBDeviceInfo
|
|
||||||
{
|
|
||||||
#region Properties & Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the physical layout of the keyboard.
|
|
||||||
/// </summary>
|
|
||||||
public LogitechPhysicalKeyboardLayout PhysicalLayout { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the logical layout of the keyboard.
|
|
||||||
/// </summary>
|
|
||||||
public LogitechLogicalKeyboardLayout LogicalLayout { get; private set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
/// <summary>
|
|
||||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Logitech.LogitechKeyboardRGBDeviceInfo" />.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model">The represented device model.</param>
|
|
||||||
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
|
|
||||||
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using</param>
|
|
||||||
internal LogitechKeyboardRGBDeviceInfo(string model, LogitechDeviceCaps deviceCaps, CultureInfo culture)
|
|
||||||
: base(RGBDeviceType.Keyboard, model, deviceCaps)
|
|
||||||
{
|
|
||||||
SetLayouts(culture.KeyboardLayoutId);
|
|
||||||
|
|
||||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Logitech\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
private void SetLayouts(int keyboardLayoutId)
|
|
||||||
{
|
|
||||||
switch (keyboardLayoutId)
|
|
||||||
{
|
|
||||||
//TODO DarthAffe 04.02.2017: Check all available keyboards and there layout-ids
|
|
||||||
default:
|
|
||||||
PhysicalLayout = LogitechPhysicalKeyboardLayout.UK;
|
|
||||||
LogicalLayout = LogitechLogicalKeyboardLayout.DE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -8,6 +8,7 @@ using System.Globalization;
|
|||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Devices.Logitech.HID;
|
using RGB.NET.Devices.Logitech.HID;
|
||||||
using RGB.NET.Devices.Logitech.Native;
|
using RGB.NET.Devices.Logitech.Native;
|
||||||
|
using RGB.NET.Devices.Logitech.PerKey;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Logitech
|
namespace RGB.NET.Devices.Logitech
|
||||||
{
|
{
|
||||||
@ -66,7 +67,7 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
|
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
|
||||||
public LogitechDeviceProvider()
|
public LogitechDeviceProvider()
|
||||||
{
|
{
|
||||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instanc of type {nameof(LogitechDeviceProvider)}");
|
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
|
||||||
_instance = this;
|
_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,25 +96,22 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
_LogitechGSDK.LogiLedSaveCurrentLighting();
|
_LogitechGSDK.LogiLedSaveCurrentLighting();
|
||||||
|
|
||||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||||
|
|
||||||
DeviceChecker.LoadDeviceList();
|
DeviceChecker.LoadDeviceList();
|
||||||
if (DeviceChecker.IsDeviceConnected)
|
|
||||||
{
|
|
||||||
LogitechRGBDevice device = new LogitechKeyboardRGBDevice(new LogitechKeyboardRGBDeviceInfo(
|
|
||||||
DeviceChecker.ConnectedDeviceModel, LogitechDeviceCaps.PerKeyRGB, GetCulture()));
|
|
||||||
devices.Add(device);
|
|
||||||
|
|
||||||
try
|
if (DeviceChecker.IsPerKeyDeviceConnected)
|
||||||
{
|
{
|
||||||
device.Initialize();
|
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
|
||||||
}
|
LogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, imageBasePath, imageLayout, layoutPath));
|
||||||
catch
|
devices.Add(device);
|
||||||
{
|
|
||||||
if (throwExceptions)
|
|
||||||
throw;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DeviceChecker.IsPerDeviceDeviceConnected)
|
||||||
|
{
|
||||||
|
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
|
||||||
|
LogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, imageBasePath, imageLayout, layoutPath));
|
||||||
|
devices.Add(device);
|
||||||
|
}
|
||||||
|
|
||||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@ -49,6 +49,7 @@ namespace RGB.NET.Devices.Logitech.Native
|
|||||||
_logiLedGetSdkVersionPointer = (LogiLedGetSdkVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedGetSdkVersion"), typeof(LogiLedGetSdkVersionPointer));
|
_logiLedGetSdkVersionPointer = (LogiLedGetSdkVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedGetSdkVersion"), typeof(LogiLedGetSdkVersionPointer));
|
||||||
_lgiLedSaveCurrentLightingPointer = (LogiLedSaveCurrentLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSaveCurrentLighting"), typeof(LogiLedSaveCurrentLightingPointer));
|
_lgiLedSaveCurrentLightingPointer = (LogiLedSaveCurrentLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSaveCurrentLighting"), typeof(LogiLedSaveCurrentLightingPointer));
|
||||||
_logiLedRestoreLightingPointer = (LogiLedRestoreLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedRestoreLighting"), typeof(LogiLedRestoreLightingPointer));
|
_logiLedRestoreLightingPointer = (LogiLedRestoreLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedRestoreLighting"), typeof(LogiLedRestoreLightingPointer));
|
||||||
|
_logiLedSetLightingPointer = (LogiLedSetLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLighting"), typeof(LogiLedSetLightingPointer));
|
||||||
_logiLedSetLightingForKeyWithKeyNamePointer = (LogiLedSetLightingForKeyWithKeyNamePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForKeyWithKeyName"), typeof(LogiLedSetLightingForKeyWithKeyNamePointer));
|
_logiLedSetLightingForKeyWithKeyNamePointer = (LogiLedSetLightingForKeyWithKeyNamePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForKeyWithKeyName"), typeof(LogiLedSetLightingForKeyWithKeyNamePointer));
|
||||||
_logiLedSetLightingFromBitmapPointer = (LogiLedSetLightingFromBitmapPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingFromBitmap"), typeof(LogiLedSetLightingFromBitmapPointer));
|
_logiLedSetLightingFromBitmapPointer = (LogiLedSetLightingFromBitmapPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingFromBitmap"), typeof(LogiLedSetLightingFromBitmapPointer));
|
||||||
}
|
}
|
||||||
@ -85,6 +86,7 @@ namespace RGB.NET.Devices.Logitech.Native
|
|||||||
private static LogiLedGetSdkVersionPointer _logiLedGetSdkVersionPointer;
|
private static LogiLedGetSdkVersionPointer _logiLedGetSdkVersionPointer;
|
||||||
private static LogiLedSaveCurrentLightingPointer _lgiLedSaveCurrentLightingPointer;
|
private static LogiLedSaveCurrentLightingPointer _lgiLedSaveCurrentLightingPointer;
|
||||||
private static LogiLedRestoreLightingPointer _logiLedRestoreLightingPointer;
|
private static LogiLedRestoreLightingPointer _logiLedRestoreLightingPointer;
|
||||||
|
private static LogiLedSetLightingPointer _logiLedSetLightingPointer;
|
||||||
private static LogiLedSetLightingForKeyWithKeyNamePointer _logiLedSetLightingForKeyWithKeyNamePointer;
|
private static LogiLedSetLightingForKeyWithKeyNamePointer _logiLedSetLightingForKeyWithKeyNamePointer;
|
||||||
private static LogiLedSetLightingFromBitmapPointer _logiLedSetLightingFromBitmapPointer;
|
private static LogiLedSetLightingFromBitmapPointer _logiLedSetLightingFromBitmapPointer;
|
||||||
|
|
||||||
@ -110,6 +112,9 @@ namespace RGB.NET.Devices.Logitech.Native
|
|||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
private delegate bool LogiLedRestoreLightingPointer();
|
private delegate bool LogiLedRestoreLightingPointer();
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
private delegate bool LogiLedSetLightingPointer(int redPercentage, int greenPercentage, int bluePercentage);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
private delegate bool LogiLedSetLightingForKeyWithKeyNamePointer(int keyCode, int redPercentage, int greenPercentage, int bluePercentage);
|
private delegate bool LogiLedSetLightingForKeyWithKeyNamePointer(int keyCode, int redPercentage, int greenPercentage, int bluePercentage);
|
||||||
|
|
||||||
@ -160,6 +165,11 @@ namespace RGB.NET.Devices.Logitech.Native
|
|||||||
return _logiLedRestoreLightingPointer();
|
return _logiLedRestoreLightingPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage)
|
||||||
|
{
|
||||||
|
return _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage);
|
||||||
|
}
|
||||||
|
|
||||||
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode,
|
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode,
|
||||||
int redPercentage, int greenPercentage, int bluePercentage)
|
int redPercentage, int greenPercentage, int bluePercentage)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
using RGB.NET.Devices.Logitech.Native;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Logitech.PerDevice
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a logitech per-device-lightable device.
|
||||||
|
/// </summary>
|
||||||
|
public class LogitechPerDeviceRGBDevice : LogitechRGBDevice
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets information about the <see cref="LogitechPerDeviceRGBDevice"/>.
|
||||||
|
/// </summary>
|
||||||
|
public LogitechRGBDeviceInfo PerDeviceDeviceInfo { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerDeviceRGBDevice" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">The specific information provided by logitech for the per-device-lightable device</param>
|
||||||
|
internal LogitechPerDeviceRGBDevice(LogitechRGBDeviceInfo info)
|
||||||
|
: base(info)
|
||||||
|
{
|
||||||
|
this.PerDeviceDeviceInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void InitializeLayout()
|
||||||
|
{
|
||||||
|
base.InitializeLayout();
|
||||||
|
|
||||||
|
if (LedMapping.Count == 0)
|
||||||
|
InitializeLed(new LogitechLedId(this, LogitechLedIds.DEVICE), new Rectangle(0, 0, 1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||||
|
{
|
||||||
|
Led led = ledsToUpdate.FirstOrDefault(x => x.Color.A > 0);
|
||||||
|
if (led == null) return;
|
||||||
|
|
||||||
|
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
|
||||||
|
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(led.Color.RPercent * 100),
|
||||||
|
(int)Math.Round(led.Color.GPercent * 100),
|
||||||
|
(int)Math.Round(led.Color.BPercent * 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
73
RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs
Normal file
73
RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
using RGB.NET.Devices.Logitech.Native;
|
||||||
|
|
||||||
|
namespace RGB.NET.Devices.Logitech.PerKey
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a logitech per-key-lightable device.
|
||||||
|
/// </summary>
|
||||||
|
public class LogitechPerKeyRGBDevice : LogitechRGBDevice
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets information about the <see cref="LogitechPerKeyRGBDevice"/>.
|
||||||
|
/// </summary>
|
||||||
|
public LogitechRGBDeviceInfo PerKeyDeviceInfo { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerKeyRGBDevice" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">The specific information provided by logitech for the per-key-lightable device</param>
|
||||||
|
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info)
|
||||||
|
: base(info)
|
||||||
|
{
|
||||||
|
this.PerKeyDeviceInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||||
|
{
|
||||||
|
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
|
||||||
|
if (leds.Count <= 0) return;
|
||||||
|
|
||||||
|
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
|
||||||
|
|
||||||
|
byte[] bitmap = null;
|
||||||
|
foreach (Led led in leds)
|
||||||
|
{
|
||||||
|
// DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
|
||||||
|
if (BitmapMapping.BitmapOffset.TryGetValue(((LogitechLedId)led.Id).LedId, out int bitmapOffset))
|
||||||
|
{
|
||||||
|
if (bitmap == null)
|
||||||
|
bitmap = BitmapMapping.CreateBitmap();
|
||||||
|
|
||||||
|
BitmapMapping.SetColor(ref bitmap, bitmapOffset, led.Color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)((LogitechLedId)led.Id).LedId,
|
||||||
|
(int)Math.Round(led.Color.RPercent * 100),
|
||||||
|
(int)Math.Round(led.Color.GPercent * 100),
|
||||||
|
(int)Math.Round(led.Color.BPercent * 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bitmap != null)
|
||||||
|
_LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -58,10 +58,10 @@
|
|||||||
<Compile Include="Generic\LogitechRGBDeviceInfo.cs" />
|
<Compile Include="Generic\LogitechRGBDeviceInfo.cs" />
|
||||||
<Compile Include="Helper\BitmapMapping.cs" />
|
<Compile Include="Helper\BitmapMapping.cs" />
|
||||||
<Compile Include="HID\DeviceChecker.cs" />
|
<Compile Include="HID\DeviceChecker.cs" />
|
||||||
<Compile Include="Keyboard\LogitechKeyboardRGBDevice.cs" />
|
|
||||||
<Compile Include="Keyboard\LogitechKeyboardRGBDeviceInfo.cs" />
|
|
||||||
<Compile Include="LogitechDeviceProvider.cs" />
|
<Compile Include="LogitechDeviceProvider.cs" />
|
||||||
<Compile Include="Native\_LogitechGSDK.cs" />
|
<Compile Include="Native\_LogitechGSDK.cs" />
|
||||||
|
<Compile Include="PerDevice\LogitechPerDeviceRGBDevice.cs" />
|
||||||
|
<Compile Include="PerKey\LogitechPerKeyRGBDevice.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -200,6 +200,7 @@
|
|||||||
<Content Include="libs\x64\LogitechLedEnginesWrapper.dll" />
|
<Content Include="libs\x64\LogitechLedEnginesWrapper.dll" />
|
||||||
<Content Include="libs\x86\LogitechLedEnginesWrapper.dll" />
|
<Content Include="libs\x86\LogitechLedEnginesWrapper.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@ -2,4 +2,5 @@
|
|||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enum/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enum/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
Loading…
x
Reference in New Issue
Block a user