public void LFXInit() { uint val = LightFXSDK.LFX_Initialize(); Global.logger.Debug("LFX: " + val); if (val == LightFXSDK.LFX_SUCCESS) { LightFXSDK.LFX_Reset(); LightFXSDK.LFX_SetTiming(40); uint numDevice = 0; isInitialized = true; usingHID = false; LightFXSDK.LFX_GetNumDevices(ref numDevice); /* * for (uint devIndex = 0; devIndex < numDevices; devIndex++) { * uint descSize = 255; * char* description = new char[descSize]; * byte devType = 0; * LightFXSDK.LFX_GetDeviceDescription(devIndex, description, descSize, &devType); * } */ } }
public bool UpdateDevice(Dictionary <DeviceKeys, Color> keyColors, DoWorkEventArgs e, bool forced = false) { if (e.Cancel) { return(false); } List <Color> leftColor = new List <Color>(); List <Color> midleftColor = new List <Color>(); List <Color> midRightColor = new List <Color>(); List <Color> rightColor = new List <Color>(); List <Color> numpadColor = new List <Color>(); try { if (e.Cancel) { return(false); } LightFXSDK.ResetColors(); if (usingHID) { int status = AlienfxWaitForBusy(); if (status == ALIENFX_DEVICE_RESET) { Thread.Sleep(1000); // continue; Global.logger.Debug("first reset false"); return(false); //AlienfxReinit(); } else if (status != ALIENFX_BUSY) { Thread.Sleep(50); // continue; Global.logger.Debug("Not busy false"); //return false; } Reset(0x04); Thread.Sleep(3); status = AlienfxWaitForReady(); if (status == 6) { Thread.Sleep(1000); //AlienfxReinit(); // continue; Global.logger.Debug("Reset false"); return(false); } else if (status != ALIENFX_READY) { if (status == ALIENFX_BUSY) { Reset(0x04); Thread.Sleep(3); status = AlienfxWaitForReady(); if (status == ALIENFX_DEVICE_RESET) { Thread.Sleep(1000); //AlienfxReinit(); // continue; Global.logger.Debug("last Reset false"); return(false); } } else { Thread.Sleep(50); // continue; return(false); } } } else { LightFXSDK.LFX_Reset(); } foreach (KeyValuePair <DeviceKeys, Color> key in keyColors) { if (e.Cancel) { return(false); } if (isInitialized) { //left if (Array.Exists(leftZoneKeys, s => s == key.Key) && (key.Value.R > 0 || key.Value.G > 0 || key.Value.B > 0)) { leftColor.Add(key.Value); } //middle left if (Array.Exists(midLeftZoneKeys, s => s == key.Key) && (key.Value.R > 0 || key.Value.G > 0 || key.Value.B > 0)) { midleftColor.Add(key.Value); }//middle right if (Array.Exists(midRightZoneKeys, s => s == key.Key) && (key.Value.R > 0 || key.Value.G > 0 || key.Value.B > 0)) { midRightColor.Add(key.Value); }//right */ if (Array.Exists(rightZoneKeys, s => s == key.Key) && (key.Value.R > 0 || key.Value.G > 0 || key.Value.B > 0)) { rightColor.Add(key.Value); } if (Array.Exists(numpadZone, s => s == key.Key) && (key.Value.R > 0 || key.Value.G > 0 || key.Value.B > 0)) { numpadColor.Add(key.Value); } if (key.Key == DeviceKeys.Peripheral_Logo) { setColor(1, (int)BITMASK.AlienFrontLogo, key.Value.R, key.Value.G, key.Value.B); if (!usingHID) { LightFXSDK.color.SetRGB(key.Value.R, key.Value.G, key.Value.B); LightFXSDK.LFX_SetLightColor(1, 5, ref LightFXSDK.color); } } } } if (NumLock) { midRightColor.AddRange(rightColor); rightColor.Clear(); rightColor = numpadColor; } if (leftColor.Any()) { var mostUsed = leftColor.GroupBy(item => item) .OrderByDescending(item => item.Count()) .Select(item => new { Color = item.Key, Count = item.Count() }) .First(); LightFXSDK.color4.SetRGB(mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(3, (int)BITMASK.LeftPanelTop, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(4, (int)BITMASK.leftZone, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); if (!usingHID) { LightFXSDK.LFX_SetLightColor(1, 0, ref LightFXSDK.color4); } } else { setColor(3, (int)BITMASK.LeftPanelTop, 0, 0, 0); setColor(4, (int)BITMASK.leftZone, 0, 0, 0); if (!usingHID) { LightFXSDK.color1.brightness = 0; LightFXSDK.LFX_SetLightColor(1, 0, ref LightFXSDK.color1); } } if (midleftColor.Any()) { // Global.logger.Debug("Updating midleftColor"); var mostUsed = midleftColor.GroupBy(item => item).OrderByDescending(item => item.Count()) .Select(item => new { Color = item.Key, Count = item.Count() }) .First(); LightFXSDK.color3.SetRGB(mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(5, (int)BITMASK.LeftPanelBottom, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(6, (int)BITMASK.leftMiddleZone, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); if (!usingHID) { LightFXSDK.LFX_SetLightColor(1, 2, ref LightFXSDK.color3); } //Global.logger.Info("Mid Left Codes: " + color3.red + " : " + color3.green + " : " + color3.blue); } else { setColor(5, (int)BITMASK.LeftPanelBottom, 0, 0, 0); setColor(6, (int)BITMASK.leftMiddleZone, 0, 0, 0); if (!usingHID) { LightFXSDK.color3.brightness = 0; LightFXSDK.LFX_SetLightColor(1, 2, ref LightFXSDK.color3); } } if (rightColor.Any()) { var mostUsed = rightColor.GroupBy(item => item) .OrderByDescending(item => item.Count()) .Select(item => new { Color = item.Key, Count = item.Count() }) .First(); LightFXSDK.color1.SetRGB(mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(7, (int)BITMASK.RightPanelTop, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(8, (int)BITMASK.rightZone, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); if (!usingHID) { LightFXSDK.LFX_SetLightColor(1, 3, ref LightFXSDK.color1); } } else { if (!usingHID) { LightFXSDK.color1.brightness = 0; LightFXSDK.LFX_SetLightColor(1, 3, ref LightFXSDK.color1); } setColor(7, (int)BITMASK.RightPanelTop, 0, 0, 0); setColor(8, (int)BITMASK.rightZone, 0, 0, 0); } if (midRightColor.Any()) { var mostUsed = midRightColor.GroupBy(item => item) .OrderByDescending(item => item.Count()) .Select(item => new { Color = item.Key, Count = item.Count() }) .First(); LightFXSDK.color2.SetRGB(mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(9, (int)BITMASK.RightPanelBottom, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); setColor(10, (int)BITMASK.rightMiddleZone, mostUsed.Color.R, mostUsed.Color.G, mostUsed.Color.B); if (!usingHID) { LightFXSDK.LFX_SetLightColor(1, 4, ref LightFXSDK.color2); } //Global.logger.Info("Mid Right Codes: " + color2.red + " : " + color2.green + " : " + color2.blue); } else { if (!usingHID) { LightFXSDK.color1.brightness = 0; LightFXSDK.LFX_SetLightColor(1, 4, ref LightFXSDK.color1); } setColor(9, (int)BITMASK.RightPanelBottom, 0, 0, 0); setColor(10, (int)BITMASK.rightMiddleZone, 0, 0, 0); } // setColor(1, TouchPad, color5.red, color5.green, color5.blue); ExecuteColors(); if (!usingHID) { LightFXSDK.LFX_Update(); } leftColor.Clear(); midleftColor.Clear(); rightColor.Clear(); midRightColor.Clear(); if (e.Cancel) { return(false); } return(true); } catch (Exception exc) { Global.logger.Error("LightFX device, error when updating device. Error: " + exc); Console.WriteLine(exc); return(false); } }