diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs
index 4d60169..f8e3834 100644
--- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs
+++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs
@@ -5,9 +5,8 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
-using System.Runtime.InteropServices;
+using AuraServiceLib;
using RGB.NET.Core;
-using RGB.NET.Devices.Asus.Native;
namespace RGB.NET.Devices.Asus
{
@@ -25,29 +24,12 @@ namespace RGB.NET.Devices.Asus
///
public static AsusDeviceProvider Instance => _instance ?? new AsusDeviceProvider();
- ///
- /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
- /// The first match will be used.
- ///
- public static List PossibleX86NativePaths { get; } = new List { "x86/AURA_SDK.dll" };
-
- ///
- /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
- /// The first match will be used.
- ///
- public static List PossibleX64NativePaths { get; } = new List { };
-
///
///
/// Indicates if the SDK is initialized and ready to use.
///
public bool IsInitialized { get; private set; }
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _AsusSDK.LoadedArchitecture;
-
///
///
/// Gets whether the application has exclusive access to the SDK or not.
@@ -68,6 +50,8 @@ namespace RGB.NET.Devices.Asus
///
public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ private IAuraSdk2 _sdk;
+
#endregion
#region Constructors
@@ -97,137 +81,73 @@ namespace RGB.NET.Devices.Asus
{
UpdateTrigger?.Stop();
- _AsusSDK.Reload();
+ // ReSharper disable once SuspiciousTypeConversion.Global
+ _sdk = (IAuraSdk2)new AuraSdk();
+ _sdk.SwitchMode();
IList devices = new List();
-
- #region Mainboard
-
- if (loadFilter.HasFlag(RGBDeviceType.Mainboard))
+ foreach (IAuraSyncDevice device in _sdk.Enumerate(0))
+ {
try
{
- //TODO DarthAffe 26.11.2017: This is not a fix! There might really be a second controller on the mainboard, but for now this should prevent the random crash for some guys.
- // DarthAffe 26.11.2017: https://rog.asus.com/forum/showthread.php?97754-Access-Violation-Wrong-EnumerateMB-Result&p=688901#post688901
- int mainboardCount = Math.Min(1, _AsusSDK.EnumerateMbController(IntPtr.Zero, 0));
- if (mainboardCount > 0)
+ IAsusRGBDevice rgbDevice = null;
+ switch (device.Type)
{
- IntPtr mainboardHandles = Marshal.AllocHGlobal(mainboardCount * IntPtr.Size);
- _AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount);
+ case 0x00010000: //Motherboard
+ rgbDevice = new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name));
+ break;
- for (int i = 0; i < mainboardCount; i++)
- {
- try
- {
- IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i);
- _AsusSDK.SetMbMode(handle, 1);
- AsusMainboardRGBDevice device = new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
- device.Initialize(UpdateTrigger);
- devices.Add(device);
- }
- catch { if (throwExceptions) throw; }
- }
+ case 0x00011000: //Motherboard LED Strip
+ rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1);
+ break;
+
+ case 0x00020000: //VGA
+ rgbDevice = new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device));
+ break;
+
+ case 0x00040000: //Headset
+ rgbDevice = new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device));
+ break;
+
+ case 0x00070000: //DRAM
+ rgbDevice = new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device));
+ break;
+
+ case 0x00080000: //Keyboard
+ case 0x00081000: //Notebook Keyboard
+ case 0x00081001: //Notebook Keyboard(4 - zone type)
+ rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture));
+ break;
+
+ case 0x00090000: //Mouse
+ rgbDevice = new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device));
+ break;
+
+ case 0x00000000: //All
+ case 0x00012000: //All - In - One PC
+ case 0x00030000: //Display
+ case 0x00050000: //Microphone
+ case 0x00060000: //External HDD
+ case 0x00061000: //External BD Drive
+ case 0x000B0000: //Chassis
+ case 0x000C0000: //Projector
+ rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1);
+ break;
+ }
+
+ if ((rgbDevice != null) && loadFilter.HasFlag(rgbDevice.DeviceInfo.DeviceType))
+ {
+ rgbDevice.Initialize(UpdateTrigger);
+ devices.Add(rgbDevice);
}
}
- catch { if (throwExceptions) throw; }
-
- #endregion
-
- #region Graphics cards
-
- //TODO DarthAffe 21.10.2017: This somehow returns non-existant gpus (at least for me) which cause huge lags (if a real asus-ready gpu is connected this doesn't happen)
-
- if (loadFilter.HasFlag(RGBDeviceType.GraphicsCard))
- try
+ catch
{
- int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
- if (graphicCardCount > 0)
- {
- IntPtr grapicsCardHandles = Marshal.AllocHGlobal(graphicCardCount * IntPtr.Size);
- _AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount);
-
- for (int i = 0; i < graphicCardCount; i++)
- {
- try
- {
- IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i);
- _AsusSDK.SetGPUMode(handle, 1);
- AsusGraphicsCardRGBDevice device = new AsusGraphicsCardRGBDevice(new AsusGraphicsCardRGBDeviceInfo(RGBDeviceType.GraphicsCard, handle));
- device.Initialize(UpdateTrigger);
- devices.Add(device);
- }
- catch { if (throwExceptions) throw; }
- }
- }
+ if (throwExceptions)
+ throw;
}
- catch { if (throwExceptions) throw; }
+ }
- #endregion
-
- #region DRAM
-
- //TODO DarthAffe 29.10.2017: I don't know why they are even documented, but the asus guy said they aren't in the SDK right now.
- //try
- //{
- //int dramCount = _AsusSDK.EnumerateDram(IntPtr.Zero, 0);
- //if (dramCount > 0)
- //{
- // IntPtr dramHandles = Marshal.AllocHGlobal(dramCount * IntPtr.Size);
- // _AsusSDK.EnumerateDram(dramHandles, dramCount);
-
- // for (int i = 0; i < dramCount; i++)
- // {
- //try
- //{
- // IntPtr handle = Marshal.ReadIntPtr(dramHandles, i);
- // _AsusSDK.SetDramMode(handle, 1);
- // AsusDramRGBDevice device = new AsusDramRGBDevice(new AsusDramRGBDeviceInfo(RGBDeviceType.DRAM, handle));
- // device.Initialize(UpdateTrigger);
- // devices.Add(device);
- // }
- //catch { if (throwExceptions) throw; }
- // }
- //}
- //}
- // catch { if (throwExceptions) throw; }
-
- #endregion
-
- #region Keyboard
-
- if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
- try
- {
- IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size);
- if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle))
- {
- _AsusSDK.SetClaymoreKeyboardMode(keyboardHandle, 1);
- AsusKeyboardRGBDevice device = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(RGBDeviceType.Keyboard, keyboardHandle, GetCulture()));
- device.Initialize(UpdateTrigger);
- devices.Add(device);
- }
- }
- catch { if (throwExceptions) throw; }
-
- #endregion
-
- #region Mouse
-
- if (loadFilter.HasFlag(RGBDeviceType.Mouse))
- try
- {
- IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size);
- if (_AsusSDK.CreateRogMouse(mouseHandle))
- {
- _AsusSDK.SetRogMouseMode(mouseHandle, 1);
- AsusMouseRGBDevice device = new AsusMouseRGBDevice(new AsusMouseRGBDeviceInfo(RGBDeviceType.Mouse, mouseHandle));
- device.Initialize(UpdateTrigger);
- devices.Add(device);
- }
- }
- catch { if (throwExceptions) throw; }
-
- #endregion
-
UpdateTrigger?.Start();
Devices = new ReadOnlyCollection(devices);
@@ -239,34 +159,22 @@ namespace RGB.NET.Devices.Asus
throw;
return false;
}
-
return true;
}
///
public void ResetDevices()
{
- foreach (IRGBDevice device in Devices)
- {
- AsusRGBDeviceInfo deviceInfo = (AsusRGBDeviceInfo)device.DeviceInfo;
- switch (deviceInfo.DeviceType)
- {
- case RGBDeviceType.Mainboard:
- _AsusSDK.SetMbMode(deviceInfo.Handle, 0);
- break;
- case RGBDeviceType.GraphicsCard:
- _AsusSDK.SetGPUMode(deviceInfo.Handle, 0);
- break;
- //case RGBDeviceType.DRAM:
- // _AsusSDK.SetDramMode(deviceInfo.Handle, 0);
- // break;
- }
- }
+ _sdk?.ReleaseControl(0);
+ _sdk?.SwitchMode();
}
///
public void Dispose()
- { }
+ {
+ _sdk?.ReleaseControl(0);
+ _sdk = null;
+ }
#endregion
}
diff --git a/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs b/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs
index 6cdc398..7e74550 100644
--- a/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs
+++ b/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs
@@ -1,56 +1,44 @@
-//using RGB.NET.Core;
-//using RGB.NET.Devices.Asus.Native;
+using RGB.NET.Core;
-//namespace RGB.NET.Devices.Asus
-//{
-// ///
-// ///
-// /// Represents a Asus dram.
-// ///
-// public class AsusDramRGBDevice : AsusRGBDevice
-// {
-// #region Properties & Fields
+namespace RGB.NET.Devices.Asus
+{
+ ///
+ ///
+ /// Represents a Asus dram.
+ ///
+ public class AsusDramRGBDevice : AsusRGBDevice
+ {
+ #region Constructors
-// ///
-// /// Gets information about the .
-// ///
-// public AsusDramRGBDeviceInfo DramDeviceInfo { get; }
+ ///
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The specific information provided by Asus for the DRAM.
+ internal AsusDramRGBDevice(AsusRGBDeviceInfo info)
+ : base(info)
+ { }
-// #endregion
+ #endregion
-// #region Constructors
+ #region Methods
-// ///
-// ///
-// /// Initializes a new instance of the class.
-// ///
-// /// The specific information provided by Asus for the DRAM.
-// internal AsusDramRGBDevice(AsusDramRGBDeviceInfo info)
-// : base(info)
-// {
-// this.DramDeviceInfo = info;
-// }
+ ///
+ protected override void InitializeLayout()
+ {
+ //TODO DarthAffe 07.10.2017: Look for a good default layout
+ int ledCount = DeviceInfo.Device.Lights.Count;
+ for (int i = 0; i < ledCount; i++)
+ InitializeLed(LedId.DRAM1 + i, new Rectangle(i * 10, 0, 10, 10));
-// #endregion
+ //TODO DarthAffe 21.10.2017: We don't know the model, how to save layouts and images?
+ //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
+ ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Drams\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
+ }
-// #region Methods
+ ///
+ protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.DRAM1;
-// ///
-// protected override void InitializeLayout()
-// {
-// //TODO DarthAffe 21.10.2017: Look for a good default layout
-// int ledCount = _AsusSDK.GetGPULedCount(DramDeviceInfo.Handle);
-// for (int i = 0; i < ledCount; i++)
-// InitializeLed(new AsusLedId(this, AsusLedIds.DramLed1 + i, i), new Rectangle(i * 10, 0, 10, 10));
-
-// //TODO DarthAffe 21.10.2017: We don't know the model, how to save layouts and images?
-// ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Drams\{DramDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"),
-// null, PathHelper.GetAbsolutePath(@"Images\Asus\Drams"));
-// }
-
-// ///
-// protected override void ApplyColorData() => _AsusSDK.SetDramColor(DramDeviceInfo.Handle, ColorData);
-
-// #endregion
-// }
-//}
+ #endregion
+ }
+}
diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs
index 083cafd..0241828 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs
@@ -1,7 +1,5 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using System.Runtime.InteropServices;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
@@ -59,7 +57,7 @@ namespace RGB.NET.Devices.Asus
}
UpdateQueue = new AsusUpdateQueue(updateTrigger);
- UpdateQueue.Initialize(GetUpdateColorAction(), DeviceInfo.Handle, LedMapping.Count);
+ UpdateQueue.Initialize(DeviceInfo.Device);
}
///
@@ -70,20 +68,16 @@ namespace RGB.NET.Devices.Asus
///
protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
- ///
- /// Gets a action to update the physical device.
- ///
- ///
- protected abstract Action GetUpdateColorAction();
-
- ///
- ///
- public override void Dispose()
+ ///
+ public override void SyncBack()
{
- if ((DeviceInfo is AsusRGBDeviceInfo deviceInfo) && (deviceInfo.Handle != IntPtr.Zero))
- Marshal.FreeHGlobal(deviceInfo.Handle);
-
- base.Dispose();
+ // DarthAffe 16.06.2019: This doesn't work since the SDK only returns the colors we set.
+ //foreach (Led led in LedMapping.Values)
+ //{
+ // int index = (int)led.CustomData;
+ // IAuraRgbLight light = DeviceInfo.Device.Lights[index];
+ // SetLedColorWithoutRequest(led, new Color(light.Red, light.Green, light.Blue));
+ //}
}
#endregion
diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
index 7c6ff69..62c7ea9 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
@@ -1,4 +1,5 @@
using System;
+using AuraServiceLib;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
@@ -7,7 +8,7 @@ namespace RGB.NET.Devices.Asus
///
/// Represents a generic information for a Corsair-.
///
- public abstract class AsusRGBDeviceInfo : IRGBDeviceInfo
+ public class AsusRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
@@ -30,12 +31,9 @@ namespace RGB.NET.Devices.Asus
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
///
- public abstract bool SupportsSyncBack { get; }
+ public bool SupportsSyncBack => false;
- ///
- /// Gets the index of the .
- ///
- internal IntPtr Handle { get; }
+ public IAuraSyncDevice Device { get; }
#endregion
@@ -45,14 +43,14 @@ namespace RGB.NET.Devices.Asus
/// Internal constructor of managed .
///
/// The type of the .
- /// The handle of the .
+ /// The backing this RGB.NET device.
/// The manufacturer-name of the .
/// The model-name of the .
- internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IntPtr handle, string model = "Generic Asus-Device", string manufacturer = "Asus")
+ internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IAuraSyncDevice device, string model = null, string manufacturer = "Asus")
{
this.DeviceType = deviceType;
- this.Handle = handle;
- this.Model = model;
+ this.Device = device;
+ this.Model = model ?? device.Name;
this.Manufacturer = manufacturer;
DeviceName = $"{Manufacturer} {Model}";
diff --git a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs
new file mode 100644
index 0000000..3515596
--- /dev/null
+++ b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs
@@ -0,0 +1,49 @@
+using RGB.NET.Core;
+
+namespace RGB.NET.Devices.Asus
+{
+ ///
+ ///
+ /// Represents a Asus headset.
+ ///
+ public class AsusUnspecifiedRGBDevice : AsusRGBDevice
+ {
+ #region Properties & Fields
+
+ private LedId _baseLedId;
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The specific information provided by Asus for the headset.
+ internal AsusUnspecifiedRGBDevice(AsusRGBDeviceInfo info, LedId baseLedId)
+ : base(info)
+ {
+ this._baseLedId = baseLedId;
+ }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ protected override void InitializeLayout()
+ {
+ int ledCount = DeviceInfo.Device.Lights.Count;
+ for (int i = 0; i < ledCount; i++)
+ InitializeLed(_baseLedId + i, new Rectangle(i * 10, 0, 10, 10));
+
+ //TODO DarthAffe 19.05.2019: Add a way to define a layout for this kind of devies
+ }
+
+ ///
+ protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)_baseLedId;
+
+ #endregion
+ }
+}
diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
index 28fa936..fb32a3e 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using AuraServiceLib;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
@@ -13,13 +14,9 @@ namespace RGB.NET.Devices.Asus
#region Properties & Fields
///
- /// Gets or sets the internal color-data cache.
+ /// The device to be updated.
///
- // ReSharper disable once MemberCanBePrivate.Global
- protected byte[] ColorData { get; private set; }
-
- private Action _updateAction;
- private IntPtr _handle;
+ protected IAuraSyncDevice Device { get; private set; }
#endregion
@@ -40,29 +37,31 @@ namespace RGB.NET.Devices.Asus
///
/// Initializes the queue.
///
- /// The update-action called by the queue to perform updates.
- /// The handle of the device this queue performs updates for.
- /// The amount of leds of the device this queue performs updates for.
- public void Initialize(Action updateAction, IntPtr handle, int ledCount)
+ /// The device to be updated.
+ public void Initialize(IAuraSyncDevice device)
{
- _updateAction = updateAction;
- _handle = handle;
-
- ColorData = new byte[ledCount * 3];
+ Device = device;
}
///
protected override void Update(Dictionary