Esempio n. 1
0
        public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache)
        {
            var ledCount = cache.GetDeviceConfig(port).LedCount;

            if (ledCount == colors.Count)
            {
                return;
            }

            if (Config.LerpType == LerpType.Smooth)
            {
                var newColors = new List <LedColor>();
                var gradient  = new LedColorGradient(colors, ledCount - 1);

                for (var i = 0; i < ledCount; i++)
                {
                    newColors.Add(gradient.GetColor(i));
                }

                colors = newColors;
            }
            else if (Config.LerpType == LerpType.Nearest)
            {
                var newColors = new List <LedColor>();
                for (var i = 0; i < ledCount; i++)
                {
                    var idx = (int)Math.Round((i / (ledCount - 1d)) * (colors.Count - 1d));
                    newColors.Add(colors[idx]);
                }

                colors = newColors;
            }
        }
        public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache)
        {
            if (Config.Reverse != null)
            {
                Apply(ref colors);
            }
            else
            {
                var offset    = 0;
                var newColors = new List <LedColor>();
                var zones     = cache.GetDeviceConfig(port).Zones;
                for (int i = 0; i < zones.Length; i++)
                {
                    var zoneColors = colors.Skip(offset).Take(zones[i]);
                    if (i < Config.ZoneReverse?.Length && Config.ZoneReverse[i])
                    {
                        zoneColors = zoneColors.Reverse();
                    }

                    offset += zones[i];
                    newColors.AddRange(zoneColors);
                }

                if (newColors.Count < colors.Count)
                {
                    newColors.AddRange(colors.Skip(offset));
                }

                colors = newColors;
            }
        }
Esempio n. 3
0
        public override void Run(string part)
        {
            var input          = FileReader.ReadFile(2017, 12);
            var portIdentifier = new PortIdentifier(input);

            if (part == "A")
            {
                Console.WriteLine(portIdentifier.GetConnectionsToRoot().Count);
            }
            else
            {
                Console.WriteLine(portIdentifier.GetGroups());
            }
        }
        public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache)
        {
            if (Config.Rotation != null)
            {
                Apply(ref colors);
            }
            else
            {
                var offset    = 0;
                var newColors = new List <LedColor>();
                var zones     = cache.GetDeviceConfig(port).Zones;
                for (int i = 0; i < zones.Length; i++)
                {
                    var zoneColors = colors.Skip(offset).Take(zones[i]);

                    if (i < Config.ZoneRotation?.Length)
                    {
                        var rotate = Config.ZoneRotation[i];
                        if (rotate > 0)
                        {
                            zoneColors = zoneColors.RotateLeft(rotate);
                        }
                        else if (rotate < 0)
                        {
                            zoneColors = zoneColors.RotateRight(rotate);
                        }
                    }

                    offset += zones[i];
                    newColors.AddRange(zoneColors);
                }

                if (newColors.Count < colors.Count)
                {
                    newColors.AddRange(colors.Skip(offset));
                }

                colors = newColors;
            }
        }
        public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache)
        {
            var ledCount = cache.GetDeviceConfig(port).LedCount;

            if (ledCount <= colors.Count)
            {
                return;
            }

            if (Config.WrapRemainder)
            {
                var wrapCount   = (int)Math.Floor(colors.Count / (double)ledCount);
                var startOffset = (wrapCount - 1) * ledCount;
                var remainder   = colors.Count - wrapCount * ledCount;

                colors = colors.Skip(colors.Count - remainder)
                         .Concat(colors.Skip(startOffset + remainder).Take(ledCount - remainder))
                         .ToList();
            }
            else
            {
                colors.RemoveRange(ledCount, colors.Count - ledCount);
            }
        }
Esempio n. 6
0
 public PortConfig GetPortConfig(PortIdentifier port) => _portConfigCache.TryGetValue(port, out var config) ? config : null;
Esempio n. 7
0
 public void StorePortConfig(PortIdentifier port, PortConfig config) => _portConfigCache[port] = config;
Esempio n. 8
0
 public PortData GetPortData(PortIdentifier port) => _portDataCache.TryGetValue(port, out var data) ? data : null;
Esempio n. 9
0
 public void StorePortData(PortIdentifier port, PortData data) => _portDataCache[port] = data;
Esempio n. 10
0
 public IControllerProxy GetController(PortIdentifier port) =>
 Controllers?.FirstOrDefault(c => c.IsValidPort(port)) ?? null;
Esempio n. 11
0
 public DeviceConfig GetDeviceConfig(PortIdentifier port) => _provider.GetDeviceConfig(port);
Esempio n. 12
0
 public List <LedColor> GetPortColors(PortIdentifier port) => _portColorCache.TryGetValue(port, out var colors) ? colors : null;
Esempio n. 13
0
 public void StorePortData(PortIdentifier port, PortData data) => _collector.StorePortData(port, data);
Esempio n. 14
0
 public byte?GetPortSpeed(PortIdentifier port) => _portSpeedCache.TryGetValue(port, out var speed) ? speed : (byte?)null;
Esempio n. 15
0
 public void StorePortSpeed(PortIdentifier port, byte speed) => _portSpeedCache[port] = speed;
Esempio n. 16
0
 public void StoreDeviceConfig(PortIdentifier port, DeviceConfig data) => _collector.StoreDeviceConfig(port, data);
Esempio n. 17
0
 public void StorePortColors(PortIdentifier port, List <LedColor> colors) => _collector.StorePortColors(port, colors);
Esempio n. 18
0
 public void StorePortSpeed(PortIdentifier port, byte speed) => _collector.StorePortSpeed(port, speed);
Esempio n. 19
0
 public PortData GetPortData(PortIdentifier port) => _provider.GetPortData(port);
Esempio n. 20
0
 public override bool IsValidPort(PortIdentifier port) =>
 port.ControllerProductId == Device.ProductId &&
 port.ControllerVendorId == Device.VendorId &&
 port.Id >= 1 && port.Id <= Definition.PortCount;
Esempio n. 21
0
 public PortConfig GetPortConfig(PortIdentifier port) => _provider.GetPortConfig(port);
Esempio n. 22
0
 public byte?GetPortSpeed(PortIdentifier port) => _provider.GetPortSpeed(port);
Esempio n. 23
0
 public void StorePortConfig(PortIdentifier port, PortConfig config) => _collector.StorePortConfig(port, config);
Esempio n. 24
0
 public abstract void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache);
Esempio n. 25
0
 public void StorePortColors(PortIdentifier port, List <LedColor> colors) => _portColorCache[port] = colors;
Esempio n. 26
0
 public List <LedColor> GetPortColors(PortIdentifier port) => _provider.GetPortColors(port);
Esempio n. 27
0
 public override bool IsValidPort(PortIdentifier port) =>
 port.ControllerProductId == Device.ProductId &&
 port.ControllerVendorId == Device.VendorId &&
 port.Id == 0;
Esempio n. 28
0
 public DeviceConfig GetDeviceConfig(PortIdentifier port) => _deviceConfigCache.TryGetValue(port, out var data) ? data : null;
 public abstract bool IsValidPort(PortIdentifier port);
Esempio n. 30
0
 public void StoreDeviceConfig(PortIdentifier port, DeviceConfig data) => _deviceConfigCache[port] = data;