public virtual void sendToHardware() { if (isSending) { return; } isSending = true; int structSize = Marshal.SizeOf(typeof(CorsairLedColor)); IntPtr ptr = Marshal.AllocHGlobal(structSize * this.Colors.Count); IntPtr addPtr = new IntPtr(ptr.ToInt64()); foreach (CorsairLedColor corsairColor in this.Colors) { Marshal.StructureToPtr(corsairColor, addPtr, false); addPtr = new IntPtr(addPtr.ToInt64() + structSize); } CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(this.CorsairDeviceIndex, this.Colors.Count, ptr); CUESDK.CorsairSetLedsColorsFlushBuffer(); Marshal.FreeHGlobal(ptr); isSending = false; }
public ICueBridge() { CUESDK.LoadCUESDK(); CorsairProtocolDetails details = CUESDK.CorsairPerformProtocolHandshake(); CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl); int devCount = CUESDK.CorsairGetDeviceCount(); Debug.WriteLine("CorsairGetDeviceCount: {1}", "", devCount); for (int deviceIndex = 0; deviceIndex < devCount; deviceIndex++) { IntPtr deviceInfoPointer = CUESDK.CorsairGetDeviceInfo(deviceIndex); CorsairDeviceInfo DeviceInfo = (CorsairDeviceInfo)Marshal.PtrToStructure(deviceInfoPointer, typeof(CorsairDeviceInfo)); IntPtr ledPositionPointer = CUESDK.CorsairGetLedPositionsByDeviceIndex(deviceIndex); CorsairLedPositions LedPositions = (CorsairLedPositions)Marshal.PtrToStructure(ledPositionPointer, typeof(CorsairLedPositions)); switch (DeviceInfo.type) { case CorsairDeviceType.Keyboard: Debug.WriteLine("Keyboard LedPosition: {1}", "", LedPositions.numberOfLed); Keyboard = new Keyboard(); Keyboard.LedPositions = LedPositions; Keyboard.DeviceInfo = DeviceInfo; Keyboard.CorsairDeviceIndex = deviceIndex; break; case CorsairDeviceType.LightningNodePro: Debug.WriteLine("LightningNodePro LedPosition: {1}", "", LedPositions.numberOfLed); LedStrip = new LedStrip(); LedStrip.LedPositions = LedPositions; LedStrip.DeviceInfo = DeviceInfo; LedStrip.CorsairDeviceIndex = deviceIndex; break; } Debug.WriteLine("DeviceInfo: {1}", "", DeviceInfo.type); } }