mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added Razer-SDK support
This commit is contained in:
parent
84133738b4
commit
9ec84b9e37
@ -21,6 +21,7 @@
|
||||
<dependency id="RGB.NET.Devices.Logitech" version="0.0.1" />
|
||||
<dependency id="RGB.NET.Devices.Msi" version="0.0.1" />
|
||||
<dependency id="RGB.NET.Devices.Novation" version="0.0.1" />
|
||||
<dependency id="RGB.NET.Devices.Razer" version="0.0.1" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
32
NuGet/RGB.NET.Devices.Razer.nuspec
Normal file
32
NuGet/RGB.NET.Devices.Razer.nuspec
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>RGB.NET.Devices.Razer</id>
|
||||
<title>RGB.NET.Devices.Razer</title>
|
||||
<version>0.0.1</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>Razer-Device-Implementations of RGB.NET</description>
|
||||
<releaseNotes></releaseNotes>
|
||||
<summary>Razer-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="0.0.1" />
|
||||
<dependency id="System.ValueTuple" version="4.3.1" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="..\bin\RGB.NET.Devices.Razer.dll" target="lib\net45\RGB.NET.Devices.Razer.dll" />
|
||||
<file src="..\bin\RGB.NET.Devices.Razer.pdb" target="lib\net45\RGB.NET.Devices.Razer.pdb" />
|
||||
<file src="..\bin\RGB.NET.Devices.Razer.xml" target="lib\net45\RGB.NET.Devices.Razer.xml" />
|
||||
<file src="..\RGB.NET.Devices.Razer\**\*.cs" target="src" exclude="..\RGB.NET.Devices.Razer\obj\**\*.*" />
|
||||
<!--<file src="..\RGB.NET.Devices.Razer\Images\**\*.*" target="build\net45\resources\Images\" />-->
|
||||
<file src="..\RGB.NET.Devices.Razer\Layouts\**\*.*" target="build\net45\resources\Layouts\" />
|
||||
<file src="..\RGB.NET.Devices.Razer\libs\**\*.*" target="build\net45\libs\" />
|
||||
<file src="..\RGB.NET.Devices.Razer\targets\*.targets" target="build\net45\" />
|
||||
</files>
|
||||
</package>
|
||||
63
RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs
Normal file
63
RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a razer chroma link.
|
||||
/// </summary>
|
||||
public class RazerChromaLinkRGBDevice : RazerRGBDevice<RazerChromaLinkRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerChromaLinkRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the chroma link.</param>
|
||||
internal RazerChromaLinkRGBDevice(RazerChromaLinkRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
||||
$@"Layouts\Razer\ChromaLink\{model}.xml"), null, PathHelper.GetAbsolutePath(@"Images\Razer\ChromaLink"));
|
||||
|
||||
if (LedMapping.Count == 0)
|
||||
for (int i = 0; i < _Defines.CHROMALINK_MAX_LEDS; i++)
|
||||
InitializeLed(new RazerLedId(this, i), new Rectangle(i * 11, 0, 10, 10));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(IEnumerable<Led> leds)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS];
|
||||
|
||||
foreach (Led led in leds)
|
||||
colors[((RazerLedId)led.Id).Index] = new _Color(led.Color.R, led.Color.G, led.Color.B);
|
||||
|
||||
_ChromaLinkCustomEffect effectParams = new _ChromaLinkCustomEffect { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerChromaLinkRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerChromaLinkRGBDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerChromaLinkRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
internal RazerChromaLinkRGBDeviceInfo(Guid deviceId, string model)
|
||||
: base(deviceId, RGBDeviceType.LedStripe, model)
|
||||
{
|
||||
string modelName = Model.Replace(" ", string.Empty).ToUpper();
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Razer\ChromaLinks\{modelName}.png"), UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
13
RGB.NET.Devices.Razer/Enum/DeviceType.cs
Normal file
13
RGB.NET.Devices.Razer/Enum/DeviceType.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
internal enum DeviceType
|
||||
{
|
||||
Keyboard = 1,
|
||||
Mouse = 2,
|
||||
Headset = 3,
|
||||
Mousepad = 4,
|
||||
Keypad = 5,
|
||||
System = 6,
|
||||
Invalid
|
||||
}
|
||||
}
|
||||
93
RGB.NET.Devices.Razer/Enum/RazerError.cs
Normal file
93
RGB.NET.Devices.Razer/Enum/RazerError.cs
Normal file
@ -0,0 +1,93 @@
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <summary>
|
||||
/// Razer-SDK: Error codes for Chroma SDK. If the error is not defined here, refer to WinError.h from the Windows SDK.
|
||||
/// </summary>
|
||||
public enum RazerError : long
|
||||
{
|
||||
/// <summary>
|
||||
/// Razer-SDK: Invalid.
|
||||
/// </summary>
|
||||
Invalid = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Success.
|
||||
/// </summary>
|
||||
Success = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Access denied.
|
||||
/// </summary>
|
||||
AccessDenied = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Invalid handle.
|
||||
/// </summary>
|
||||
InvalidHandle = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Not supported.
|
||||
/// </summary>
|
||||
NotSupported = 50,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Invalid parameter.
|
||||
/// </summary>
|
||||
InvalidParameter = 87,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: The service has not been started.
|
||||
/// </summary>
|
||||
ServiceNotActive = 1062,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Cannot start more than one instance of the specified program.
|
||||
/// </summary>
|
||||
SingleInstanceApp = 1152,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Device not connected.
|
||||
/// </summary>
|
||||
DeviceNotConnected = 1167,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Element not found.
|
||||
/// </summary>
|
||||
NotFound = 1168,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Request aborted.
|
||||
/// </summary>
|
||||
RequestAborted = 1235,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: An attempt was made to perform an initialization operation when initialization has already been completed.
|
||||
/// </summary>
|
||||
AlreadyInitialized = 1247,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Resource not available or disabled.
|
||||
/// </summary>
|
||||
ResourceDisabled = 4309,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Device not available or supported.
|
||||
/// </summary>
|
||||
DeviceNotAvailable = 4319,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: The group or resource is not in the correct state to perform the requested operation.
|
||||
/// </summary>
|
||||
NotValidState = 5023,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: No more items.
|
||||
/// </summary>
|
||||
NoMoreItems = 259,
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: General failure.
|
||||
/// </summary>
|
||||
Failed = 2147500037
|
||||
}
|
||||
}
|
||||
15
RGB.NET.Devices.Razer/Enum/RazerLogicalKeyboardLayout.cs
Normal file
15
RGB.NET.Devices.Razer/Enum/RazerLogicalKeyboardLayout.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available logical layouts for razer keyboards.
|
||||
/// </summary>
|
||||
public enum RazerLogicalKeyboardLayout
|
||||
{
|
||||
TODO
|
||||
};
|
||||
}
|
||||
15
RGB.NET.Devices.Razer/Enum/RazerPhysicalKeyboardLayout.cs
Normal file
15
RGB.NET.Devices.Razer/Enum/RazerPhysicalKeyboardLayout.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available physical layouts for razer keyboards.
|
||||
/// </summary>
|
||||
public enum RazerPhysicalKeyboardLayout
|
||||
{
|
||||
TODO
|
||||
}
|
||||
}
|
||||
37
RGB.NET.Devices.Razer/Exceptions/RazerException.cs
Normal file
37
RGB.NET.Devices.Razer/Exceptions/RazerException.cs
Normal file
@ -0,0 +1,37 @@
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents an exception thrown by the Razer-SDK.
|
||||
/// </summary>
|
||||
public class RazerException : ApplicationException
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error code provided by the SDK.
|
||||
/// </summary>
|
||||
public RazerError ErrorCode { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">The error code provided by the SDK.</param>
|
||||
public RazerException(RazerError errorCode)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
61
RGB.NET.Devices.Razer/Generic/Devices.cs
Normal file
61
RGB.NET.Devices.Razer/Generic/Devices.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
internal class Devices
|
||||
{
|
||||
public static readonly List<(Guid guid, string model)> KEYBOARDS = new List<(Guid guid, string model)>
|
||||
{
|
||||
(new Guid("2EA1BB63-CA28-428D-9F06-196B88330BBB"), "Blackwidow Chroma"),
|
||||
(new Guid("ED1C1B82-BFBE-418F-B49D-D03F05B149DF"), "Razer Blackwidow Chroma Tournament Edition"),
|
||||
(new Guid("18C5AD9B-4326-4828-92C4-2669A66D2283"), "Razer Deathstalker "),
|
||||
(new Guid("872AB2A9-7959-4478-9FED-15F6186E72E4"), "Overwatch Keyboard"),
|
||||
(new Guid("5AF60076-ADE9-43D4-B574-52599293B554"), "Razer Blackwidow X Chroma"),
|
||||
(new Guid("2D84DD51-3290-4AAC-9A89-D8AFDE38B57C"), "Razer Blackwidow X TE Chroma"),
|
||||
(new Guid("803378C1-CC48-4970-8539-D828CC1D420A"), "Razer Omata Chroma"),
|
||||
(new Guid("C83BDFE8-E7FC-40E0-99DB-872E23F19891"), "Razer Blade Stealth"),
|
||||
(new Guid("F2BEDFAF-A0FE-4651-9D41-B6CE603A3DDD"), "Razer Blade"),
|
||||
(new Guid("A73AC338-F0E5-4BF7-91AE-DD1F7E1737A5"), "Razer Blade Pro"),
|
||||
(new Guid("608E743F-B402-44BD-A7A6-7AA9F574ECF4"), "Razer Blackwidow Chroma v2")
|
||||
};
|
||||
|
||||
public static readonly List<(Guid guid, string model)> MICE = new List<(Guid guid, string model)>
|
||||
{
|
||||
(new Guid("7EC00450-E0EE-4289-89D5-0D879C19061A"), "Razer Mamba Chroma Tournament Edition"),
|
||||
(new Guid("AEC50D91-B1F1-452F-8E16-7B73F376FDF3"), "Razer Deathadder Chroma "),
|
||||
(new Guid("FF8A5929-4512-4257-8D59-C647BF9935D0"), "Razer Diamondback"),
|
||||
(new Guid("D527CBDC-EB0A-483A-9E89-66D50463EC6C"), "Razer Mamba"),
|
||||
(new Guid("D714C50B-7158-4368-B99C-601ACB985E98"), "Razer Naga Epic"),
|
||||
(new Guid("F1876328-6CA4-46AE-BE04-BE812B414433"), "Razer Naga"),
|
||||
(new Guid("52C15681-4ECE-4DD9-8A52-A1418459EB34"), "Razer Orochi Chroma"),
|
||||
(new Guid("195D70F5-F285-4CFF-99F2-B8C0E9658DB4"), "Razer Naga Hex Chroma"),
|
||||
(new Guid("77834867-3237-4A9F-AD77-4A46C4183003"), "Razer DeathAdder Elite Chroma")
|
||||
};
|
||||
|
||||
public static readonly List<(Guid guid, string model)> HEADSETS = new List<(Guid guid, string model)>
|
||||
{
|
||||
(new Guid("DF3164D7-5408-4A0E-8A7F-A7412F26BEBF"), "Razer ManO'War"),
|
||||
(new Guid("CD1E09A5-D5E6-4A6C-A93B-E6D9BF1D2092"), "Razer Kraken 7.1 Chroma"),
|
||||
(new Guid("7FB8A36E-9E74-4BB3-8C86-CAC7F7891EBD"), "Razer Kraken 7.1 Chroma Refresh")
|
||||
};
|
||||
|
||||
public static readonly List<(Guid guid, string model)> MOUSEMATS = new List<(Guid guid, string model)>
|
||||
{
|
||||
(new Guid("80F95A94-73D2-48CA-AE9A-0986789A9AF2"), "Razer Firefly")
|
||||
};
|
||||
|
||||
public static readonly List<(Guid guid, string model)> KEYPADS = new List<(Guid guid, string model)>
|
||||
{
|
||||
(new Guid("9D24B0AB-0162-466C-9640-7A924AA4D9FD"), "Razer Orbweaver"),
|
||||
(new Guid("00F0545C-E180-4AD1-8E8A-419061CE505E"), "Razer Tartarus")
|
||||
};
|
||||
|
||||
public static readonly List<(Guid guid, string model)> CHROMALINKS = new List<(Guid guid, string model)>
|
||||
{
|
||||
(new Guid("0201203B-62F3-4C50-83DD-598BABD208E0"), "Core Chroma"),
|
||||
(new Guid("35F6F18D-1AE5-436C-A575-AB44A127903A"), "Lenovo Y900"),
|
||||
(new Guid("47DB1FA7-6B9B-4EE6-B6F4-4071A3B2053B"), "Lenovo Y27")
|
||||
};
|
||||
}
|
||||
}
|
||||
13
RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs
Normal file
13
RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a razer RGB-device.
|
||||
/// </summary>
|
||||
internal interface IRazerRGBDevice : IRGBDevice
|
||||
{
|
||||
void Initialize();
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
94
RGB.NET.Devices.Razer/Generic/RazerLedId.cs
Normal file
94
RGB.NET.Devices.Razer/Generic/RazerLedId.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a Id of a <see cref="T:RGB.NET.Core.Led" /> on a <see cref="T:RGB.NET.Devices.Razer.RazerRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerLedId : ILedId
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
internal int Index { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRGBDevice Device { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsValid => true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RazerLedId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
|
||||
/// <param name="index">The index representing the led-location in the grid.</param>
|
||||
public RazerLedId(IRGBDevice device, int index)
|
||||
{
|
||||
this.Device = device;
|
||||
this.Index = index;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Converts the Id of this <see cref="RazerLedId"/> to a human-readable string.
|
||||
/// </summary>
|
||||
/// <returns>A string that contains the Id of this <see cref="RazerLedId"/>. For example "Enter".</returns>
|
||||
public override string ToString() => Index.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="RazerLedId" /> and is equivalent to this <see cref="RazerLedId" />.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="RazerLedId" /> equivalent to this <see cref="RazerLedId" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (!(obj is RazerLedId other)) return false;
|
||||
|
||||
return (Index == other.Index) && Equals(Device, other.Device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash code for this <see cref="RazerLedId" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="RazerLedId" />.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (Index * 397) ^ (Device != null ? Device.GetHashCode() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="RazerLedId" /> are equal.
|
||||
/// </summary>
|
||||
/// <param name="ledId1">The first <see cref="RazerLedId" /> to compare.</param>
|
||||
/// <param name="ledId2">The second <see cref="RazerLedId" /> 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 ==(RazerLedId ledId1, RazerLedId ledId2) => ReferenceEquals(ledId1, null) ? ReferenceEquals(ledId2, null) : ledId1.Equals(ledId2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="RazerLedId" /> are equal.
|
||||
/// </summary>
|
||||
/// <param name="ledId1">The first <see cref="RazerLedId" /> to compare.</param>
|
||||
/// <param name="ledId2">The second <see cref="RazerLedId" /> 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 !=(RazerLedId ledId1, RazerLedId ledId2) => !(ledId1 == ledId2);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
143
RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs
Normal file
143
RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs
Normal file
@ -0,0 +1,143 @@
|
||||
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.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||
/// <inheritdoc cref="IRazerRGBDevice" />
|
||||
/// <summary>
|
||||
/// Represents a generic razer-device. (keyboard, mouse, headset, mousepad).
|
||||
/// </summary>
|
||||
public abstract class RazerRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IRazerRGBDevice
|
||||
where TDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private Guid? _lastEffect;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets information about the <see cref="T:RGB.NET.Devices.Razer.RazerRGBDevice" />.
|
||||
/// </summary>
|
||||
public override TDeviceInfo DeviceInfo { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RazerRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by razer for the device.</param>
|
||||
protected RazerRGBDevice(TDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the device.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
Size = 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>
|
||||
/// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
|
||||
/// <param name="imageBasePath">The path images for this device are collected in.</param>
|
||||
protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
|
||||
{
|
||||
DeviceLayout layout = DeviceLayout.Load(layoutPath);
|
||||
if (layout != null)
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
{
|
||||
if (Enum.TryParse(layoutLed.Id, true, out int ledIndex))
|
||||
{
|
||||
if (LedMapping.TryGetValue(new RazerLedId(this, ledIndex), out Led led))
|
||||
{
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
|
||||
led.Image = (!string.IsNullOrEmpty(image?.Image))
|
||||
? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
|
||||
: new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
{
|
||||
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
|
||||
|
||||
if (leds.Count <= 0) return;
|
||||
|
||||
IntPtr effectParams = CreateEffectParams(leds);
|
||||
Guid effectId = Guid.NewGuid();
|
||||
_RazerSDK.CreateEffect(DeviceInfo.DeviceId, _Defines.EFFECT_ID, effectParams, ref effectId);
|
||||
|
||||
_RazerSDK.SetEffect(effectId);
|
||||
|
||||
if (_lastEffect.HasValue)
|
||||
_RazerSDK.DeleteEffect(_lastEffect.Value);
|
||||
|
||||
_lastEffect = effectId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the device-specific effect parameters for the led-update.
|
||||
/// </summary>
|
||||
/// <param name="leds">The leds to be updated.</param>
|
||||
/// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns>
|
||||
protected abstract IntPtr CreateEffectParams(IEnumerable<Led> leds);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the device.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
if (_lastEffect.HasValue)
|
||||
{
|
||||
_RazerSDK.DeleteEffect(_lastEffect.Value);
|
||||
_lastEffect = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
56
RGB.NET.Devices.Razer/Generic/RazerRGBDeviceInfo.cs
Normal file
56
RGB.NET.Devices.Razer/Generic/RazerRGBDeviceInfo.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a Razer-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerRGBDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the <see cref="RazerRGBDevice{TDeviceInfo}"/>.
|
||||
/// </summary>
|
||||
public Guid DeviceId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Manufacturer => "Razer";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Uri Image { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="RazerRGBDeviceInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
internal RazerRGBDeviceInfo(Guid deviceId, RGBDeviceType deviceType, string model)
|
||||
{
|
||||
this.DeviceId = deviceId;
|
||||
this.DeviceType = deviceType;
|
||||
this.Model = model;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
63
RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs
Normal file
63
RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a razer headset.
|
||||
/// </summary>
|
||||
public class RazerHeadsetRGBDevice : RazerRGBDevice<RazerHeadsetRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerHeadsetRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the headset.</param>
|
||||
internal RazerHeadsetRGBDevice(RazerHeadsetRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
||||
$@"Layouts\Razer\Headset\{model}.xml"), null, PathHelper.GetAbsolutePath(@"Images\Razer\Headset"));
|
||||
|
||||
if (LedMapping.Count == 0)
|
||||
for (int i = 0; i < _Defines.HEADSET_MAX_LEDS; i++)
|
||||
InitializeLed(new RazerLedId(this, i), new Rectangle(i * 11, 0, 10, 10));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(IEnumerable<Led> leds)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS];
|
||||
|
||||
foreach (Led led in leds)
|
||||
colors[((RazerLedId)led.Id).Index] = new _Color(led.Color.R, led.Color.G, led.Color.B);
|
||||
|
||||
_HeadsetCustomEffect effectParams = new _HeadsetCustomEffect { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
32
RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDeviceInfo.cs
Normal file
32
RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDeviceInfo.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerHeadsetRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerHeadsetRGBDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerHeadsetRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
internal RazerHeadsetRGBDeviceInfo(Guid deviceId, string model)
|
||||
: base(deviceId, RGBDeviceType.Headset, model)
|
||||
{
|
||||
string modelName = Model.Replace(" ", string.Empty).ToUpper();
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Razer\Headsets\{modelName}.png"), UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
67
RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs
Normal file
67
RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a razer keyboard.
|
||||
/// </summary>
|
||||
public class RazerKeyboardRGBDevice : RazerRGBDevice<RazerKeyboardRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the keyboard.</param>
|
||||
internal RazerKeyboardRGBDevice(RazerKeyboardRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
//string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
||||
//ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
||||
// $@"Layouts\Razer\Keyboards\{model}\{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"),
|
||||
// DeviceInfo.LogicalLayout.ToString(), PathHelper.GetAbsolutePath(@"Images\Razer\Keyboards"));
|
||||
|
||||
if (LedMapping.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < _Defines.KEYBOARD_MAX_ROW; i++)
|
||||
for (int j = 0; j < _Defines.KEYBOARD_MAX_COLUMN; j++)
|
||||
InitializeLed(new RazerLedId(this, (i * _Defines.KEYBOARD_MAX_COLUMN) + j), new Rectangle(j * 20, i * 20, 19, 19));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(IEnumerable<Led> leds)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS];
|
||||
|
||||
foreach (Led led in leds)
|
||||
colors[((RazerLedId)led.Id).Index] = new _Color(led.Color.R, led.Color.G, led.Color.B);
|
||||
|
||||
_KeyboardCustomEffect effectParams = new _KeyboardCustomEffect { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
66
RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs
Normal file
66
RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs
Normal file
@ -0,0 +1,66 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerKeyboardRGBDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the physical layout of the keyboard.
|
||||
/// </summary>
|
||||
public RazerPhysicalKeyboardLayout PhysicalLayout { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the logical layout of the keyboard as set in CUE settings.
|
||||
/// </summary>
|
||||
public RazerLogicalKeyboardLayout LogicalLayout { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using.</param>
|
||||
internal RazerKeyboardRGBDeviceInfo(Guid deviceId, string model, CultureInfo culture)
|
||||
: base(deviceId, RGBDeviceType.Keyboard, model)
|
||||
{
|
||||
SetLayouts(culture.KeyboardLayoutId);
|
||||
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Razer\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}.png"),
|
||||
UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void SetLayouts(int keyboardLayoutId)
|
||||
{
|
||||
switch (keyboardLayoutId)
|
||||
{
|
||||
//TODO DarthAffe 07.10.2017: Implement
|
||||
default:
|
||||
PhysicalLayout = RazerPhysicalKeyboardLayout.TODO;
|
||||
LogicalLayout = RazerLogicalKeyboardLayout.TODO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
66
RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs
Normal file
66
RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs
Normal file
@ -0,0 +1,66 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a razer keypad.
|
||||
/// </summary>
|
||||
public class RazerKeypadRGBDevice : RazerRGBDevice<RazerKeypadRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerKeypadRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the keypad.</param>
|
||||
internal RazerKeypadRGBDevice(RazerKeypadRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
||||
$@"Layouts\Razer\Keypad\{model}.xml"), null, PathHelper.GetAbsolutePath(@"Images\Razer\Keypad"));
|
||||
|
||||
if (LedMapping.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < _Defines.KEYPAD_MAX_ROW; i++)
|
||||
for (int j = 0; j < _Defines.KEYPAD_MAX_COLUMN; j++)
|
||||
InitializeLed(new RazerLedId(this, (i * _Defines.KEYPAD_MAX_COLUMN) + j), new Rectangle(j * 20, i * 20, 19, 19));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(IEnumerable<Led> leds)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS];
|
||||
|
||||
foreach (Led led in leds)
|
||||
colors[((RazerLedId)led.Id).Index] = new _Color(led.Color.R, led.Color.G, led.Color.B);
|
||||
|
||||
_KeypadCustomEffect effectParams = new _KeypadCustomEffect { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
32
RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDeviceInfo.cs
Normal file
32
RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDeviceInfo.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerKeypadRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerKeypadRGBDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerKeypadRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
internal RazerKeypadRGBDeviceInfo(Guid deviceId, string model)
|
||||
: base(deviceId, RGBDeviceType.Keypad, model)
|
||||
{
|
||||
string modelName = Model.Replace(" ", string.Empty).ToUpper();
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Razer\Keypads\{modelName}.png"), UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
63
RGB.NET.Devices.Razer/Layouts/DeviceLayout.xsd
Normal file
63
RGB.NET.Devices.Razer/Layouts/DeviceLayout.xsd
Normal file
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
|
||||
<xsd:element name="Device">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="Name" type="xsd:string" />
|
||||
<xsd:element name="Description" type="xsd:string" />
|
||||
<xsd:element name="Type" type="xsd:string" />
|
||||
<xsd:element name="Lighting" type="xsd:string" />
|
||||
<xsd:element name="Vendor" type="xsd:string" />
|
||||
<xsd:element name="Model" type="xsd:string" />
|
||||
<xsd:element name="Shape" type="xsd:string" />
|
||||
<xsd:element name="Width" type="xsd:double" />
|
||||
<xsd:element name="Height" type="xsd:double" />
|
||||
<xsd:element name="LedUnitWidth" type="xsd:double" />
|
||||
<xsd:element name="LedUnitHeight" type="xsd:double" />
|
||||
<xsd:element name="Leds">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element maxOccurs="unbounded" name="Led">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="Shape" type="xsd:string" />
|
||||
<xsd:element name="X" type="xsd:string" />
|
||||
<xsd:element name="Y" type="xsd:string" />
|
||||
<xsd:element name="Width" type="xsd:string" />
|
||||
<xsd:element name="Height" type="xsd:string" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="Id" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="LedImageLayouts">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element maxOccurs="unbounded" name="LedImageLayout">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="LedImages">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element maxOccurs="unbounded" name="LedImage">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="Id" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="Image" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="Layout" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xs:schema>
|
||||
66
RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs
Normal file
66
RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs
Normal file
@ -0,0 +1,66 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a razer mouse.
|
||||
/// </summary>
|
||||
public class RazerMouseRGBDevice : RazerRGBDevice<RazerMouseRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerMouseRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the mouse.</param>
|
||||
internal RazerMouseRGBDevice(RazerMouseRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
||||
$@"Layouts\Razer\Mice\{model}.xml"), null, PathHelper.GetAbsolutePath(@"Images\Razer\Mice"));
|
||||
|
||||
if (LedMapping.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < _Defines.MOUSE_MAX_ROW; i++)
|
||||
for (int j = 0; j < _Defines.MOUSE_MAX_COLUMN; j++)
|
||||
InitializeLed(new RazerLedId(this, (i * _Defines.MOUSE_MAX_COLUMN) + j), new Rectangle(j * 11, i * 11, 10, 10));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(IEnumerable<Led> leds)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS];
|
||||
|
||||
foreach (Led led in leds)
|
||||
colors[((RazerLedId)led.Id).Index] = new _Color(led.Color.R, led.Color.G, led.Color.B);
|
||||
|
||||
_MouseCustomEffect effectParams = new _MouseCustomEffect { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
32
RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDeviceInfo.cs
Normal file
32
RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDeviceInfo.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerMouseRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerMouseRGBDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerMouseRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
internal RazerMouseRGBDeviceInfo(Guid deviceId, string model)
|
||||
: base(deviceId, RGBDeviceType.Mouse, model)
|
||||
{
|
||||
string modelName = Model.Replace(" ", string.Empty).ToUpper();
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Razer\Mice\{modelName}.png"), UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
63
RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs
Normal file
63
RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a razer mousepad.
|
||||
/// </summary>
|
||||
public class RazerMousepadRGBDevice : RazerRGBDevice<RazerMousepadRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerMousepadRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the mousepad.</param>
|
||||
internal RazerMousepadRGBDevice(RazerMousepadRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
|
||||
$@"Layouts\Razer\Mousepad\{model}.xml"), null, PathHelper.GetAbsolutePath(@"Images\Razer\Mousepad"));
|
||||
|
||||
if (LedMapping.Count == 0)
|
||||
for (int i = 0; i < _Defines.MOUSEPAD_MAX_LEDS; i++)
|
||||
InitializeLed(new RazerLedId(this, i), new Rectangle(i * 11, 0, 10, 10));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IntPtr CreateEffectParams(IEnumerable<Led> leds)
|
||||
{
|
||||
_Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS];
|
||||
|
||||
foreach (Led led in leds)
|
||||
colors[((RazerLedId)led.Id).Index] = new _Color(led.Color.R, led.Color.G, led.Color.B);
|
||||
|
||||
_MousepadCustomEffect effectParams = new _MousepadCustomEffect { Color = colors };
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
|
||||
Marshal.StructureToPtr(effectParams, ptr, false);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
32
RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDeviceInfo.cs
Normal file
32
RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDeviceInfo.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerMousepadRGBDevice" />.
|
||||
/// </summary>
|
||||
public class RazerMousepadRGBDeviceInfo : RazerRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerMousepadRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
|
||||
internal RazerMousepadRGBDeviceInfo(Guid deviceId, string model)
|
||||
: base(deviceId, RGBDeviceType.Mousepad, model)
|
||||
{
|
||||
string modelName = Model.Replace(" ", string.Empty).ToUpper();
|
||||
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Razer\Mousepads\{modelName}.png"), UriKind.Absolute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
11
RGB.NET.Devices.Razer/Native/_ChromaLinkCustomEffect.cs
Normal file
11
RGB.NET.Devices.Razer/Native/_ChromaLinkCustomEffect.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _ChromaLinkCustomEffect
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = _Defines.CHROMALINK_MAX_LEDS)]
|
||||
public _Color[] Color;
|
||||
}
|
||||
}
|
||||
30
RGB.NET.Devices.Razer/Native/_Color.cs
Normal file
30
RGB.NET.Devices.Razer/Native/_Color.cs
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma warning disable 169 // Field 'x' is never used
|
||||
#pragma warning disable 414 // Field 'x' is assigned but its value never used
|
||||
#pragma warning disable 649 // Field 'x' is never assigned
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[StructLayout(LayoutKind.Sequential, Size = sizeof(uint))]
|
||||
internal struct _Color
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public uint Color;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public _Color(byte red, byte green, byte blue)
|
||||
: this()
|
||||
{
|
||||
Color = red + ((uint)green << 8) + ((uint)blue << 16);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
25
RGB.NET.Devices.Razer/Native/_Defines.cs
Normal file
25
RGB.NET.Devices.Razer/Native/_Defines.cs
Normal file
@ -0,0 +1,25 @@
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
internal static class _Defines
|
||||
{
|
||||
internal const int EFFECT_ID = 7;
|
||||
|
||||
internal const int KEYBOARD_MAX_ROW = 6;
|
||||
internal const int KEYBOARD_MAX_COLUMN = 22;
|
||||
internal const int KEYBOARD_MAX_LEDS = KEYBOARD_MAX_ROW * KEYBOARD_MAX_COLUMN;
|
||||
|
||||
internal const int MOUSE_MAX_ROW = 9;
|
||||
internal const int MOUSE_MAX_COLUMN = 7;
|
||||
internal const int MOUSE_MAX_LEDS = KEYBOARD_MAX_ROW * KEYBOARD_MAX_COLUMN;
|
||||
|
||||
internal const int HEADSET_MAX_LEDS = 5;
|
||||
|
||||
internal const int MOUSEPAD_MAX_LEDS = 15;
|
||||
|
||||
internal const int KEYPAD_MAX_ROW = 4;
|
||||
internal const int KEYPAD_MAX_COLUMN = 5;
|
||||
internal const int KEYPAD_MAX_LEDS = KEYPAD_MAX_ROW * KEYPAD_MAX_COLUMN;
|
||||
|
||||
internal const int CHROMALINK_MAX_LEDS = 5;
|
||||
}
|
||||
}
|
||||
27
RGB.NET.Devices.Razer/Native/_DeviceInfo.cs
Normal file
27
RGB.NET.Devices.Razer/Native/_DeviceInfo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma warning disable 169 // Field 'x' is never used
|
||||
#pragma warning disable 414 // Field 'x' is assigned but its value never used
|
||||
#pragma warning disable 649 // Field 'x' is never assigned
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>
|
||||
/// Razer-SDK: Device info.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _DeviceInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Razer-SDK: Device types.
|
||||
/// </summary>
|
||||
internal DeviceType Type;
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Number of devices connected.
|
||||
/// </summary>
|
||||
internal int Connected;
|
||||
}
|
||||
}
|
||||
11
RGB.NET.Devices.Razer/Native/_HeadsetCustomEffect.cs
Normal file
11
RGB.NET.Devices.Razer/Native/_HeadsetCustomEffect.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _HeadsetCustomEffect
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = _Defines.HEADSET_MAX_LEDS)]
|
||||
public _Color[] Color;
|
||||
}
|
||||
}
|
||||
11
RGB.NET.Devices.Razer/Native/_KeyboardCustomEffect.cs
Normal file
11
RGB.NET.Devices.Razer/Native/_KeyboardCustomEffect.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _KeyboardCustomEffect
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = _Defines.KEYBOARD_MAX_LEDS)]
|
||||
public _Color[] Color;
|
||||
}
|
||||
}
|
||||
11
RGB.NET.Devices.Razer/Native/_KeypadCustomEffect.cs
Normal file
11
RGB.NET.Devices.Razer/Native/_KeypadCustomEffect.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _KeypadCustomEffect
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = _Defines.KEYPAD_MAX_LEDS)]
|
||||
public _Color[] Color;
|
||||
}
|
||||
}
|
||||
11
RGB.NET.Devices.Razer/Native/_MouseCustomEffect.cs
Normal file
11
RGB.NET.Devices.Razer/Native/_MouseCustomEffect.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _MouseCustomEffect
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = _Defines.MOUSE_MAX_LEDS)]
|
||||
public _Color[] Color;
|
||||
}
|
||||
}
|
||||
11
RGB.NET.Devices.Razer/Native/_MousepadCustomEffect.cs
Normal file
11
RGB.NET.Devices.Razer/Native/_MousepadCustomEffect.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct _MousepadCustomEffect
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = _Defines.MOUSEPAD_MAX_LEDS)]
|
||||
public _Color[] Color;
|
||||
}
|
||||
}
|
||||
146
RGB.NET.Devices.Razer/Native/_RazerSDK.cs
Normal file
146
RGB.NET.Devices.Razer/Native/_RazerSDK.cs
Normal file
@ -0,0 +1,146 @@
|
||||
// ReSharper disable UnusedMethodReturnValue.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core.Exceptions;
|
||||
|
||||
namespace RGB.NET.Devices.Razer.Native
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal static class _RazerSDK
|
||||
{
|
||||
#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()
|
||||
{
|
||||
UnloadRazerSDK();
|
||||
LoadRazerSDK();
|
||||
}
|
||||
|
||||
private static void LoadRazerSDK()
|
||||
{
|
||||
if (_dllHandle != IntPtr.Zero) return;
|
||||
|
||||
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
|
||||
List<string> possiblePathList = Environment.Is64BitProcess ? RazerDeviceProvider.PossibleX64NativePaths : RazerDeviceProvider.PossibleX86NativePaths;
|
||||
string dllPath = possiblePathList.FirstOrDefault(File.Exists);
|
||||
if (dllPath == null) throw new RGBDeviceException($"Can't find the Razer-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
|
||||
|
||||
_dllHandle = LoadLibrary(dllPath);
|
||||
|
||||
_initPointer = (InitPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "Init"), typeof(InitPointer));
|
||||
_unInitPointer = (UnInitPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "UnInit"), typeof(UnInitPointer));
|
||||
_queryDevicePointer = (QueryDevicePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "QueryDevice"), typeof(QueryDevicePointer));
|
||||
_createEffectPointer = (CreateEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateEffect"), typeof(CreateEffectPointer));
|
||||
_setEffectPointer = (SetEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetEffect"), typeof(SetEffectPointer));
|
||||
_deleteEffectPointer = (DeleteEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "DeleteEffect"), typeof(DeleteEffectPointer));
|
||||
}
|
||||
|
||||
private static void UnloadRazerSDK()
|
||||
{
|
||||
if (_dllHandle == IntPtr.Zero) return;
|
||||
|
||||
// ReSharper disable once EmptyEmbeddedStatement - DarthAffe 09.11.2017: 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 InitPointer _initPointer;
|
||||
private static UnInitPointer _unInitPointer;
|
||||
private static QueryDevicePointer _queryDevicePointer;
|
||||
private static CreateEffectPointer _createEffectPointer;
|
||||
private static SetEffectPointer _setEffectPointer;
|
||||
private static DeleteEffectPointer _deleteEffectPointer;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate RazerError InitPointer();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate RazerError UnInitPointer();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate RazerError QueryDevicePointer(Guid deviceId, IntPtr deviceInfo);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate RazerError CreateEffectPointer(Guid deviceId, int effectType, IntPtr param, ref Guid effectId);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate RazerError SetEffectPointer(Guid effectId);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate RazerError DeleteEffectPointer(Guid effectId);
|
||||
|
||||
#endregion
|
||||
|
||||
// ReSharper disable EventExceptionNotDocumented
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Initialize Chroma SDK.
|
||||
/// </summary>
|
||||
internal static RazerError Init() => _initPointer();
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: UnInitialize Chroma SDK.
|
||||
/// </summary>
|
||||
internal static RazerError UnInit() => _unInitPointer();
|
||||
|
||||
/// <summary>
|
||||
/// Razer-SDK: Query for device information.
|
||||
/// </summary>
|
||||
internal static RazerError QueryDevice(Guid deviceId, out _DeviceInfo deviceInfo)
|
||||
{
|
||||
int structSize = Marshal.SizeOf(typeof(_DeviceInfo));
|
||||
IntPtr deviceInfoPtr = Marshal.AllocHGlobal(structSize);
|
||||
|
||||
RazerError error = _queryDevicePointer(deviceId, deviceInfoPtr);
|
||||
|
||||
deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo));
|
||||
Marshal.FreeHGlobal(deviceInfoPtr);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
internal static RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) => _createEffectPointer(deviceId, effectType, param, ref effectId);
|
||||
|
||||
internal static RazerError SetEffect(Guid effectId) => _setEffectPointer(effectId);
|
||||
|
||||
internal static RazerError DeleteEffect(Guid effectId) => _deleteEffectPointer(effectId);
|
||||
|
||||
// ReSharper restore EventExceptionNotDocumented
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
35
RGB.NET.Devices.Razer/Properties/AssemblyInfo.cs
Normal file
35
RGB.NET.Devices.Razer/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
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.Razer")]
|
||||
[assembly: AssemblyDescription("Razer-Device-Implementations of RGB.NET")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Wyrez")]
|
||||
[assembly: AssemblyProduct("RGB.NET.Devices.Razer")]
|
||||
[assembly: AssemblyCopyright("Copyright © Wyrez 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("24ff4acb-d679-4b2d-86d4-50ab6c02d816")]
|
||||
|
||||
// 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")]
|
||||
105
RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj
Normal file
105
RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj
Normal file
@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" 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>{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RGB.NET.Devices.Razer</RootNamespace>
|
||||
<AssemblyName>RGB.NET.Devices.Razer</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.Razer.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.Razer.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<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\RazerLogicalKeyboardLayout.cs" />
|
||||
<Compile Include="Enum\RazerPhysicalKeyboardLayout.cs" />
|
||||
<Compile Include="Enum\DeviceType.cs" />
|
||||
<Compile Include="Exceptions\RazerException.cs" />
|
||||
<Compile Include="Generic\RazerLedId.cs" />
|
||||
<Compile Include="Generic\RazerRGBDevice.cs" />
|
||||
<Compile Include="Generic\RazerRGBDeviceInfo.cs" />
|
||||
<Compile Include="Generic\Devices.cs" />
|
||||
<Compile Include="Generic\IRazerRGBDevice.cs" />
|
||||
<Compile Include="ChromaLink\RazerChromaLinkRGBDevice.cs" />
|
||||
<Compile Include="ChromaLink\RazerChromaLinkRGBDeviceInfo.cs" />
|
||||
<Compile Include="Mousepad\RazerMousepadRGBDevice.cs" />
|
||||
<Compile Include="Mousepad\RazerMousepadRGBDeviceInfo.cs" />
|
||||
<Compile Include="Keypad\RazerKeypadRGBDevice.cs" />
|
||||
<Compile Include="Keypad\RazerKeypadRGBDeviceInfo.cs" />
|
||||
<Compile Include="Headset\RazerHeadsetRGBDevice.cs" />
|
||||
<Compile Include="Headset\RazerHeadsetRGBDeviceInfo.cs" />
|
||||
<Compile Include="Mouse\RazerMouseRGBDevice.cs" />
|
||||
<Compile Include="Mouse\RazerMouseRGBDeviceInfo.cs" />
|
||||
<Compile Include="Keyboard\RazerKeyboardRGBDevice.cs" />
|
||||
<Compile Include="Keyboard\RazerKeyboardRGBDeviceInfo.cs" />
|
||||
<Compile Include="Native\_Color.cs" />
|
||||
<Compile Include="Native\_Defines.cs" />
|
||||
<Compile Include="Native\_DeviceInfo.cs" />
|
||||
<Compile Include="Native\_ChromaLinkCustomEffect.cs" />
|
||||
<Compile Include="Native\_KeypadCustomEffect.cs" />
|
||||
<Compile Include="Native\_MousepadCustomEffect.cs" />
|
||||
<Compile Include="Native\_HeadsetCustomEffect.cs" />
|
||||
<Compile Include="Native\_MouseCustomEffect.cs" />
|
||||
<Compile Include="Native\_KeyboardCustomEffect.cs" />
|
||||
<Compile Include="RazerDeviceProvider.cs" />
|
||||
<Compile Include="Enum\RazerError.cs" />
|
||||
<Compile Include="Native\_RazerSDK.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj">
|
||||
<Project>{5a4f9a75-75fe-47cd-90e5-914d5b20d232}</Project>
|
||||
<Name>RGB.NET.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="libs\x86\RzChromaSDK.dll" />
|
||||
<Content Include="libs\x64\RzChromaSDK.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Layouts\DeviceLayout.xsd">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
<None Include="targets\RGB.NET.Devices.Razer.targets" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Images\Razer\" />
|
||||
<Folder Include="Layouts\Razer\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -0,0 +1,11 @@
|
||||
<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/=chromalink/@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/=exceptions/@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/=headset/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=headsetstand/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keypad/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mousepad/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
218
RGB.NET.Devices.Razer/RazerDeviceProvider.cs
Normal file
218
RGB.NET.Devices.Razer/RazerDeviceProvider.cs
Normal file
@ -0,0 +1,218 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Razer.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Razer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a device provider responsible for razer devices.
|
||||
/// </summary>
|
||||
public class RazerDeviceProvider : IRGBDeviceProvider
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private static RazerDeviceProvider _instance;
|
||||
/// <summary>
|
||||
/// Gets the singleton <see cref="RazerDeviceProvider"/> instance.
|
||||
/// </summary>
|
||||
public static RazerDeviceProvider Instance => _instance ?? new RazerDeviceProvider();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
|
||||
/// The first match will be used.
|
||||
/// </summary>
|
||||
public static List<string> PossibleX86NativePaths { get; } = new List<string> { "x86/RzChromaSDK.dll" };
|
||||
|
||||
/// <summary>
|
||||
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
|
||||
/// The first match will be used.
|
||||
/// </summary>
|
||||
public static List<string> PossibleX64NativePaths { get; } = new List<string> { "x64/RzChromaSDK.dll", "x64/RzChromaSDK64.dll" };
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Indicates if the SDK is initialized and ready to use.
|
||||
/// </summary>
|
||||
public bool IsInitialized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the loaded architecture (x64/x86).
|
||||
/// </summary>
|
||||
public string LoadedArchitecture => _RazerSDK.LoadedArchitecture;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets whether the application has exclusive access to the SDK or not.
|
||||
/// </summary>
|
||||
public bool HasExclusiveAccess => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IRGBDevice> Devices { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a function to get the culture for a specific device.
|
||||
/// </summary>
|
||||
public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
|
||||
|
||||
/// <summary>
|
||||
/// Forces to load the devices represented by the emulator even if they aren't reported to exist.
|
||||
/// </summary>
|
||||
public bool LoadEmulatorDevices { get; set; } = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RazerDeviceProvider"/> class.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
|
||||
public RazerDeviceProvider()
|
||||
{
|
||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}");
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
if (IsInitialized)
|
||||
TryUnInit();
|
||||
|
||||
IsInitialized = false;
|
||||
|
||||
try
|
||||
{
|
||||
_RazerSDK.Reload();
|
||||
|
||||
RazerError error;
|
||||
if ((error = _RazerSDK.Init()) != RazerError.Success)
|
||||
ThrowRazerError(error);
|
||||
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
|
||||
foreach ((Guid guid, string model) in Razer.Devices.KEYBOARDS)
|
||||
try
|
||||
{
|
||||
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
|
||||
&& (!LoadEmulatorDevices || (Razer.Devices.KEYBOARDS.FirstOrDefault().guid != guid))) continue;
|
||||
|
||||
RazerKeyboardRGBDevice device = new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo(guid, model, GetCulture()));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Mouse))
|
||||
foreach ((Guid guid, string model) in Razer.Devices.MICE)
|
||||
try
|
||||
{
|
||||
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
|
||||
&& (!LoadEmulatorDevices || (Razer.Devices.MICE.FirstOrDefault().guid != guid))) continue;
|
||||
|
||||
RazerMouseRGBDevice device = new RazerMouseRGBDevice(new RazerMouseRGBDeviceInfo(guid, model));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Headset))
|
||||
foreach ((Guid guid, string model) in Razer.Devices.HEADSETS)
|
||||
try
|
||||
{
|
||||
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
|
||||
&& (!LoadEmulatorDevices || (Razer.Devices.HEADSETS.FirstOrDefault().guid != guid))) continue;
|
||||
|
||||
RazerHeadsetRGBDevice device = new RazerHeadsetRGBDevice(new RazerHeadsetRGBDeviceInfo(guid, model));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Mousepad))
|
||||
foreach ((Guid guid, string model) in Razer.Devices.MOUSEMATS)
|
||||
try
|
||||
{
|
||||
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
|
||||
&& (!LoadEmulatorDevices || (Razer.Devices.MOUSEMATS.FirstOrDefault().guid != guid))) continue;
|
||||
|
||||
RazerMousepadRGBDevice device = new RazerMousepadRGBDevice(new RazerMousepadRGBDeviceInfo(guid, model));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Keypad))
|
||||
foreach ((Guid guid, string model) in Razer.Devices.KEYPADS)
|
||||
try
|
||||
{
|
||||
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
|
||||
&& (!LoadEmulatorDevices || (Razer.Devices.KEYPADS.FirstOrDefault().guid != guid))) continue;
|
||||
|
||||
RazerKeypadRGBDevice device = new RazerKeypadRGBDevice(new RazerKeypadRGBDeviceInfo(guid, model));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
|
||||
foreach ((Guid guid, string model) in Razer.Devices.CHROMALINKS)
|
||||
try
|
||||
{
|
||||
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
|
||||
&& (!LoadEmulatorDevices || (Razer.Devices.CHROMALINKS.FirstOrDefault().guid != guid))) continue;
|
||||
|
||||
RazerChromaLinkRGBDevice device = new RazerChromaLinkRGBDevice(new RazerChromaLinkRGBDeviceInfo(guid, model));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
TryUnInit();
|
||||
if (throwExceptions) throw;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ResetDevices()
|
||||
{
|
||||
foreach (IRGBDevice device in Devices)
|
||||
((IRazerRGBDevice)device).Reset();
|
||||
}
|
||||
|
||||
private void ThrowRazerError(RazerError errorCode) => throw new RazerException(errorCode);
|
||||
|
||||
private void TryUnInit()
|
||||
{
|
||||
try
|
||||
{
|
||||
_RazerSDK.UnInit();
|
||||
}
|
||||
catch { /* We tried our best */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
BIN
RGB.NET.Devices.Razer/libs/x64/RzChromaSDK.dll
Normal file
BIN
RGB.NET.Devices.Razer/libs/x64/RzChromaSDK.dll
Normal file
Binary file not shown.
BIN
RGB.NET.Devices.Razer/libs/x86/RzChromaSDK.dll
Normal file
BIN
RGB.NET.Devices.Razer/libs/x86/RzChromaSDK.dll
Normal file
Binary file not shown.
4
RGB.NET.Devices.Razer/packages.config
Normal file
4
RGB.NET.Devices.Razer/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="System.ValueTuple" version="4.3.1" targetFramework="net45" />
|
||||
</packages>
|
||||
150
RGB.NET.Devices.Razer/targets/RGB.NET.Devices.Razer.targets
Normal file
150
RGB.NET.Devices.Razer/targets/RGB.NET.Devices.Razer.targets
Normal 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>
|
||||
<RazerSDKFiles 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="'$(ContentRazerSDKFiles)' != '' And
|
||||
'$(ContentRazerSDKFiles)' != 'false' And
|
||||
'@(RazerSDKFiles)' != ''">
|
||||
<Content Include="@(RazerSDKFiles)">
|
||||
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
******************************************************************************
|
||||
** Build Targets* **
|
||||
******************************************************************************
|
||||
-->
|
||||
|
||||
<Target Name="CopyRazerSDKFiles"
|
||||
Condition="'$(CopyRazerSDKFiles)' != 'false' And
|
||||
'$(OutDir)' != '' And
|
||||
HasTrailingSlash('$(OutDir)') And
|
||||
Exists('$(OutDir)')"
|
||||
Inputs="@(RazerSDKFiles)"
|
||||
Outputs="@(RazerSDKFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')">
|
||||
<!--
|
||||
NOTE: Copy "RzChromaSDK.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="@(RazerSDKFiles)"
|
||||
DestinationFiles="@(RazerSDKFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
******************************************************************************
|
||||
-->
|
||||
|
||||
<Target Name="CleanRazerSDKFiles"
|
||||
Condition="'$(CleanRazerSDKFiles)' != 'false' And
|
||||
'$(OutDir)' != '' And
|
||||
HasTrailingSlash('$(OutDir)') And
|
||||
Exists('$(OutDir)')">
|
||||
|
||||
<!--
|
||||
NOTE: Delete "RzChromaSDK.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="@(RazerSDKFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
******************************************************************************
|
||||
-->
|
||||
|
||||
<Target Name="CollectRazerSDKFiles"
|
||||
Condition="'$(CollectRazerSDKFiles)' != 'false'">
|
||||
<Message Text="Collecting SDK files..." Importance="high" />
|
||||
<ItemGroup>
|
||||
<FilesForPackagingFromProject Include="@(RazerSDKFiles)">
|
||||
<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);
|
||||
CopyRazerSDKFiles;
|
||||
</PostBuildEventDependsOn>
|
||||
<BuildDependsOn>
|
||||
$(BuildDependsOn);
|
||||
CopyRazerSDKFiles;
|
||||
</BuildDependsOn>
|
||||
<CleanDependsOn>
|
||||
$(CleanDependsOn);
|
||||
CleanRazerSDKFiles;
|
||||
</CleanDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
******************************************************************************
|
||||
** Publish Properties for Visual Studio 201x **
|
||||
******************************************************************************
|
||||
-->
|
||||
|
||||
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' Or
|
||||
'$(VisualStudioVersion)' == '10.0' Or
|
||||
'$(VisualStudioVersion)' == '11.0' Or
|
||||
'$(VisualStudioVersion)' == '12.0'">
|
||||
<PipelineCollectFilesPhaseDependsOn>
|
||||
CollectRazerSDKFiles;
|
||||
$(PipelineCollectFilesPhaseDependsOn);
|
||||
</PipelineCollectFilesPhaseDependsOn>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
11
RGB.NET.sln
11
RGB.NET.sln
@ -34,12 +34,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{06416566
|
||||
NuGet\RGB.NET.Devices.Logitech.nuspec = NuGet\RGB.NET.Devices.Logitech.nuspec
|
||||
NuGet\RGB.NET.Devices.Msi.nuspec = NuGet\RGB.NET.Devices.Msi.nuspec
|
||||
NuGet\RGB.NET.Devices.Novation.nuspec = NuGet\RGB.NET.Devices.Novation.nuspec
|
||||
NuGet\RGB.NET.Devices.nuspec = NuGet\RGB.NET.Devices.nuspec
|
||||
NuGet\RGB.NET.Devices.Razer.nuspec = NuGet\RGB.NET.Devices.Razer.nuspec
|
||||
NuGet\RGB.NET.Groups.nuspec = NuGet\RGB.NET.Groups.nuspec
|
||||
NuGet\RGB.NET.Input.Corsair.nuspec = NuGet\RGB.NET.Input.Corsair.nuspec
|
||||
NuGet\RGB.NET.Input.nuspec = NuGet\RGB.NET.Input.nuspec
|
||||
NuGet\RGB.NET.nuspec = NuGet\RGB.NET.nuspec
|
||||
NuGet\RGB.NET.Presets.nuspec = NuGet\RGB.NET.Presets.nuspec
|
||||
NuGet\RGB.NET.WPF.nuspec = NuGet\RGB.NET.WPF.nuspec
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@ -70,6 +68,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metapackages", "Metapackage
|
||||
NuGet\Metapackages\RGB.NET.Presets.nuspec = NuGet\Metapackages\RGB.NET.Presets.nuspec
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.Razer", "RGB.NET.Devices.Razer\RGB.NET.Devices.Razer.csproj", "{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -128,6 +128,10 @@ Global
|
||||
{4EFD77C7-FDB4-4C6B-970C-0EF66D24BE09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4EFD77C7-FDB4-4C6B-970C-0EF66D24BE09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4EFD77C7-FDB4-4C6B-970C-0EF66D24BE09}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -146,6 +150,7 @@ Global
|
||||
{4F2F3FBD-A1E4-4968-A2AD-0514959E5E59} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
{4EFD77C7-FDB4-4C6B-970C-0EF66D24BE09} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
{C191D5BE-E1B2-47E4-AB39-D954B277188C} = {06416566-481F-4571-80EE-7BB05B1E0299}
|
||||
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CDECA6C7-8D18-4AF3-94F7-C70A69B8571B}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user