Esempio n. 1
0
        /// <summary>
        /// Sets the percentage according to the defined steps in the percentage profile
        /// </summary>
        protected async Task ApplyPercentageEffect(float percentage)
        {
            var numberOfActiveSteps = _amountOfSteps; //Default the percentage is deemed 100

            if (!float.IsNaN(percentage))
            {
                Math.Max(0, (int)Math.Floor(percentage / _percentagePerStep));
            }

            var activeSteps   = _percentageProfile.Steps.Take(numberOfActiveSteps);
            var inactiveSteps = _percentageProfile.Steps.Except(activeSteps);

            foreach (var step in activeSteps)
            {
                foreach (var panel in step.PanelIds)
                {
                    _externalControlEndpoint.SetPanelColor(_orchestrator.PanelLayout.DeviceType, panel, _redColor.Color.R, _redColor.Color.G, _redColor.Color.B);
                }
            }

            foreach (var step in inactiveSteps)
            {
                foreach (var panel in step.PanelIds)
                {
                    _externalControlEndpoint.SetPanelColor(_orchestrator.PanelLayout.DeviceType, panel, _whiteColor.Color.R, _whiteColor.Color.G, _whiteColor.Color.B);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Applies the screen mirror effect to the lights.
        /// This method is called 10x per second by <see cref="ScreenMirrorEffect"/>
        /// </summary>
        public async Task ApplyEffect()
        {
            const int numberOfPanelsPerIteration = 5; //5x10 = 50hz. Note: 50hz seems to work good, higher values can make Canvas stop its external control
            const int minimumColorDifference     = 30;

            var panelsToUpdate = _panels.Take(numberOfPanelsPerIteration * 2).ToList(); //Take 2 times the number of panels, in case any color differences are not large enough

            var colors = ScreenGrabber.CalculateAverageColor(panelsToUpdate.Select(panel => panel.ScreenshotArea), 0);
            var numberOfPanelsChanged = 0;

            for (var i = 0; i < panelsToUpdate.Count; i++)
            {
                //Only update the color of a panel that has a large enough color difference
                if (ColorDistance(panelsToUpdate[i].CurrentColor, colors[i]) > minimumColorDifference)
                {
                    numberOfPanelsChanged++;
                    panelsToUpdate[i].CurrentColor = colors[i];
                    _externalControlEndpoint.SetPanelColor(_deviceType, panelsToUpdate[i].PanelId, colors[i].R, colors[i].G, colors[i].B);

                    _panels.Remove(panelsToUpdate[i]); //Remove the current panel and place it at the back of the list
                    _panels.Add(panelsToUpdate[i]);
                }

                if (numberOfPanelsChanged >= numberOfPanelsPerIteration)
                {
                    break;
                }
            }
        }