public async Task SetColorAsync(LedCommand command) { // Turn off all the pins (i.e., it turns off the led). await gpioService.SetPinAsync(redPinNumber, PinValue.Low); await gpioService.SetPinAsync(greenPinNumber, PinValue.Low); await gpioService.SetPinAsync(bluePinNumber, PinValue.Low); // Check which color (i.e. pin) to enable. int?pin = command.Color?.ToLower() switch { "red" => redPinNumber, "green" => greenPinNumber, "blue" => bluePinNumber, "black" => null, null => null, _ => throw new NotSupportedException() }; if (pin.HasValue) { await gpioService.SetPinAsync(pin.Value, PinValue.High); } } }
private void LedMatrixInit() { BrushConverter bc = new BrushConverter(); int[] ledColors = InitialColors; Grid grid = new Grid() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; for (int i = 0; i < 8; i++) { grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); for (int j = 0; j < 8; j++) { grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); Rectangle rect = new Rectangle() { Fill = new SolidColorBrush(Color.FromArgb(153, (byte)((ledColors[i * 8 + j] >> 16) & 0xFF), (byte)((ledColors[i * 8 + j] >> 8) & 0xFF), (byte)((ledColors[i * 8 + j] >> 0) & 0xFF))), Width = 30, Height = 30, Margin = new Thickness(5, 5, 5, 5), }; LedClicked = new LedCommand(this, i, j); MouseAction action = MouseAction.LeftClick; MouseGesture gesture = new MouseGesture(action); MouseBinding binding = new MouseBinding(LedClicked, gesture); rect.InputBindings.Add(binding); Grid.SetRow(rect, i); Grid.SetColumn(rect, j); grid.Children.Add(rect); ledMatrix.Add(Tuple.Create(i, j), rect); ledMatrixData[i * 8 + j] = initialColor; } } ViewLedMatrix = grid; }
public static void Main(string[] args) { ICommand command = null; if (args.Length > 0) { switch (args[0]) { case "devices": command = new DevicesCommand(); break; case "passthrough": command = new PassthroughCommand(); break; case "led": command = new LedCommand(); break; case "visualize": command = new VisualizeCommand(); break; } } if (command != null) { Console.CancelKeyPress += (sender, e) => { Console.WriteLine("Finalizing..."); command.Dispose(); }; using (command) { command.Execute(args); } } else { Console.WriteLine("Ws281x.Visualizer"); } }
public async Task <IActionResult> LedCommand(LedCommand command) { await ledService.SetColorAsync(command); return(NoContent()); }