public void CheckLedChange() { Stopwatch sw = Stopwatch.StartNew(); var client = new OpenRGBClient(name: "OpenRGB.NET Test: CheckLedChange"); var controllerCount = client.GetControllerCount(); var devices = new Device[controllerCount]; for (int i = 0; i < controllerCount; i++) { devices[i] = client.GetControllerData(i); } for (int i = 0; i < controllerCount; i++) { var device = devices[i]; var originalColors = Color.GetHueRainbow(device.Leds.Length); client.UpdateLeds(i, originalColors.ToArray()); var updatedColors = client.GetControllerData(i).Colors; Assert.True(updatedColors.SequenceEqual(originalColors)); } client.Dispose(); sw.Stop(); Output.WriteLine($"Time elapsed: {(double)sw.ElapsedTicks / Stopwatch.Frequency * 1000} ms."); }
public void UpdateZoneTypes() { //This delay is needed due to a threading bug in OpenRGB //https://gitlab.com/CalcProgrammer1/OpenRGB/-/issues/376 //https://gitlab.com/CalcProgrammer1/OpenRGB/-/issues/350 Thread.Sleep(150); Stopwatch sw = Stopwatch.StartNew(); var client = new OpenRGBClient(name: "OpenRGB.NET Test: UpdateZoneTypes"); var controllerCount = client.GetControllerCount(); var devices = new Device[controllerCount]; for (int i = 0; i < controllerCount; i++) { devices[i] = client.GetControllerData(i); } for (int i = 0; i < controllerCount; i++) { var device = devices[i]; for (int j = 0; j < device.Zones.Length; j++) { var zone = device.Zones[j]; switch (zone.Type) { case Enums.ZoneType.Linear: var colors = Color.GetHueRainbow((int)zone.LedCount); client.UpdateZone(i, j, colors.ToArray()); break; case Enums.ZoneType.Single: client.UpdateZone(i, j, new[] { new Color(255, 0, 0) }); break; case Enums.ZoneType.Matrix: var yeet = 2 * Math.PI / zone.MatrixMap.Width; var rainbow = Color.GetHueRainbow((int)zone.MatrixMap.Width).ToArray(); //var rainbow = Color.GetSinRainbow((int)zone.MatrixMap.Width).ToArray(); var matrix = Enumerable.Range(0, (int)zone.LedCount).Select(_ => new Color()).ToArray(); for (int k = 0; k < zone.MatrixMap.Width; k++) { for (int l = 0; l < zone.MatrixMap.Height; l++) { var index = zone.MatrixMap.Matrix[l, k]; if (index != uint.MaxValue) { matrix[index] = rainbow[k].Clone(); } } } client.UpdateZone(i, j, matrix); break; } } } client.Dispose(); sw.Stop(); Output.WriteLine($"Time elapsed: {(double)sw.ElapsedTicks / Stopwatch.Frequency * 1000} ms."); }
private void DoDryRun(int nbDryRun) { for (int i = 0; i < nbDryRun; i++) { using OpenRGBClient client = new OpenRGBClient(name: "OpenRGB.NET Test: DryRun"); int nbController = client.GetControllerCount(); for (int j = 0; j < nbController; j++) { Device controller = client.GetControllerData(j); Assert.True(!string.IsNullOrWhiteSpace(controller.Name)); } } }
public void DisposePatternListController() { Stopwatch sw = Stopwatch.StartNew(); using OpenRGBClient client = new OpenRGBClient(name: "OpenRGB.NET Test: DisposePatternListController", autoconnect: true); int nbController = client.GetControllerCount(); for (int i = 0; i < nbController; i++) { Device controller = client.GetControllerData(i); Assert.True(!string.IsNullOrWhiteSpace(controller.Name)); } sw.Stop(); Output.WriteLine($"Time elapsed: {(double)sw.ElapsedTicks / Stopwatch.Frequency * 1000} ms."); }
/// <inheritdoc /> public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { IsInitialized = false; try { UpdateTrigger?.Stop(); openRgb = new OpenRGBClient(port: 1337, name: "JackNet RGBSync"); openRgb.Connect(); int controllerCount = openRgb.GetControllerCount(); var devices = new List <OpenRGBDevice>(); //IOpenRGBDevice _device = null; IList <IRGBDevice> _devices = new List <IRGBDevice>(); for (int i = 0; i < controllerCount; i++) { devices.Add(openRgb.GetControllerData(i)); } for (int i = 0; i < devices.Count; i++) { OpenRGBUpdateQueue updateQueue = new OpenRGBUpdateQueue(UpdateTrigger, i, openRgb, devices[i].leds.Length); IOpenRGBDevice _device = new OpenRGBUnspecifiedRGBDevice(new OpenRGBDeviceInfo(RGBDeviceType.Unknown, i + " " + devices[i].name, "OpenRGB")); _device.Initialize(updateQueue, devices[i].leds.Length); _devices.Add(_device); /* * var list = new OpenRGBColor[devices[i].leds.Length]; * for (int j = 0; j < devices[i].leds.Length; j++) * { * list[j] = new OpenRGBColor(0, 255, 0); * } * openRgb.UpdateLeds(i, list); */ } UpdateTrigger?.Start(); Devices = new ReadOnlyCollection <IRGBDevice>(_devices); IsInitialized = true; } catch (Exception ex) { throw; } return(true); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var devices = new List <Tuple <OpenRGBDevice, ILedPattern> >(); var client = new OpenRGBClient(name: "SimpleOpenRGBColorSetter", autoconnect: false); while (!stoppingToken.IsCancellationRequested) // Attempt to connect, forever. { try { client.Connect(); break; } catch (TimeoutException) { _logger.LogError("Failed to connect to OpenRGB, retrying..."); await Task.Delay(1000, stoppingToken); } } if (stoppingToken.IsCancellationRequested) { return; } var maxDeviceIndex = client.GetControllerCount(); for (var deviceIndex = 0; deviceIndex < maxDeviceIndex; deviceIndex++) { if (stoppingToken.IsCancellationRequested) { return; } var device = client.GetControllerData(deviceIndex); int?staticModeIndex = null; int?directModeIndex = null; for (int i = 0; i < device.Modes.Length; i++) { if (device.Modes[i].Name.ToLowerInvariant() == "static") { staticModeIndex = i; } else if (device.Modes[i].Name.ToLowerInvariant() == "direct") { directModeIndex = i; } if (staticModeIndex != null && directModeIndex != null) { break; } } if (staticModeIndex == null || directModeIndex == null) { _logger.LogError($"Device '{device.Name}' is missing a Static or Direct mode."); continue; } // First set Static then Direct to work around OpenRGB issue #444, which happens with basically random devices. client.SetMode(deviceIndex, staticModeIndex.Value); await Task.Delay(100, stoppingToken); // Letting OpenRGB catch up a bit... client.SetMode(deviceIndex, directModeIndex.Value); for (int zoneIndex = 0; zoneIndex < device.Zones.Length; zoneIndex++) { var abstractedDevice = new OpenRGBDevice(client, deviceIndex, zoneIndex); var effect = new StaticLedPattern(abstractedDevice, new Color(0, 255, 255)); //var effect = new SineLedPattern(abstractedDevice, new Color(0, 255, 255), new Color(255, 80, 0)); devices.Add(new Tuple <OpenRGBDevice, ILedPattern>(abstractedDevice, effect)); } } var lastTime = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; while (true) { if (stoppingToken.IsCancellationRequested) { return; } var now = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; foreach (var deviceTuple in devices) { deviceTuple.Item2.Tick((uint)(lastTime - now), (ulong)now); deviceTuple.Item1.SetColors(); } lastTime = now; await Task.Delay(10000, stoppingToken); } }