public async void BlinkLight(IAuraSyncDevice device, int lightId) { if (tokenSource != null && !tokenSource.Token.IsCancellationRequested) { tokenSource.Cancel(); } tokenSource = new CancellationTokenSource(); for (int i = 0; i < BlinkCount; i++) { if (tokenSource.IsCancellationRequested || device == null) { return; } // set everything to black foreach (IAuraRgbLight light in device.Lights) { light.Color = 0; } // set this one key to white if (i % 2 == 1) { device.Lights[lightId].Red = 255; device.Lights[lightId].Green = 255; device.Lights[lightId].Blue = 255; } device.Apply(); await Task.Delay(200); // ms } }
public void setLights(int r, int g, int b) { Console.WriteLine($"{name}: Called setLights"); if (!busy) { busy = true; Task.Run(() => { Console.WriteLine($"{name}: Setting colors"); foreach (IAuraRgbLight light in device.Lights) { light.Red = (byte)r; light.Green = (byte)g; light.Blue = (byte)b; } Console.WriteLine($"{name}: Starting applying"); device.Apply(); Console.WriteLine($"{name}: Done"); busy = false; }); } else { Console.WriteLine($"{name}: Return because is busy"); } }
public Task ApplyAsync(IVirtualLedGrid virtualGrid, CancellationToken cancellationToken = default) { if (_sdk == null || this._notebookKeyboard == null) { return(Task.CompletedTask); } foreach (var key in virtualGrid.Where(x => x.Type != KeyType.Headset)) { var color = ToRGBNetColor(key.Color); switch (key.FriendlyName) { case "Enter": _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.OemEnterLed0].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.OemEnterLed1].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.OemEnterLed2].Color = color; break; case "RightShift": _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.RightShiftLed0].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.RightShiftLed1].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.RightShiftLed2].Color = color; break; case "Backspace": _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.BackspaceLed0].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.BackspaceLed1].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.BackspaceLed2].Color = color; break; case "Space": _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.SpaceLed0].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.SpaceLed1].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.SpaceLed2].Color = color; _notebookKeyboard.Lights[(int)RogStrixKeyboardMap.SpaceLed3].Color = color; break; default: var asusKey = KeyConvert(key.FriendlyName); if (asusKey == RogStrixKeyboardMap.GhostKey) { continue; } var led = _notebookKeyboard.Lights[(int)asusKey]; if (led == null) { continue; } led.Color = color; break; } } _notebookKeyboard.Apply(); return(Task.CompletedTask); }
/// <summary> /// Applies light changes to the device /// </summary> public void ApplyLights() { try { if (NumberOfLights > 0) { _device.Apply(); } } catch (COMException ex) { _logger.LogError(ex, "Failed Applying Lights"); } }
public void Start() { if (!tokenSource.IsCancellationRequested) { tokenSource.Cancel(); } tokenSource = new CancellationTokenSource(); // create a scary parallel thread var parallelOptions = new ParallelOptions(); parallelOptions.CancellationToken = tokenSource.Token; // set every key to black foreach (IAuraRgbLight light in device.Lights) { light.Color = 0; } device.Apply(); Parallel.Invoke(parallelOptions, () => Thread(tokenSource.Token)); Active = true; }
/// <inheritdoc/> public Task ApplyAsync(IVirtualLedGrid virtualGrid, CancellationToken cancellationToken = default) { if (!this.Initialized) { return(Task.CompletedTask); } for (var row = 0; row < virtualGrid.RowCount; row++) { var physicalRow = _representor[row]; for (var col = 0; col < virtualGrid.ColumnCount; col++) { var cellColor = virtualGrid[col, row]; if (cellColor == null) { continue; } var key = physicalRow[col]; if (IsInvalidKey(key)) { continue; } var color = ToUint(cellColor.Value); _notebookKeyboard.Lights[(int)key].Color = color; } } _notebookKeyboard.Apply(); return(Task.CompletedTask); }