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.");
        }
        /// <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);
        }
Exemple #3
0
        public void Connect()
        {
            if (_client == null)
            {
                return;
            }

            if (_client.Connected)
            {
                return;
            }

            Log.Debug("Connecting OpenRGB client.");
            try {
                _client?.Connect();
            } catch (Exception) {
                Log.Warning("Could not connect to open RGB at " + Ip);
            }
        }
Exemple #4
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);
        }
        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);
            }
        }