Пример #1
0
        public override IDictionary <PortIdentifier, List <LedColor> > GenerateColors(List <PortIdentifier> ports, ICacheProvider cache)
        {
            var current = Environment.TickCount;
            var diff    = current - _ticks;

            if ((_state && diff > Config.OnTime) || (!_state && diff > Config.OffTime))
            {
                _ticks = current;
                _state = !_state;
            }

            if (Config.ColorGenerationMethod == ColorGenerationMethod.PerPort)
            {
                return(EffectUtils.GenerateColorsPerPort(ports, cache,
                                                         (port, ledCount) => (_state ? Config.OnColor : Config.OffColor).Get(ledCount).ToList()
                                                         ));
            }
            else if (Config.ColorGenerationMethod == ColorGenerationMethod.SpanPorts)
            {
                var totalLedCount = ports.Select(p => cache.GetDeviceConfig(p).LedCount).Sum();
                var colors        = (_state ? Config.OnColor : Config.OffColor).Get(totalLedCount).ToList();
                return(EffectUtils.SplitColorsPerPort(colors, ports, cache));
            }

            return(null);
        }
Пример #2
0
        public override IDictionary <PortIdentifier, List <LedColor> > GenerateColors(List <PortIdentifier> ports, ICacheProvider cache)
        {
            _fill += Config.FillStep;
            if (_fill >= 1)
            {
                _fill       = 0;
                _lastHue    = _currentHue;
                _currentHue = ((_currentHue + Config.HueStep) % 360 + 360) % 360;
            }

            var lastColor    = LedColor.FromHsv(_lastHue, Config.Saturation, Config.Brightness);
            var currentColor = LedColor.FromHsv(_currentHue, Config.Saturation, Config.Brightness);

            if (Config.ColorGenerationMethod == ColorGenerationMethod.PerPort)
            {
                return(EffectUtils.GenerateColorsPerPort(ports, cache, (port, ledCount) => GenerateColors(ledCount, currentColor, lastColor)));
            }
            else if (Config.ColorGenerationMethod == ColorGenerationMethod.SpanPorts)
            {
                var totalLedCount = ports.Select(p => cache.GetDeviceConfig(p).LedCount).Sum();
                var colors        = GenerateColors(totalLedCount, currentColor, lastColor);
                return(EffectUtils.SplitColorsPerPort(colors, ports, cache));
            }

            return(null);
        }
Пример #3
0
        public override IDictionary <PortIdentifier, List <LedColor> > GenerateColors(List <PortIdentifier> ports, ICacheProvider cache)
        {
            if (Config.ColorGenerationMethod == ColorGenerationMethod.PerPort)
            {
                return(EffectUtils.GenerateColorsPerPort(ports, cache, (_, ledCount) => GenerateColors(ledCount, cache)));
            }
            else if (Config.ColorGenerationMethod == ColorGenerationMethod.SpanPorts)
            {
                var totalLedCount = ports.Select(p => cache.GetDeviceConfig(p).LedCount).Sum();
                return(EffectUtils.SplitColorsPerPort(GenerateColors(totalLedCount, cache), ports, cache));
            }

            return(null);
        }
Пример #4
0
        public override IDictionary <PortIdentifier, List <LedColor> > GenerateColors(List <PortIdentifier> ports, ICacheProvider cache)
        {
            if (_tick++ >= Config.TickInterval)
            {
                _tick = 0;
                _rotation++;
            }

            if (Config.ColorGenerationMethod == ColorGenerationMethod.PerPort)
            {
                return(EffectUtils.GenerateColorsPerPort(ports, cache,
                                                         (port, ledCount) => Config.Color.Get(ledCount).RotateRight(_rotation % ledCount).ToList()
                                                         ));
            }
            else if (Config.ColorGenerationMethod == ColorGenerationMethod.SpanPorts)
            {
                var totalLedCount = ports.Select(p => cache.GetDeviceConfig(p).LedCount).Sum();
                var colors        = Config.Color.Get(totalLedCount).RotateRight(_rotation % totalLedCount).ToList();
                return(EffectUtils.SplitColorsPerPort(colors, ports, cache));
            }

            return(null);
        }
Пример #5
0
        public IDictionary <PortIdentifier, List <LedColor> > GenerateColors(ColorGenerationMethod generationMethod,
                                                                             List <PortIdentifier> ports, ICacheProvider cache, float[] fftBuffer)
        {
            if (generationMethod == ColorGenerationMethod.PerPort)
            {
                var result = new Dictionary <PortIdentifier, List <LedColor> >();

                List <LedColor>          colors = null;
                List <SpectrumPointData> points = null;
                foreach (var port in ports)
                {
                    var ledCount = cache.GetDeviceConfig(port).LedCount;

                    if (UpdateFrequencyMappingIfNecessary(ledCount) || points == null)
                    {
                        points = CalculateSpectrumPoints(1.0, fftBuffer);
                        colors = GenerateColors(points);
                    }

                    result.Add(port, colors.ToList());
                }

                return(result);
            }
            else if (generationMethod == ColorGenerationMethod.SpanPorts)
            {
                var totalLedCount = ports.Select(p => cache.GetDeviceConfig(p).LedCount).Sum();

                UpdateFrequencyMappingIfNecessary(totalLedCount);
                var points = CalculateSpectrumPoints(1.0, fftBuffer);
                var colors = GenerateColors(points);
                return(EffectUtils.SplitColorsPerPort(colors, ports, cache));
            }

            return(null);
        }
Пример #6
0
        public override IDictionary <PortIdentifier, List <LedColor> > GenerateColors(List <PortIdentifier> ports, ICacheProvider cache)
        {
            _t += Config.BrightnessStep * _direction;
            if (_t < 0 || _t > 1)
            {
                _direction = -_direction;
            }

            if (Config.ColorGenerationMethod == ColorGenerationMethod.PerPort)
            {
                return(EffectUtils.GenerateColorsPerPort(ports, cache,
                                                         (port, ledCount) => Config.Color.Get(ledCount).Select(c => LedColor.ChangeValue(c, c.GetValue() * _t)).ToList()
                                                         ));
            }

            if (Config.ColorGenerationMethod == ColorGenerationMethod.SpanPorts)
            {
                var totalLedCount = ports.Sum(p => cache.GetDeviceConfig(p).LedCount);
                var colors        = Config.Color.Get(totalLedCount).Select(c => LedColor.ChangeValue(c, c.GetValue() * _t)).ToList();
                return(EffectUtils.SplitColorsPerPort(colors, ports, cache));
            }

            return(null);
        }