Exemplo n.º 1
0
        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.");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsusUpdateQueue"/> class.
 /// </summary>
 /// <param name="updateTrigger">The update trigger used by this queue.</param>
 public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, OpenRGBClient client, int ledcount)
     : base(updateTrigger)
 {
     this._deviceid = deviceid;
     this._openRGB  = client;
     this._ledcount = ledcount;
 }
Exemplo n.º 3
0
        public void SetMode()
        {
            Stopwatch sw = Stopwatch.StartNew();

            using var client = new OpenRGBClient();
            var devices = client.GetAllControllerData();

            client.SetMode(0, 0);
            //for testing purposes
            for (int i = 0; i < devices.Length; i++)
            {
                for (int j = 0; j < devices[i].Modes.Length; j++)
                {
                    var mode = devices[i].Modes[j];
                    if (mode.HasFlag(ModeFlags.HasModeSpecificColor) && mode.HasFlag(ModeFlags.HasSpeed))
                    {
                        var len = (int)mode.ColorMax;
                        client.SetMode(i, j, speed: mode.SpeedMax, colors: Enumerable.Range(0, len).Select(_ => new Color(0, 255, 0)).ToArray());
                        break;
                    }
                }
            }

            Output.WriteLine($"Time elapsed: {(double)sw.ElapsedTicks / Stopwatch.Frequency * 1000} ms.");
        }
Exemplo n.º 4
0
        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.");
        }
Exemplo n.º 5
0
        public void Configure(DriverDetails driverDetails)
        {
            client = new OpenRGBClient(name: "RGB Sync Studio", autoconnect: true, timeout: 1000);

            var deviceCount = client.GetControllerCount();
            var devices     = client.GetAllControllerData();

            for (int devId = 0; devId < devices.Length; devId++)
            {
                ORGBControlDevice slsDevice = new ORGBControlDevice();
                slsDevice.id           = devId;
                slsDevice.Driver       = this;
                slsDevice.Name         = devices[devId].Name;
                slsDevice.DeviceType   = DeviceTypeConverter.GetType(devices[devId].Type);
                slsDevice.Has2DSupport = false;
                slsDevice.ProductImage = (Bitmap)Image.FromStream(orgbImage);

                List <ControlDevice.LedUnit> deviceLeds = new List <ControlDevice.LedUnit>();

                int i = 0;
                foreach (Led orgbLed in devices[devId].Leds)
                {
                    ControlDevice.LedUnit slsLed = new ControlDevice.LedUnit();
                    slsLed.LEDName = orgbLed.Name;
                    deviceLeds.Add(slsLed);
                }

                slsDevice.LEDs = deviceLeds.ToArray();

                DeviceAdded?.Invoke(slsDevice, new Events.DeviceChangeEventArgs(slsDevice));
            }
        }
        public void LoadRandomProfile()
        {
            OpenRGBClient client   = new OpenRGBClient(name: "OpenRGB.NET Test: LoadRandomProfile");
            var           profiles = client.GetProfiles();
            var           loadMe   = profiles[new Random().Next(0, profiles.Length)];

            client.LoadProfile(loadMe);
        }
Exemplo n.º 7
0
        public void UseAfterDispose()
        {
            Stopwatch sw     = Stopwatch.StartNew();
            var       client = new OpenRGBClient();

            client.Dispose();

            Assert.Throws <ObjectDisposedException>(() => client.GetControllerCount());
            Output.WriteLine($"Time elapsed: {(double)sw.ElapsedTicks / Stopwatch.Frequency * 1000} ms.");
        }
 public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, OpenRGBClient client, OpenRGBDevice device)
     : base(updateTrigger)
 {
     _deviceid = deviceid;
     _openRGB  = client;
     _device   = device;
     _colors   = Enumerable.Range(0, _device.Colors.Length)
                 .Select(_ => new OpenRGBColor())
                 .ToArray();
 }
Exemplo n.º 9
0
        public void TestProtocolVersionTwo()
        {
            using OpenRGBClient versionOne = new OpenRGBClient(protocolVersion: 1);
            Assert.Throws <NotSupportedException>(() => versionOne.GetProfiles());

            using OpenRGBClient versionTwo = new OpenRGBClient(protocolVersion: 2);
            var exception = Record.Exception(() => versionTwo.GetProfiles());

            Assert.Null(exception);
        }
Exemplo n.º 10
0
        public void ClientConnectToServer()
        {
            Stopwatch     sw     = Stopwatch.StartNew();
            OpenRGBClient client = new OpenRGBClient(name: "OpenRGB.NET Test: ClientConnectToServer");

            client.Connect();
            client.Dispose();
            sw.Stop();
            Output.WriteLine($"Time elapsed: {(double)sw.ElapsedTicks / Stopwatch.Frequency * 1000} ms.");
        }
Exemplo n.º 11
0
        public void TestProtocolVersionOne()
        {
            using OpenRGBClient versionZero = new OpenRGBClient(protocolVersion: 0);
            var devicesZero = versionZero.GetAllControllerData();

            Assert.All(devicesZero, d => Assert.Null(d.Vendor));

            using OpenRGBClient versionOne = new OpenRGBClient(protocolVersion: 1);
            var devicesOne = versionOne.GetAllControllerData();

            Assert.All(devicesOne, d => Assert.NotNull(d.Vendor));
        }
Exemplo n.º 12
0
 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));
         }
     }
 }
Exemplo n.º 13
0
        public void LoadRandomProfile()
        {
            using OpenRGBClient client = new OpenRGBClient(name: "OpenRGB.NET Test: LoadRandomProfile");
            var profiles = client.GetProfiles();

            if (profiles.Length == 0)
            {
                client.SaveProfile("TestProfile");
                profiles = client.GetProfiles();
            }
            var loadMe = profiles[new Random().Next(0, profiles.Length)];

            client.LoadProfile(loadMe);
        }
Exemplo n.º 14
0
        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.");
        }
Exemplo n.º 15
0
 protected override void InitializeSDK()
 {
     foreach (OpenRGBServerDefinition?deviceDefinition in DeviceDefinitions)
     {
         try
         {
             OpenRGBClient?openRgb = new OpenRGBClient(ip: deviceDefinition.Ip, port: deviceDefinition.Port, name: deviceDefinition.ClientName, autoconnect: true);
             _clients.Add(openRgb);
         }
         catch (Exception e)
         {
             Throw(e);
         }
     }
 }
        /// <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);
        }
Exemplo n.º 17
0
 protected override void InitializeSDK()
 {
     foreach (OpenRGBServerDefinition?deviceDefinition in DeviceDefinitions)
     {
         try
         {
             OpenRGBClient?openRgb = new OpenRGBClient(ip: deviceDefinition.Ip, port: deviceDefinition.Port, name: deviceDefinition.ClientName, autoconnect: true);
             _clients.Add(openRgb);
             deviceDefinition.Connected = true;
         }
         catch (Exception e)
         {
             deviceDefinition.Connected = false;
             deviceDefinition.LastError = e.Message;
         }
     }
 }
Exemplo n.º 18
0
        public override bool Initialize()
        {
            if (IsInitialized)
            {
                return(true);
            }

            try
            {
                var ip               = Global.Configuration.VarRegistry.GetVariable <string>($"{DeviceName}_ip");
                var port             = Global.Configuration.VarRegistry.GetVariable <int>($"{DeviceName}_port");
                var usePeriphLogo    = Global.Configuration.VarRegistry.GetVariable <bool>($"{DeviceName}_use_periph_logo");
                var ignoreDirectMode = Global.Configuration.VarRegistry.GetVariable <bool>($"{DeviceName}_ignore_direct");

                _openRgb = new OpenRGBClient(name: "Aurora", ip: ip, port: port);
                _openRgb.Connect();

                var devices = _openRgb.GetAllControllerData();
                _devices = new List <HelperOpenRGBDevice>();

                for (int i = 0; i < devices.Length; i++)
                {
                    if (devices[i].Modes.Any(m => m.Name == "Direct") || ignoreDirectMode)
                    {
                        var helper = new HelperOpenRGBDevice(i, devices[i]);
                        helper.ProcessMappings(usePeriphLogo);
                        _devices.Add(helper);
                    }
                }
            }
            catch (Exception e)
            {
                LogError("error in OpenRGB device: " + e);
                IsInitialized = false;
                return(false);
            }

            IsInitialized = true;
            return(IsInitialized);
        }
Exemplo n.º 19
0
        public override void Shutdown()
        {
            if (!IsInitialized)
            {
                return;
            }

            foreach (var d in _devices)
            {
                try
                {
                    _openRgb.UpdateLeds(d.Index, d.OrgbDevice.Colors);
                }
                catch
                {
                    //we tried.
                }
            }

            _openRgb?.Dispose();
            _openRgb      = null;
            IsInitialized = false;
        }
Exemplo n.º 20
0
        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);
            }
        }