mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 13:06:24 +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:
1 parent
4f48c63ae2
commit
c3edd506cb
14 files changed
+241
-207
No files matched your search
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Core.Layout;
|
||||
using RGB.NET.Devices.Logitech.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Logitech
|
||||
{
|
||||
@@ -56,7 +54,14 @@ namespace RGB.NET.Devices.Logitech
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
|
||||
/// </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>
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Logitech
|
||||
return RGBDeviceLighting.Key;
|
||||
|
||||
if (DeviceCaps.HasFlag(LogitechDeviceCaps.DeviceRGB))
|
||||
return RGBDeviceLighting.Keyboard;
|
||||
return RGBDeviceLighting.Device;
|
||||
|
||||
return RGBDeviceLighting.None;
|
||||
}
|
||||
@@ -43,6 +43,21 @@ namespace RGB.NET.Devices.Logitech
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
#region Constructors
|
||||
@@ -53,11 +68,20 @@ namespace RGB.NET.Devices.Logitech
|
||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The represented device model.</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.Model = model;
|
||||
this.DeviceCaps = deviceCaps;
|
||||
this.ImageBasePath = imageBasePath;
|
||||
this.ImageLayout = imageLayout;
|
||||
this.LayoutPath = layoutPath;
|
||||
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Logitech\{LayoutPath}.png"), UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user