public override async Task Handle(CancellationToken cancellationToken)
        {
            var pixelTransition = new List <PixelSet>();
            var zeroPixelSet = new PixelSet();
            var pixelSet = new PixelSet();
            var random = new Random();
            int red, green, blue;

            do
            {
                red   = possiblePixelValues[random.Next(3)];
                green = possiblePixelValues[random.Next(3)];
                blue  = possiblePixelValues[random.Next(3)];
            } while ((red == 0 && green == 0 && blue == 0) || (red == 20 && green == 20 && blue == 20));

            for (var i = 0; i < Consts.PixelCount; i++)
            {
                zeroPixelSet.Pixels.Add(new Pixel(i, 0, 0, 0));
                pixelSet.Pixels.Add(new Pixel(i, red, green, blue));
            }
            pixelTransition.Add(pixelSet);
            pixelTransition.Add(zeroPixelSet);
            NeopixelCompiler.RunPixelTransition(5, pixelTransition);

            await CompleteJob(new { jobStatus = Statuses.Success.ToString() });
        }
        public override async Task Handle(CancellationToken cancellationToken)
        {
            var pixelTransition = new List <PixelSet>();
            var index           = Job.Payload.SelectToken("$.index")?.ToObject <int>();

            pixelTransition.Add(new PixelSet {
                Pixels = new List <Pixel> {
                    new Pixel(index ?? 0, 255, 0, 0)
                }
            });
            pixelTransition.Add(new PixelSet {
                Pixels = new List <Pixel> {
                    new Pixel(index ?? 0, 0, 255, 0)
                }
            });
            pixelTransition.Add(new PixelSet {
                Pixels = new List <Pixel> {
                    new Pixel(index ?? 0, 0, 0, 255)
                }
            });
            pixelTransition.Add(new PixelSet {
                Pixels = new List <Pixel> {
                    new Pixel(index ?? 0, 0, 0, 0)
                }
            });
            NeopixelCompiler.RunPixelTransition(0.5, pixelTransition);

            await CompleteJob(new { jobStatus = Statuses.Success.ToString() });
        }
        public override async Task Handle(CancellationToken cancellationToken)
        {
            const int TransitionSize   = 60;
            const int Transition1Break = 60;
            const int Transition2Break = 120;
            const int Transition3Break = 180;
            const int Transition4Break = 240;
            const int Transition5Break = 300;

            var pixelTransition = new List <PixelSet>();
            var zeroPixelSet    = new PixelSet();
            var pixelSet        = new PixelSet();
            var brightness      = 0.25;

            for (var pixelIndex = 0; pixelIndex < Consts.PixelCount; pixelIndex++)
            {
                zeroPixelSet.Pixels.Add(new Pixel(pixelIndex, 0, 0, 0));

                if (pixelIndex < Transition1Break)
                {
                    pixelSet.Pixels.Add(new Pixel(pixelIndex, 255, 0 + 127 * pixelIndex / TransitionSize, 0, brightness));
                }
                else if (pixelIndex < Transition2Break)
                {
                    var transitionRelativePixelIndex = pixelIndex - Transition1Break;
                    pixelSet.Pixels.Add(new Pixel(pixelIndex, 255, 127 + 128 * transitionRelativePixelIndex / TransitionSize, 0, brightness));
                }
                else if (pixelIndex < Transition3Break)
                {
                    var transitionRelativePixelIndex = pixelIndex - Transition2Break;
                    pixelSet.Pixels.Add(new Pixel(pixelIndex, 255 - 255 * transitionRelativePixelIndex / TransitionSize, 255, 0, brightness));
                }
                else if (pixelIndex < Transition4Break)
                {
                    var transitionRelativePixelIndex = pixelIndex - Transition3Break;
                    pixelSet.Pixels.Add(new Pixel(pixelIndex, 0, 255 - 255 * transitionRelativePixelIndex / TransitionSize, 0 + 255 * transitionRelativePixelIndex / TransitionSize, brightness));
                }
                else if (pixelIndex < Transition5Break)
                {
                    var transitionRelativePixelIndex = pixelIndex - Transition4Break;
                    pixelSet.Pixels.Add(new Pixel(pixelIndex, 0 + 143 * transitionRelativePixelIndex / TransitionSize, 0, 255, brightness));
                }
            }
            pixelTransition.Add(pixelSet);
            pixelTransition.Add(zeroPixelSet);
            NeopixelCompiler.RunPixelTransition(5, pixelTransition);

            await CompleteJob(new { jobStatus = Statuses.Success.ToString() });
        }
Beispiel #4
0
        public override async Task Handle(CancellationToken cancellationToken)
        {
            var length          = Job.Payload.SelectToken("$.length")?.ToObject <int>();
            var red             = Job.Payload.SelectToken("$.red")?.ToObject <int>();
            var green           = Job.Payload.SelectToken("$.green")?.ToObject <int>();
            var blue            = Job.Payload.SelectToken("$.blue")?.ToObject <int>();
            var pixelTransition = new List <PixelSet>();

            for (var leadPixelIndex = 0; leadPixelIndex < Consts.PixelCount + length; leadPixelIndex++)
            {
                var pixelSet = new PixelSet();
                pixelSet.Pixels.AddRange(GetPixels(leadPixelIndex, red ?? 0, green ?? 0, blue ?? 0, length ?? 5));
                pixelTransition.Add(pixelSet);
            }
            NeopixelCompiler.RunPixelTransition(0, pixelTransition);

            await CompleteJob(new { jobStatus = Statuses.Success.ToString() });
        }