Пример #1
0
        /// <summary>
        ///     Modifies the layer, adapting it to the provided <paramref name="devices" />
        /// </summary>
        /// <param name="devices">The devices to adapt the layer to</param>
        public void Adapt(List <ArtemisDevice> devices)
        {
            // Use adaption hints if provided
            if (AdaptionHints.Any())
            {
                foreach (IAdaptionHint adaptionHint in AdaptionHints)
                {
                    adaptionHint.Apply(Layer, devices);
                }
            }
            // If there are no hints, try to find matching LEDs anyway
            else
            {
                List <ArtemisLed> availableLeds = devices.SelectMany(d => d.Leds).ToList();
                List <ArtemisLed> usedLeds      = new();

                foreach (LedEntity ledEntity in Layer.LayerEntity.Leds)
                {
                    // TODO: If this is a keyboard LED and the layouts don't match, convert it before looking for it on the devices

                    LedId      ledId = Enum.Parse <LedId>(ledEntity.LedName);
                    ArtemisLed?led   = availableLeds.FirstOrDefault(l => l.RgbLed.Id == ledId);

                    if (led != null)
                    {
                        availableLeds.Remove(led);
                        usedLeds.Add(led);
                    }
                }

                Layer.AddLeds(usedLeds);
            }
        }
Пример #2
0
        private Led FlickAndUpdate(LedId id)
        {
            var led = _ledContext.Flick(id);

            _hardwareContext.Hal.Update(led);
            return(led);
        }
        private void InitializeLayout()
        {
            LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);

            int       y            = 0;
            Size      ledSize      = new Size(19);
            int       zoneLedIndex = 0;
            const int ledSpacing   = 20;

            foreach (global::OpenRGB.NET.Models.Zone?zone in DeviceInfo.OpenRGBDevice.Zones)
            {
                if (zone.Type == ZoneType.Matrix)
                {
                    for (int row = 0; row < zone.MatrixMap.Height; row++)
                    {
                        for (int column = 0; column < zone.MatrixMap.Width; column++)
                        {
                            uint index = zone.MatrixMap.Matrix[row, column];

                            //will be max value if the position does not have an associated key
                            if (index == uint.MaxValue)
                            {
                                continue;
                            }

                            LedId ledId = StandardKeyNames.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[zoneLedIndex + index].Name, out LedId l)
                                ? l
                                : initial++;

                            //HACK: doing this because some different Led Names are mapped to the same LedId
                            //for example, "Enter" and "ISO Enter".
                            //this way, at least they'll be controllable as CustomX
                            while (AddLed(ledId, new Point(ledSpacing * column, y + (ledSpacing * row)), ledSize, zoneLedIndex + (int)index) == null)
                            {
                                ledId = initial++;
                            }
                        }
                    }
                    y += (int)(zone.MatrixMap.Height * ledSpacing);
                }
                else
                {
                    for (int i = 0; i < zone.LedCount; i++)
                    {
                        LedId ledId = initial++;

                        while (AddLed(ledId, new Point(ledSpacing * i, y), ledSize, zoneLedIndex + i) == null)
                        {
                            ledId = initial++;
                        }
                    }
                }

                //we'll just set each zone in its own row for now,
                //with each led for that zone being horizontally distributed
                y            += ledSpacing;
                zoneLedIndex += (int)zone.LedCount;
            }
        }
Пример #4
0
        private void InitializeLayout()
        {
            LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);

            int       y            = 0;
            Size      ledSize      = new Size(19);
            int       zoneLedIndex = 0;
            const int ledSpacing   = 20;

            foreach (global::OpenRGB.NET.Models.Zone?zone in DeviceInfo.OpenRGBDevice.Zones)
            {
                if (zone.Type == ZoneType.Matrix)
                {
                    for (int row = 0; row < zone.MatrixMap.Height; row++)
                    {
                        for (int column = 0; column < zone.MatrixMap.Width; column++)
                        {
                            uint index = zone.MatrixMap.Matrix[row, column];

                            //will be max value if the position does not have an associated key
                            if (index == uint.MaxValue)
                            {
                                continue;
                            }

                            LedId ledId = StandardKeyNames.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[zoneLedIndex + index].Name, out LedId l)
                                ? l
                                : initial++;

                            if (!_indexMapping.ContainsKey(ledId))
                            {
                                _indexMapping.Add(ledId, zoneLedIndex + (int)index);
                                AddLed(ledId, new Point(ledSpacing * column, y + (ledSpacing * row)), ledSize);
                            }
                        }
                    }
                    y += (int)(zone.MatrixMap.Height * ledSpacing);
                }
                else
                {
                    for (int i = 0; i < zone.LedCount; i++)
                    {
                        LedId ledId = initial++;

                        if (!_indexMapping.ContainsKey(ledId))
                        {
                            _indexMapping.Add(ledId, zoneLedIndex + i);
                            AddLed(ledId, new Point(i * ledSpacing, y), ledSize);
                        }
                    }
                }

                //we'll just set each zone in its own row for now,
                //with each led for that zone being horizontally distributed
                y            += ledSpacing;
                zoneLedIndex += (int)zone.LedCount;
            }
        }
Пример #5
0
        /// <inheritdoc />
        protected override object CreateLedCustomData(LedId ledId)
        {
            if (DeviceInfo.Device.Type == (uint)AsusDeviceType.NB_KB_4ZONE_RGB)
            {
                return(ledId - LedId.Keyboard_Custom1);
            }

            return(AsusKeyboardLedMapping.MAPPING[ledId]);
        }
        protected override object?GetLedCustomData(LedId ledId)
        {
            if (!_indexMapping.TryGetValue(ledId, out int index))
            {
                return(null);
            }

            return(index);
        }
Пример #7
0
        public static void Set(LedId id, byte r, byte g, byte b)
        {
            if (_rules == null)
            {
                return;
            }
            _rules[id] = new Color(r, g, b);

            hasChanged = true;
        }
Пример #8
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId)
 {
     if (string.Equals(DeviceInfo.Model, "GLAIVE RGB", StringComparison.OrdinalIgnoreCase))
     {
         return(MouseIdMapping.GLAIVE.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid);
     }
     else
     {
         return(MouseIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid);
     }
 }
Пример #9
0
 public Pin GetPin(LedId id)
 {
     if (_pins.ContainsKey(id))
     {
         return(_pins[id]);
     }
     else
     {
         throw new ArgumentException(
                   $"The LedId '{id}' is unknown. Make sure the id is registered in the hardware configuration");
     }
 }
Пример #10
0
        /// <inheritdoc />
        protected override void InitializeLayout()
        {
            LedId referenceId = (DeviceInfo.DeviceType == RGBDeviceType.LedStripe ? LedId.LedStripe1 : (DeviceInfo.DeviceType == RGBDeviceType.Fan ? LedId.Fan1 : LedId.Custom1));

            for (int i = 0; i < DeviceInfo.LedCount; i++)
            {
                LedId ledId = referenceId + i;
                _idMapping.Add(ledId, DeviceInfo.ReferenceCorsairLed + i);
                InitializeLed(ledId, new Rectangle(i * 10, 0, 10, 10));
            }

            string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();

            ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Customs\{model}.xml"), null);
        }
        private void InitializeLayout()
        {
            Size      ledSize    = new Size(19);
            const int ledSpacing = 20;
            LedId     initial    = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed;

            if (_zone.Type == ZoneType.Matrix)
            {
                for (int row = 0; row < _zone.MatrixMap.Height; row++)
                {
                    for (int column = 0; column < _zone.MatrixMap.Width; column++)
                    {
                        uint index = _zone.MatrixMap.Matrix[row, column];

                        //will be max value if the position does not have an associated key
                        if (index == uint.MaxValue)
                        {
                            continue;
                        }

                        LedId ledId = StandardKeyNames.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[_initialLed + index].Name, out LedId l)
                            ? l
                            : initial++;

                        if (!_indexMapping.ContainsKey(ledId))
                        {
                            _indexMapping.Add(ledId, _initialLed + (int)index);
                            AddLed(ledId, new Point(ledSpacing * column, ledSpacing * row), ledSize);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < _zone.LedCount; i++)
                {
                    LedId ledId = initial++;

                    if (!_indexMapping.ContainsKey(ledId))
                    {
                        _indexMapping.Add(ledId, _initialLed + i);
                        AddLed(ledId, new Point(ledSpacing * i, 0), ledSize);
                    }
                }
            }
        }
        private void InitializeLayout()
        {
            LedId initial = LedId.Mouse1;

            int       y          = 0;
            Size      ledSize    = new Size(3);
            const int ledSpacing = 20;

            for (int i = 0; i < 3; i++)
            {
                LedId ledId = initial++;
                while (AddLed(ledId, new Point(ledSpacing * i, y), new Size(20, 20), i) == null)
                {
                    ledId = initial++;
                }
            }
        }
Пример #13
0
        /// <inheritdoc />
        public override void SyncBack()
        {
            lock (_syncbackCache)
            {
                foreach (KeyValuePair <LedId, Color> cacheEntry in _syncbackCache)
                {
                    LedId ledId = cacheEntry.Key;
                    Color color = cacheEntry.Value;

                    if (!LedMapping.TryGetValue(ledId, out Led led))
                    {
                        led = InitializeLed(cacheEntry.Key, new Rectangle(0, 0, 10, 10)); //TODO DarthAffe 10.06.2018: Send layout with initial package
                    }
                    SetLedColorWithoutRequest(led, color);
                }

                _syncbackCache.Clear();
            }
        }
Пример #14
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId];
Пример #15
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusHeadsetRGBDevice" /> class.
 /// </summary>
 /// <param name="info">The specific information provided by Asus for the headset.</param>
 internal AsusUnspecifiedRGBDevice(AsusRGBDeviceInfo info, LedId baseLedId)
     : base(info)
 {
     this._baseLedId = baseLedId;
 }
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => HeadsetStandIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
Пример #17
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.GraphicsCard1;
Пример #18
0
        static void Main(string[] args)
        {
            RGBSurface surface = RGBSurface.Instance;
            Random     random  = new Random();

            surface.Exception += eventArgs => Console.WriteLine(eventArgs.Exception.Message);

            TimerUpdateTrigger updateTrigger = new TimerUpdateTrigger();

            updateTrigger.UpdateFrequency = 1.0 / 200.0;
            surface.RegisterUpdateTrigger(updateTrigger);
            updateTrigger.Start();

            bool throwExceptions = true;
            //RGBDeviceType loadType = (RGBDeviceType)(-1);
            RGBDeviceType loadType = RGBDeviceType.Keyboard;

            surface.LoadDevices(RGB.NET.Devices.CoolerMaster.CoolerMasterDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.Corsair.CorsairDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.DMX.DMXDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.Logitech.LogitechDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            //MSI DLL Broken -- surface.LoadDevices(RGB.NET.Devices.Msi.MsiDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.Novation.NovationDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.Razer.RazerDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.SteelSeries.SteelSeriesDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);
            surface.LoadDevices(RGB.NET.Devices.WS281X.WS281XDeviceProvider.Instance, loadType, throwExceptions: throwExceptions);

            surface.AlignDevices();

            //List Detected Devices of loadType
            Console.WriteLine("Device Count: " + surface.Devices.Count());

            int index = 0;

            foreach (IRGBDevice device in surface.Devices)
            {
                Console.WriteLine("[" + index + "] " + device.DeviceInfo.DeviceName + " || " + device.DeviceInfo.DeviceType + " || " + device.DeviceInfo.Manufacturer + " || " + device.DeviceInfo.Model);
                index++;
            }

            //Index of the chosen device
            int choice;

            if (surface.Devices.Count() < 1)
            {
                Console.WriteLine("No devices detected :(");
                Console.ReadKey();

                return;
            }
            else if (surface.Devices.Count() == 1)
            {
                choice = 0;
            }
            else
            {
                //Let the user choose which device the effect should be applied to by it's index in the enumeration
                Console.Write("Pick a device [Enter Number]:\n>");


                bool isOutOfRange = false;
                do
                {
                    //Is the entered string an int?
                    while (!int.TryParse(Console.ReadLine(), out choice))
                    {
                        Console.Write("Invalid Number.\n>");
                    }

                    //If it is an int, is it out of range?
                    isOutOfRange = choice <0 || choice> surface.Devices.Count() - 1;

                    if (isOutOfRange)
                    {
                        Console.Write("Invalid Number.\n>");
                    }
                } while (isOutOfRange);
            }


            //Determine device-specific led position minima and maxima (Rectangle Bounds)
            double minx = double.PositiveInfinity, miny = double.PositiveInfinity, maxx = double.NegativeInfinity, maxy = double.NegativeInfinity;
            int    count = 0;

            foreach (Led led in surface.Devices.ElementAt(choice))
            {
                if (led.ActualLocation.X < minx)
                {
                    minx = led.ActualLocation.X;
                }
                if (led.ActualLocation.Y < miny)
                {
                    miny = led.ActualLocation.Y;
                }
                if (led.ActualLocation.X > maxx)
                {
                    maxx = led.ActualLocation.X;
                }
                if (led.ActualLocation.Y > maxy)
                {
                    maxy = led.ActualLocation.Y;
                }
                count++;
            }

            Console.WriteLine($"Total LED count: {count}, X: [{minx}, {maxx}], Y: [{miny}, {maxy}]\nPress [ESC] to Close, any other key to continue the animation.");

            //Set background
            ListLedGroup groupBackground = new ListLedGroup(surface.Devices.ElementAt(choice));

            groupBackground.ZIndex = 0;
            groupBackground.Brush  = new SolidColorBrush(new Color(0, 0, 0));

            Dictionary <LedId, ListLedGroup> ledGroups = new Dictionary <LedId, ListLedGroup>();

            foreach (Led led in surface.Devices.ElementAt(choice))
            {
                if (!ledGroups.ContainsKey(led.Id))
                {
                    ListLedGroup group = new ListLedGroup(led);
                    group.ZIndex          = 1;
                    group.Brush           = new SolidColorBrush(new Color(0.0, 0.0, 0.0));
                    group.Brush.IsEnabled = false;

                    ledGroups.Add(led.Id, group);
                }
            }

            ConsoleKeyInfo key = Console.ReadKey();

            Console.Write("\r");
            while (key.Key != ConsoleKey.Escape)
            {
                LedId pressedKeyLedId = KeyConverter.GetLedByConsoleKey(key.Key);

                foreach (Led led in surface.Devices.ElementAt(choice))
                {
                    ledGroups[led.Id].Brush.IsEnabled = false;
                }

                if (pressedKeyLedId != LedId.Invalid)
                {
                    double hue = random.NextDouble() * 360;
                    foreach (Led led in surface.Devices.ElementAt(choice))
                    {
                        const double distScaleFac = 2.0;
                        double       deltaX       = led.ActualLocation.X - led.ActualSize.Width / 2 - surface.Devices.ElementAt(choice)[pressedKeyLedId].ActualLocation.X - surface.Devices.ElementAt(choice)[pressedKeyLedId].ActualSize.Width / 2;
                        double       deltaY       = led.ActualLocation.Y - led.ActualSize.Height / 2 - surface.Devices.ElementAt(choice)[pressedKeyLedId].ActualLocation.Y - surface.Devices.ElementAt(choice)[pressedKeyLedId].ActualSize.Height / 2;
                        double       dist         = distScaleFac * Math.Sqrt(deltaX * deltaX + deltaY * deltaY);

                        Color color = new Color();
                        color = color.SetHSV(hue, 1.0, 1.0);
                        color = color.SetA(Math.Max(255.0 - dist, 0) / 255.0);

                        ledGroups[led.Id].Brush           = new SolidColorBrush(color);
                        ledGroups[led.Id].Brush.IsEnabled = true;
                    }
                }

                key = Console.ReadKey();
                Console.Write("\r");
            }


            Console.ReadKey();
            return;
        }
Пример #19
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => (int)(ledId - _baseLedId);
Пример #20
0
        /// <summary>
        /// Blink one of the two leds on the Element.  
        /// Note: Element versions 3.0 and thereafter only have one user programmable LED.
        /// Therefore, led id '1' is the only valid LED on version 3.0 and greater boards.
        /// </summary>
        /// <param name="led">Led Id</param>
        /// <param name="rate">Blink Rate (0-127)</param>
        public void BlinkLED (LedId led, int rate)
        {
			string cmd = String.Format("blink {0}:{1}", (int)led, rate);
            commTask.EnqueueCommJob(Priority.High, cmd);
        }
Пример #21
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape;
Пример #22
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechZoneRGBDevice" /> class.
 /// </summary>
 /// <param name="info">The specific information provided by logitech for the zone-lightable device</param>
 internal LogitechZoneRGBDevice(LogitechRGBDeviceInfo info)
     : base(info)
 {
     _baseLedId = BASE_LED_MAPPING.TryGetValue(info.DeviceType, out LedId id) ? id : LedId.Custom1;
 }
Пример #23
0
 protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mainboard1;
Пример #24
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mousepad1;
 protected override object GetLedCustomData(LedId ledId) => (ledId, 0x00);
Пример #26
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => LaunchpadIdMapping.DEFAULT.TryGetValue(ledId, out NovationLedId novationLedId) ? novationLedId : NovationLedId.Invalid;
Пример #27
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => GetDeviceMapping().TryGetValue(ledId, out (byte mode, byte id, int _, int __)data) ? (data.mode, data.id) : ((byte)0x00, (byte)0x00);
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => (Channel, (int)ledId - (int)LedId.LedStripe1);
Пример #29
0
 protected override object CreateLedCustomData(LedId ledId) => _ledMapping[ledId];
Пример #30
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Headset1;
Пример #31
0
 /// <inheritdoc />
 protected override object CreateLedCustomData(LedId ledId) => CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex][ledId];