/// <inheritdoc /> public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { IsInitialized = false; try { UpdateTrigger?.Stop(); // ReSharper disable once SuspiciousTypeConversion.Global _sdk = (IAuraSdk2) new AuraSdk(); _sdk.SwitchMode(); IList <IRGBDevice> devices = new List <IRGBDevice>(); foreach (IAuraSyncDevice device in _sdk.Enumerate(0)) { try { IAsusRGBDevice rgbDevice; switch ((AsusDeviceType)device.Type) { case AsusDeviceType.MB_RGB: rgbDevice = new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name)); break; case AsusDeviceType.MB_ADDRESABLE: rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1); break; case AsusDeviceType.VGA_RGB: rgbDevice = new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device)); break; case AsusDeviceType.HEADSET_RGB: rgbDevice = new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device)); break; case AsusDeviceType.DRAM_RGB: rgbDevice = new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device)); break; case AsusDeviceType.KEYBOARD_RGB: case AsusDeviceType.NB_KB_RGB: case AsusDeviceType.NB_KB_4ZONE_RGB: rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture)); break; case AsusDeviceType.MOUSE_RGB: rgbDevice = new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device)); break; default: rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1); break; } if (loadFilter.HasFlag(rgbDevice.DeviceInfo.DeviceType)) { rgbDevice.Initialize(UpdateTrigger); devices.Add(rgbDevice); } } catch { if (throwExceptions) { throw; } } } UpdateTrigger?.Start(); Devices = new ReadOnlyCollection <IRGBDevice>(devices); IsInitialized = true; } catch { if (throwExceptions) { throw; } return(false); } return(true); }
/// <inheritdoc /> public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { IsInitialized = false; try { UpdateTrigger?.Stop(); _AsusSDK.Reload(); IList <IRGBDevice> devices = new List <IRGBDevice>(); #region Mainboard if (loadFilter.HasFlag(RGBDeviceType.Mainboard)) { 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) { IntPtr mainboardHandles = Marshal.AllocHGlobal(mainboardCount * IntPtr.Size); _AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount); 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; } } } } } 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 { 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; } } } } } 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 <IRGBDevice>(devices); IsInitialized = true; } catch { if (throwExceptions) { throw; } return(false); } return(true); }
/// <inheritdoc /> public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { IsInitialized = false; try { UpdateTrigger?.Stop(); // ReSharper disable once SuspiciousTypeConversion.Global _sdk = (IAuraSdk2) new AuraSdk(); _sdk.SwitchMode(); IList <IRGBDevice> devices = new List <IRGBDevice>(); foreach (IAuraSyncDevice device in _sdk.Enumerate(0)) { try { IAsusRGBDevice rgbDevice = null; switch (device.Type) { case 0x00010000: //Motherboard rgbDevice = new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name)); break; 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; } } } UpdateTrigger?.Start(); Devices = new ReadOnlyCollection <IRGBDevice>(devices); IsInitialized = true; } catch { if (throwExceptions) { throw; } return(false); } return(true); }