Ejemplo n.º 1
0
        private void Send()
        {
            if (_isStopped)
            {
                _isStopped = false;
            }

            var acceptedColor = default(AcceptedColor?);

            if (_red || _green || _blue)
            {
                if (_red && _green && _blue)
                {
                    acceptedColor = AcceptedColor.White;
                }
                else if (_red && _green && !_blue)
                {
                    acceptedColor = AcceptedColor.Yellow;
                }
                else if (_red && !_green && _blue)
                {
                    acceptedColor = AcceptedColor.Magenta;
                }
                else if (!_red && _green && _blue)
                {
                    acceptedColor = AcceptedColor.LightBlue;
                }
                else if (_red)
                {
                    acceptedColor = AcceptedColor.Red;
                }
                else if (_green)
                {
                    acceptedColor = AcceptedColor.Green;
                }
                else if (_blue)
                {
                    acceptedColor = AcceptedColor.Blue;
                }

                _communicationService.ChangeColorAsync(acceptedColor.Value);
            }
            else
            {
                _communicationService.TurnOffLightsAsync();
            }
        }
Ejemplo n.º 2
0
        private void EvaluateColorExpressions(Screenshot screenshot)
        {
            var highestHealthLevel = _userProcess.Expression
                                     .OrderBy(p => p.Priority)
                                     .First()
                                     .Status;

            _userProcess.Expression
            .OrderBy(p => p.Priority)
            .ToList()
            .ForEach(e =>
            {
                var pixel = screenshot.Bitmap.GetPixel(e.PixelIndex, 0);

                var expectedLab = ColorHelper.CreateLabFromRgb(e.TargetColor.R, e.TargetColor.G, e.TargetColor.B);
                var currentLab  = ColorHelper.CreateLabFromRgb(pixel.R, pixel.G, pixel.B);

                var diference = CompareLabColors(expectedLab, currentLab);

                if (diference > -e.Tolerance && diference < e.Tolerance)
                {
                    if (e.Strategy == EvaluationStrategy.KeepLast)
                    {
                        highestHealthLevel = _lastHealthLevel;
                    }
                    else
                    {
                        highestHealthLevel = e.Status;
                    }
                }
                #region Debug
                //screenshot.Bitmap.MarkPixel(e.PixelIndex, 0, e.Status);
                #endregion
            });
            _lastHealthLevel = highestHealthLevel;

            _userLoggingService.LogLine($"Health: {highestHealthLevel}");
            _communicationService.ChangeColorAsync(highestHealthLevel);
        }