1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Added logitech support (unfinished: HID-Ids and layouts are missing)

This commit is contained in:
Darth Affe 2017-02-04 17:09:00 +01:00
parent 5bd1012fbe
commit 2af55146cc
22 changed files with 1310 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>RGB.NET.Devices.Logitech</id>
<title>CUE.NET.Devices.Logitech</title>
<version>1.0.0.0</version>
<authors>Darth Affe</authors>
<owners>Darth Affe</owners>
<projectUrl>https://github.com/DarthAffe/RGB.NET</projectUrl>
<licenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Logitech-Device-Implementations of RGB.NET</description>
<releaseNotes></releaseNotes>
<summary>Logitech-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</summary>
<copyright>Copyright © Wyrez 2017</copyright>
<language>en-US</language>
<dependencies>
<dependency id="RGB.NET.Core" version="1.0" />
</dependencies>
</metadata>
<files>
<file src="..\bin\RGB.NET.Devices.Logitech.dll" target="lib\net45\RGB.NET.Devices.Logitech.dll" />
<file src="..\bin\RGB.NET.Devices.Logitech.pdb" target="lib\net45\RGB.NET.Devices.Logitech.pdb" />
<file src="..\bin\RGB.NET.Devices.Logitech.xml" target="lib\net45\RGB.NET.Devices.Logitech.xml" />
<file src="..\RGB.NET.Devices.Logitech\**\*.cs" target="src" exclude="..\RGB.NET.Devices.Logitech\obj\**\*.*" />
<file src="..\RGB.NET.Devices.Logitech\Images\**\*.*" target="build\net45\resources\Images\" />
<file src="..\RGB.NET.Devices.Logitech\Layouts\**\*.*" target="build\net45\resources\Layouts\" />
<file src="..\RGB.NET.Devices.Logitech\libs\**\*.*" target="build\net45\libs\" />
<file src="..\RGB.NET.Devices.Logitech\targets\*.targets" target="build\net45\" />
</files>
</package>

View File

@ -0,0 +1,18 @@
// ReSharper disable InconsistentNaming
using System;
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Logitech
{
[Flags]
public enum LogitechDeviceCaps
{
None = 0,
Monochrome = 1 << 0,
DeviceRGB = 1 << 1,
PerKeyRGB = 1 << 2,
All = Monochrome | DeviceRGB | PerKeyRGB
}
}

View File

@ -0,0 +1,129 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains list of all LEDs available for all logitech devices.
/// </summary>
public enum LogitechLedIds
{
Invalid = 0,
ESC = 0x01,
F1 = 0x3b,
F2 = 0x3c,
F3 = 0x3d,
F4 = 0x3e,
F5 = 0x3f,
F6 = 0x40,
F7 = 0x41,
F8 = 0x42,
F9 = 0x43,
F10 = 0x44,
F11 = 0x57,
F12 = 0x58,
PRINT_SCREEN = 0x137,
SCROLL_LOCK = 0x46,
PAUSE_BREAK = 0x45,
TILDE = 0x29,
ONE = 0x02,
TWO = 0x03,
THREE = 0x04,
FOUR = 0x05,
FIVE = 0x06,
SIX = 0x07,
SEVEN = 0x08,
EIGHT = 0x09,
NINE = 0x0A,
ZERO = 0x0B,
MINUS = 0x0C,
EQUALS = 0x0D,
BACKSPACE = 0x0E,
INSERT = 0x152,
HOME = 0x147,
PAGE_UP = 0x149,
NUM_LOCK = 0x145,
NUM_SLASH = 0x135,
NUM_ASTERISK = 0x37,
NUM_MINUS = 0x4A,
TAB = 0x0F,
Q = 0x10,
W = 0x11,
E = 0x12,
R = 0x13,
T = 0x14,
Y = 0x15,
U = 0x16,
I = 0x17,
O = 0x18,
P = 0x19,
OPEN_BRACKET = 0x1A,
CLOSE_BRACKET = 0x1B,
BACKSLASH = 0x2B,
KEYBOARD_DELETE = 0x153,
END = 0x14F,
PAGE_DOWN = 0x151,
NUM_SEVEN = 0x47,
NUM_EIGHT = 0x48,
NUM_NINE = 0x49,
NUM_PLUS = 0x4E,
CAPS_LOCK = 0x3A,
A = 0x1E,
S = 0x1F,
D = 0x20,
F = 0x21,
G = 0x22,
H = 0x23,
J = 0x24,
K = 0x25,
L = 0x26,
SEMICOLON = 0x27,
APOSTROPHE = 0x28,
ENTER = 0x1C,
NUM_FOUR = 0x4B,
NUM_FIVE = 0x4C,
NUM_SIX = 0x4D,
LEFT_SHIFT = 0x2A,
Z = 0x2C,
X = 0x2D,
C = 0x2E,
V = 0x2F,
B = 0x30,
N = 0x31,
M = 0x32,
COMMA = 0x33,
PERIOD = 0x34,
FORWARD_SLASH = 0x35,
RIGHT_SHIFT = 0x36,
ARROW_UP = 0x148,
NUM_ONE = 0x4F,
NUM_TWO = 0x50,
NUM_THREE = 0x51,
NUM_ENTER = 0x11C,
LEFT_CONTROL = 0x1D,
LEFT_WINDOWS = 0x15B,
LEFT_ALT = 0x38,
SPACE = 0x39,
RIGHT_ALT = 0x138,
RIGHT_WINDOWS = 0x15C,
APPLICATION_SELECT = 0x15D,
RIGHT_CONTROL = 0x11D,
ARROW_LEFT = 0x14B,
ARROW_DOWN = 0x150,
ARROW_RIGHT = 0x14D,
NUM_ZERO = 0x52,
NUM_PERIOD = 0x53,
G_1 = 0xFFF1,
G_2 = 0xFFF2,
G_3 = 0xFFF3,
G_4 = 0xFFF4,
G_5 = 0xFFF5,
G_6 = 0xFFF6,
G_7 = 0xFFF7,
G_8 = 0xFFF8,
G_9 = 0xFFF9,
G_LOGO = 0xFFFF1,
G_BADGE = 0xFFFF2,
}
}

View File

@ -0,0 +1,32 @@
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains list of available logical layouts for logitech keyboards.
/// </summary>
public enum LogitechLogicalKeyboardLayout
{
US_Int = 1,
NA = 2,
EU = 3,
UK = 4,
BE = 5,
BR = 6,
CH = 7,
CN = 8,
DE = 9,
ES = 10,
FR = 11,
IT = 12,
ND = 13,
RU = 14,
JP = 15,
KR = 16,
TW = 17,
MEX = 18
};
}

View File

@ -0,0 +1,36 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable InconsistentNaming
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains list of available physical layouts for logitech keyboards.
/// </summary>
public enum LogitechPhysicalKeyboardLayout
{
/// <summary>
/// US-Keyboard
/// </summary>
US = 1,
/// <summary>
/// UK-Keyboard
/// </summary>
UK = 2,
/// <summary>
/// BR-Keyboard
/// </summary>
BR = 3,
/// <summary>
/// JP-Keyboard
/// </summary>
JP = 4,
/// <summary>
/// KR-Keyboard
/// </summary>
KR = 5
}
}

View File

@ -0,0 +1,107 @@
using System.Diagnostics;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents a Id of a <see cref="Led"/> on a <see cref="LogitechRGBDevice"/>.
/// </summary>
[DebuggerDisplay("{" + nameof(LedId) + "}")]
public class LogitechLedId : ILedId
{
#region Properties & Fields
internal readonly LogitechLedIds LedId;
/// <inheritdoc />
public IRGBDevice Device { get; }
/// <inheritdoc />
public bool IsValid => LedId != LogitechLedIds.Invalid;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LogitechLedId"/> class.
/// </summary>
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
/// <param name="ledId">The <see cref="LogitechLedId"/> of the represented <see cref="Led"/>.</param>
public LogitechLedId(IRGBDevice device, LogitechLedIds ledId)
{
this.Device = device;
this.LedId = ledId;
}
#endregion
#region Methods
/// <summary>
/// Converts the Id of this <see cref="LogitechLedId"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the Id of this <see cref="LogitechLedId"/>. For example "Enter".</returns>
public override string ToString()
{
return LedId.ToString();
}
/// <summary>
/// Tests whether the specified object is a <see cref="LogitechLedId" /> and is equivalent to this <see cref="LogitechLedId" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="LogitechLedId" /> equivalent to this <see cref="LogitechLedId" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
LogitechLedId compareLedId = obj as LogitechLedId;
if (ReferenceEquals(compareLedId, null))
return false;
if (ReferenceEquals(this, compareLedId))
return true;
if (GetType() != compareLedId.GetType())
return false;
return compareLedId.LedId == LedId;
}
/// <summary>
/// Returns a hash code for this <see cref="LogitechLedId" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="LogitechLedId" />.</returns>
public override int GetHashCode()
{
return LedId.GetHashCode();
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="LogitechLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="LogitechLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="LogitechLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(LogitechLedId ledId1, LogitechLedId ledId2)
{
return ReferenceEquals(ledId1, null) ? ReferenceEquals(ledId2, null) : ledId1.Equals(ledId2);
}
/// <summary>
/// Returns a value that indicates whether two specified <see cref="LogitechLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="LogitechLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="LogitechLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(LogitechLedId ledId1, LogitechLedId ledId2)
{
return !(ledId1 == ledId2);
}
#endregion
}
}

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents a generic Logitech-device. (keyboard, mouse, headset, mousmat).
/// </summary>
public abstract class LogitechRGBDevice : AbstractRGBDevice
{
#region Properties & Fields
/// <summary>
/// Gets information about the <see cref="LogitechRGBDevice"/>.
/// </summary>
public override IRGBDeviceInfo DeviceInfo { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LogitechRGBDevice"/> class.
/// </summary>
/// <param name="info">The generic information provided by Logitech for the device.</param>
protected LogitechRGBDevice(IRGBDeviceInfo info)
{
this.DeviceInfo = info;
}
#endregion
#region Methods
/// <summary>
/// Initializes the device.
/// </summary>
internal void Initialize()
{
InitializeLayout();
if (InternalSize == null)
{
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
}
/// <summary>
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
/// </summary>
protected abstract void InitializeLayout();
/// <summary>
/// Applies the given layout.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
protected void ApplyLayoutFromFile(string layoutPath)
{
DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null)
{
InternalSize = new Size(layout.Width, layout.Height);
if (layout.Leds != null)
foreach (LedLayout layoutLed in layout.Leds)
{
LogitechLedIds ledId;
if (Enum.TryParse(layoutLed.Id, true, out ledId))
{
LogitechLedId id = new LogitechLedId(this, ledId);
Led led;
if (!LedMapping.TryGetValue(id, out led))
led = InitializeLed(id, new Rectangle());
led.LedRectangle.Location.X = layoutLed.X;
led.LedRectangle.Location.Y = layoutLed.Y;
led.LedRectangle.Size.Width = layoutLed.Width;
led.LedRectangle.Size.Height = layoutLed.Height;
led.Shape = layoutLed.Shape;
}
}
}
}
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
foreach (Led led in leds)
_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));
}
#endregion
}
}

View File

@ -0,0 +1,64 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents a generic information for a Logitech-<see cref="IRGBDevice"/>.
/// </summary>
public class LogitechRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string Manufacturer => "Logitech";
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public Uri Image { get; protected set; }
/// <inheritdoc />
public RGBDeviceLighting Lighting
{
get
{
if (DeviceCaps.HasFlag(LogitechDeviceCaps.PerKeyRGB))
return RGBDeviceLighting.Key;
if (DeviceCaps.HasFlag(LogitechDeviceCaps.DeviceRGB))
return RGBDeviceLighting.Keyboard;
return RGBDeviceLighting.None;
}
}
/// <summary>
/// Gets a flag that describes device capabilities. (<see cref="LogitechDeviceCaps" />)
/// </summary>
public LogitechDeviceCaps DeviceCaps { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="LogitechRGBDeviceInfo"/>.
/// </summary>
/// <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)
{
this.DeviceType = deviceType;
this.Model = model;
this.DeviceCaps = deviceCaps;
}
#endregion
}
}

View File

@ -0,0 +1,57 @@
using System.Collections.Generic;
using HidSharp;
namespace RGB.NET.Devices.Logitech.HID
{
//TODO DarthAffe 04.02.2017: Rewrite this once the SDK supports per-device lighting to get all the devices connected.
internal static class DeviceChecker
{
#region Constants
//TODO DarthAffe 04.02.2017: Add IDs
private const int VENDOR_ID = 0x0;
private const int G910_ID = 0x0;
private const int G810_ID = 0x0;
#endregion
#region Properties & Fields
public static string ConnectedDeviceModel
{
get
{
if (IsG910Connected) return "G910";
if (IsG810Connected) return "G810";
return null;
}
}
public static bool IsDeviceConnected => IsG910Connected || IsG810Connected;
public static bool IsG910Connected { get; private set; }
public static bool IsG810Connected { get; private set; }
#endregion
#region Methods
internal static void LoadDeviceList()
{
IsG910Connected = false;
IsG810Connected = false;
HidDeviceLoader loader = new HidDeviceLoader();
IEnumerable<HidDevice> devices = loader.GetDevices();
foreach (HidDevice hidDevice in devices)
if (hidDevice.VendorID == VENDOR_ID)
{
if (hidDevice.ProductID == G910_ID)
IsG910Connected = true;
else if (hidDevice.ProductID == G810_ID)
IsG810Connected = true;
}
}
#endregion
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Globalization;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Offers some helper-methods for culture related things.
/// </summary>
public static class CultureHelper
{
#region DLLImports
[DllImport("user32.dll")]
static extern IntPtr GetKeyboardLayout(uint thread);
#endregion
#region Constructors
#endregion
#region Methods
/// <summary>
/// Gets the current keyboard-layout from the OS.
/// </summary>
/// <returns>The current keyboard-layout</returns>
public static CultureInfo GetCurrentCulture()
{
try
{
int keyboardLayout = GetKeyboardLayout(0).ToInt32() & 0xFFFF;
return new CultureInfo(keyboardLayout);
}
catch
{
return new CultureInfo(1033); // en-US on error.
}
}
#endregion
}
}

View File

@ -0,0 +1,49 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.IO;
using System.Reflection;
namespace RGB.NET.Devices.Logitech
{
/// <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
/// <summary>
/// Initializes a new instance of the <see cref="LogitechKeyboardRGBDevice"/> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the keyboard</param>
internal LogitechKeyboardRGBDevice(LogitechKeyboardRGBDeviceInfo info)
: base(info)
{
this.KeyboardDeviceInfo = info;
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeLayout()
{
ApplyLayoutFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Layouts\Logitech\Keyboards\{KeyboardDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}\{KeyboardDeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"));
}
#endregion
}
}

View File

@ -0,0 +1,63 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents a generic information for a <see cref="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
/// <summary>
/// Internal constructor of managed <see cref="LogitechKeyboardRGBDeviceInfo"/>.
/// </summary>
/// <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>
/// <param name="culture">The <see cref="CultureInfo"/> of the layout this keyboard is using</param>
internal LogitechKeyboardRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, CultureInfo culture)
: base(deviceType, model, deviceCaps)
{
SetLayouts(culture.KeyboardLayoutId);
Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Images\Logitech\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}\{LogicalLayout.ToString().ToUpper()}.png"), UriKind.Absolute);
}
private void SetLayouts(int keyboardLayoutId)
{
switch (keyboardLayoutId)
{
//TODO DarthAffe 04.02.2017: Check all available keyboards and there layout-ids
default:
PhysicalLayout = LogitechPhysicalKeyboardLayout.US;
LogicalLayout = LogitechLogicalKeyboardLayout.NA;
break;
}
}
#endregion
}
}

View File

@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.HID;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents a device provider responsible for logitech devices.
/// </summary>
public class LogitechDeviceProvider : IRGBDeviceProvider
{
#region Properties & Fields
/// <summary>
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary>
public static LogitechDeviceProvider Instance { get; } = new LogitechDeviceProvider();
/// <inheritdoc />
public bool IsInitialized { get; private set; }
/// <summary>
/// Gets the loaded architecture (x64/x86).
/// </summary>
public string LoadedArchitecture => _LogitechGSDK.LoadedArchitecture;
/// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; }
/// <inheritdoc />
public bool HasExclusiveAccess => false; // Exclusive access isn't possible for logitech devices.
/// <summary>
/// Gets or sets a function to get the culture for a specific device.
/// </summary>
public Func<CultureInfo> GetCulture { get; set; } = () => CultureHelper.GetCurrentCulture();
#endregion
#region Constructors
private LogitechDeviceProvider()
{ }
#endregion
#region Methods
/// <inheritdoc />
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
{
try
{
if (IsInitialized)
_LogitechGSDK.LogiLedRestoreLighting();
}
catch
{ /* At least we tried ... */ }
IsInitialized = false;
try
{
_LogitechGSDK.Reload();
if (!_LogitechGSDK.LogiLedInit()) return false;
_LogitechGSDK.LogiLedSaveCurrentLighting();
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
IList<IRGBDevice> devices = new List<IRGBDevice>();
DeviceChecker.LoadDeviceList();
if (DeviceChecker.IsDeviceConnected)
{
LogitechRGBDevice device = new LogitechKeyboardRGBDevice(new LogitechKeyboardRGBDeviceInfo(
RGBDeviceType.Keyboard, DeviceChecker.ConnectedDeviceModel, LogitechDeviceCaps.PerKeyRGB, GetCulture()));
devices.Add(device);
try
{
device.Initialize();
}
catch
{
if (throwExceptions)
throw;
return false;
}
}
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
}
catch
{
if (throwExceptions)
throw;
else
return false;
}
IsInitialized = true;
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
_LogitechGSDK.LogiLedRestoreLighting();
}
#endregion
}
}

View File

@ -0,0 +1,166 @@
// ReSharper disable UnusedMethodReturnValue.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBePrivate.Global
using System;
using System.IO;
using System.Runtime.InteropServices;
using RGB.NET.Core.Exceptions;
namespace RGB.NET.Devices.Logitech.Native
{
// ReSharper disable once InconsistentNaming
internal class _LogitechGSDK
{
#region Libary Management
private static IntPtr _dllHandle = IntPtr.Zero;
/// <summary>
/// Gets the loaded architecture (x64/x86).
/// </summary>
internal static string LoadedArchitecture { get; private set; }
/// <summary>
/// Reloads the SDK.
/// </summary>
internal static void Reload()
{
UnloadLogitechGSDK();
LoadLogitechGSDK();
}
private static void LoadLogitechGSDK()
{
if (_dllHandle != IntPtr.Zero) return;
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
string dllPath = (LoadedArchitecture = Environment.Is64BitProcess ? "x64" : "x86") + "/LogitechLedEnginesWrapper.dll";
if (!File.Exists(dllPath))
throw new RGBDeviceException($"Can't find the Logitech-SDK at the expected location '{Path.GetFullPath(dllPath)}'");
_dllHandle = LoadLibrary(dllPath);
_logiLedInitPointer = (LogiLedInitPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedInit"), typeof(LogiLedInitPointer));
_logiLedShutdownPointer = (LogiLedShutdownPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedShutdown"), typeof(LogiLedShutdownPointer));
_logiLedSetTargetDevicePointer = (LogiLedSetTargetDevicePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetTargetDevice"), typeof(LogiLedSetTargetDevicePointer));
_logiLedGetSdkVersionPointer = (LogiLedGetSdkVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedGetSdkVersion"), typeof(LogiLedGetSdkVersionPointer));
_lgiLedSaveCurrentLightingPointer = (LogiLedSaveCurrentLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSaveCurrentLighting"), typeof(LogiLedSaveCurrentLightingPointer));
_logiLedRestoreLightingPointer = (LogiLedRestoreLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedRestoreLighting"), typeof(LogiLedRestoreLightingPointer));
_logiLedSetLightingForKeyWithKeyNamePointer = (LogiLedSetLightingForKeyWithKeyNamePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForKeyWithKeyName"), typeof(LogiLedSetLightingForKeyWithKeyNamePointer));
}
private static void UnloadLogitechGSDK()
{
if (_dllHandle == IntPtr.Zero) return;
LogiLedShutdown();
// ReSharper disable once EmptyEmbeddedStatement - DarthAffe 20.02.2016: We might need to reduce the internal reference counter more than once to set the library free
while (FreeLibrary(_dllHandle)) ;
_dllHandle = IntPtr.Zero;
}
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion
#region SDK-METHODS
#region Pointers
private static LogiLedInitPointer _logiLedInitPointer;
private static LogiLedShutdownPointer _logiLedShutdownPointer;
private static LogiLedSetTargetDevicePointer _logiLedSetTargetDevicePointer;
private static LogiLedGetSdkVersionPointer _logiLedGetSdkVersionPointer;
private static LogiLedSaveCurrentLightingPointer _lgiLedSaveCurrentLightingPointer;
private static LogiLedRestoreLightingPointer _logiLedRestoreLightingPointer;
private static LogiLedSetLightingForKeyWithKeyNamePointer _logiLedSetLightingForKeyWithKeyNamePointer;
#endregion
#region Delegates
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedInitPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void LogiLedShutdownPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetTargetDevicePointer(int targetDevice);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedGetSdkVersionPointer(ref int majorNum, ref int minorNum, ref int buildNum);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSaveCurrentLightingPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedRestoreLightingPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingForKeyWithKeyNamePointer(int keyCode, int redPercentage, int greenPercentage, int bluePercentage);
#endregion
// ReSharper disable EventExceptionNotDocumented
internal static bool LogiLedInit()
{
return _logiLedInitPointer();
}
internal static void LogiLedShutdown()
{
_logiLedShutdownPointer();
}
internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice)
{
return _logiLedSetTargetDevicePointer((int)targetDevice);
}
internal static string LogiLedGetSdkVersion()
{
int major = 0;
int minor = 0;
int build = 0;
LogiLedGetSdkVersion(ref major, ref minor, ref build);
return $"{major}.{minor}.{build}";
}
internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum)
{
return _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum);
}
internal static bool LogiLedSaveCurrentLighting()
{
return _lgiLedSaveCurrentLightingPointer();
}
internal static bool LogiLedRestoreLighting()
{
return _logiLedRestoreLightingPointer();
}
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode,
int redPercentage, int greenPercentage, int bluePercentage)
{
return _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage);
}
// ReSharper restore EventExceptionNotDocumented
#endregion
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RGB.NET.Devices.Logitech")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RGB.NET.Devices.Logitech")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e7b2f174-fcc6-4fc7-9970-3138b5f4c921")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E7B2F174-FCC6-4FC7-9970-3138B5F4C921}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RGB.NET.Devices.Logitech</RootNamespace>
<AssemblyName>RGB.NET.Devices.Logitech</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\bin\RGB.NET.Devices.Logitech.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\bin\RGB.NET.Devices.Logitech.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="HidSharp, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HidSharp.1.5\lib\net35\HidSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="RGB.NET.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Core.1.0.0\lib\net45\RGB.NET.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Enum\LogitechLogicalKeyboardLayout.cs" />
<Compile Include="Enum\LogitechPhysicalKeyboardLayout.cs" />
<Compile Include="Enum\LogitechDeviceCaps.cs" />
<Compile Include="Enum\LogitechLedIds.cs" />
<Compile Include="Generic\LogitechLedId.cs" />
<Compile Include="Generic\LogitechRGBDevice.cs" />
<Compile Include="Generic\LogitechRGBDeviceInfo.cs" />
<Compile Include="Helper\CultureHelper.cs" />
<Compile Include="HID\DeviceChecker.cs" />
<Compile Include="Keyboard\LogitechKeyboardRGBDevice.cs" />
<Compile Include="Keyboard\LogitechKeyboardRGBDeviceInfo.cs" />
<Compile Include="LogitechDeviceProvider.cs" />
<Compile Include="Native\_LogitechGSDK.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="targets\RGB.NET.Devices.Logitech.targets" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images\Logitech\Keyboards\" />
<Folder Include="Layouts\Logitech\Keyboards\" />
</ItemGroup>
<ItemGroup>
<Content Include="libs\x64\LogitechLedEnginesWrapper.dll" />
<Content Include="libs\x86\LogitechLedEnginesWrapper.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<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/=helper/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HidSharp" version="1.5" targetFramework="net45" />
<package id="RGB.NET.Core" version="1.0.0" targetFramework="net45" />
</packages>

View File

@ -0,0 +1,150 @@
<!--
* Build targets hacked from SQLite (thanks!)
* System.Data.SQLite.Core.targets -
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
******************************************************************************
** Build Items **
******************************************************************************
-->
<ItemGroup>
<LogitechSDKFiles Condition="'$(MSBuildThisFileDirectory)' != '' And
HasTrailingSlash('$(MSBuildThisFileDirectory)')"
Include="$(MSBuildThisFileDirectory)libs\**\*.dll;$(MSBuildThisFileDirectory)resources\**\*.*" />
<AdditionalPublishFilex86 Include="$(MSBuildThisFileDirectory)libs\x86\*.dll">
<Visible>False</Visible>
</AdditionalPublishFilex86>
<AdditionalPublishFilex64 Include="$(MSBuildThisFileDirectory)libs\x64\*.dll">
<Visible>False</Visible>
</AdditionalPublishFilex64>
</ItemGroup>
<!--
******************************************************************************
** Content Items **
******************************************************************************
-->
<ItemGroup Condition="'$(ContentLogitechSDKFiles)' != '' And
'$(ContentLogitechSDKFiles)' != 'false' And
'@(LogitechSDKFiles)' != ''">
<Content Include="@(LogitechSDKFiles)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<!--
******************************************************************************
** Build Targets* **
******************************************************************************
-->
<Target Name="CopyLogitechSDKFiles"
Condition="'$(CopyLogitechSDKFiles)' != 'false' And
'$(OutDir)' != '' And
HasTrailingSlash('$(OutDir)') And
Exists('$(OutDir)')"
Inputs="@(LogitechSDKFiles)"
Outputs="@(LogitechSDKFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')">
<!--
NOTE: Copy "CUESDK*.dll" and all related files, for every
architecture that we support, to the build output directory.
-->
<Message Text="Copying SDK files..." Importance="high" />
<Copy SourceFiles="@(LogitechSDKFiles)"
DestinationFiles="@(LogitechSDKFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<!--
******************************************************************************
-->
<Target Name="CleanLogitechSDKFiles"
Condition="'$(CleanLogitechSDKFiles)' != 'false' And
'$(OutDir)' != '' And
HasTrailingSlash('$(OutDir)') And
Exists('$(OutDir)')">
<!--
NOTE: Delete "CUESDK*.dll" and all related files, for every
architecture that we support, from the build output directory.
-->
<Message Text="this file $(MSBuildThisFileDirectory)" Importance="high"/>
<Message Text="Cleaning SDK files..." Importance="high" />
<Delete Files="@(LogitechSDKFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<!--
******************************************************************************
-->
<Target Name="CollectLogitechSDKFiles"
Condition="'$(CollectLogitechSDKFiles)' != 'false'">
<Message Text="Collecting SDK files..." Importance="high" />
<ItemGroup>
<FilesForPackagingFromProject Include="@(LogitechSDKFiles)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<!--
******************************************************************************
-->
<Target Name="BeforePublish">
<Touch Files="@(IntermediateAssembly)" />
</Target>
<Target Name="BeforeBuild">
<CreateItem Include="@(AdditionalPublishFilex86)" AdditionalMetadata="TargetPath=x86\%(FileName)%(Extension);IsDataFile=false">
<Output TaskParameter="Include" ItemName="_DeploymentManifestFiles" />
</CreateItem>
<CreateItem Include="@(AdditionalPublishFilex64)" AdditionalMetadata="TargetPath=x64\%(FileName)%(Extension);IsDataFile=false">
<Output TaskParameter="Include" ItemName="_DeploymentManifestFiles" />
</CreateItem>
</Target>
<!--
******************************************************************************
** Build Properties **
******************************************************************************
-->
<PropertyGroup>
<PostBuildEventDependsOn>
$(PostBuildEventDependsOn);
CopyLogitechSDKFiles;
</PostBuildEventDependsOn>
<BuildDependsOn>
$(BuildDependsOn);
CopyLogitechSDKFiles;
</BuildDependsOn>
<CleanDependsOn>
$(CleanDependsOn);
CleanLogitechSDKFiles;
</CleanDependsOn>
</PropertyGroup>
<!--
******************************************************************************
** Publish Properties for Visual Studio 201x **
******************************************************************************
-->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' Or
'$(VisualStudioVersion)' == '10.0' Or
'$(VisualStudioVersion)' == '11.0' Or
'$(VisualStudioVersion)' == '12.0'">
<PipelineCollectFilesPhaseDependsOn>
CollectLogitechSDKFiles;
$(PipelineCollectFilesPhaseDependsOn);
</PipelineCollectFilesPhaseDependsOn>
</PropertyGroup>
</Project>

View File

@ -31,6 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{06416566
NuGet\RGB.NET.Brushes.nuspec = NuGet\RGB.NET.Brushes.nuspec
NuGet\RGB.NET.Core.nuspec = NuGet\RGB.NET.Core.nuspec
NuGet\RGB.NET.Devices.Corsair.nuspec = NuGet\RGB.NET.Devices.Corsair.nuspec
NuGet\RGB.NET.Devices.Logitech.nuspec = NuGet\RGB.NET.Devices.Logitech.nuspec
NuGet\RGB.NET.Effects.nuspec = NuGet\RGB.NET.Effects.nuspec
NuGet\RGB.NET.Groups.nuspec = NuGet\RGB.NET.Groups.nuspec
NuGet\RGB.NET.Input.Corsair.nuspec = NuGet\RGB.NET.Input.Corsair.nuspec
@ -42,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UI", "UI", "{BD7C9994-1747-
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.WPF", "RGB.NET.WPF\RGB.NET.WPF.csproj", "{8D6C4FE6-0046-4E98-876F-4C0B87249989}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.Logitech", "RGB.NET.Devices.Logitech\RGB.NET.Devices.Logitech.csproj", "{E7B2F174-FCC6-4FC7-9970-3138B5F4C921}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -80,6 +83,10 @@ Global
{8D6C4FE6-0046-4E98-876F-4C0B87249989}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D6C4FE6-0046-4E98-876F-4C0B87249989}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D6C4FE6-0046-4E98-876F-4C0B87249989}.Release|Any CPU.Build.0 = Release|Any CPU
{E7B2F174-FCC6-4FC7-9970-3138B5F4C921}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7B2F174-FCC6-4FC7-9970-3138B5F4C921}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7B2F174-FCC6-4FC7-9970-3138B5F4C921}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7B2F174-FCC6-4FC7-9970-3138B5F4C921}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -92,5 +99,6 @@ Global
{F905C418-76BB-4BA6-88AB-0793BC2681D3} = {C854766D-9C1D-474B-B5B8-249DF4A9E552}
{2A39F859-AAD0-4C16-94F8-78057820B376} = {FFBCAF88-6646-43EC-9F24-2D719D3779C8}
{8D6C4FE6-0046-4E98-876F-4C0B87249989} = {BD7C9994-1747-4595-9C21-298E8FDCB657}
{E7B2F174-FCC6-4FC7-9970-3138B5F4C921} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
EndGlobalSection
EndGlobal