Esempio n. 1
0
        public TestLight(ColorDimmer logicalDevice)
        {
            this.logicalDevice = logicalDevice;

            logicalDevice.ColorChanged += (sender, e) =>
            {
                var hsv = new HSV(e.NewColor);
                hsv.Value = hsv.Value * e.NewBrightness;

                this.control.Color = hsv.Color;
                this.control.Text = string.Format("{0:0%}", e.NewBrightness);
            };

            WireUpStrobe(logicalDevice as StrobeColorDimmer);
        }
Esempio n. 2
0
 public static void ColorToHSV(Color color, out double hue, out double saturation, out double value)
 {
     var hsv = new HSV(color);
     hue = hsv.Hue;
     saturation = hsv.Saturation;
     value = hsv.Value;
 }
Esempio n. 3
0
        public static Color ColorFromHSV(double hue, double saturation, double value)
        {
            var hsv = new HSV(hue, saturation, value);

            return(hsv.Color);
        }
Esempio n. 4
0
        public static Color ColorFromHSV(double hue, double saturation, double value)
        {
            var hsv = new HSV(hue, saturation, value);

            return hsv.Color;
        }
Esempio n. 5
0
        public TestPixel1D(Pixel1D logicalDevice)
        {
            Executor.Current.Register(this);

            this.logicalDevice = logicalDevice;
            this.numberOfPixels = logicalDevice.Pixels;

            logicalDevice.PixelChanged += (sender, e) =>
                {
                    var hsv = new HSV(e.NewColor);
                    hsv.Value = hsv.Value * e.NewBrightness;
                    Color c = hsv.Color;

                    lock (lockObject)
                    {
                        if (!this.changedPixels.Any())
                            this.firstChange.Restart();

                        this.pixelData[e.Channel] = c;

                        this.changedPixels.Add((byte)e.Channel);
                        receivedUpdates++;
                    }

                };

            logicalDevice.MultiPixelChanged += (sender, e) =>
                {
                    var newColors = new Color[e.NewValues.Length];
                    for(int i = 0; i < e.NewValues.Length; i++)
                    {
                        var hsv = new HSV(e.NewValues[i].Color);
                        hsv.Value = hsv.Value * e.NewValues[i].Brightness;
                        newColors[i] = hsv.Color;
                    }

                    lock (lockObject)
                    {
                        if (!this.changedPixels.Any())
                            this.firstChange.Restart();

                        int readOffset = 0;
                        for (int i = 0; i < newColors.Length; i++)
                        {
                            int dataOffset = e.StartChannel + i;

                            this.pixelData[dataOffset] = newColors[readOffset++];

                            this.changedPixels.Add((byte)(e.StartChannel + i));
                        }
                        receivedUpdates++;
                    }
                };

            this.changedPixels = new HashSet<byte>();
            this.cancelSource = new System.Threading.CancellationTokenSource();
            this.firstChange = new System.Diagnostics.Stopwatch();
            this.pixelData = new Color[this.numberOfPixels];

            this.senderTask = new Task(x =>
            {
                while (!this.cancelSource.IsCancellationRequested)
                {
                    lock (lockObject)
                    {
                        if (this.changedPixels.Any())
                        {
                            this.firstChange.Stop();
                            this.sentUpdates++;
                            //Console.WriteLine("Sending {0} changes to SIM. Oldest {1:N2}ms. Recv: {2}   Sent: {3}",
                            //    this.changedPixels.Count, this.firstChange.Elapsed.TotalMilliseconds,
                            //    receivedUpdates, sentUpdates);

                            if (this.changedPixels.Count <= 2)
                            {
                                foreach (var channel in this.changedPixels)
                                {
                                    control.SetPixel(channel, this.pixelData[channel]);
                                }
                            }
                            else
                            {
                                // Send everything
                                control.SetPixels(0, this.pixelData);
                            }
                            this.changedPixels.Clear();
                        }
                    }

                    System.Threading.Thread.Sleep(10);
                }
            }, this.cancelSource.Token, TaskCreationOptions.LongRunning);

            this.senderTask.Start();
        }