Esempio n. 1
0
        public LifxBulb(byte[] mac, IPhysicalLed led)
        {
            this.led = led;

            this.label = "Demo";

            this.Tags = new byte[LifxConst.BulbTagsLength];

            this.TagLabels = string.Empty;

            this.Address = BitHelper.ReadUInt64(mac, 0);

            this.colorHsbk = new LifxHsbkColor
            {
                Brightness = 1,
                Hue = 300,
                Saturation = 0,
                Kelvin = 2000
            };

            this.colorRgb = this.colorHsbk.ToRgb();

            this.Power = 65535;

            this.Location = "Home";
        }
Esempio n. 2
0
        public static LifxHsbkColor ToHsbk(LifxRgbColor color)
        {
            var result = new LifxHsbkColor();

            int max = Math.Max(color.Red, Math.Max(color.Green, color.Blue));
            int min = Math.Min(color.Red, Math.Min(color.Green, color.Blue));

            result.Brightness = max; // v

            var delta = max - min;

            if (max > 0.0)
            {
                result.Saturation = delta / max; // s
            }
            else
            {
                // r = g = b = 0                        // s = 0, v is undefresulted
                result.Saturation = 0;
                result.Hue = -1; // NAN;                            // its now undefresulted
                return result;
            }

            if (color.Red >= max) // > is bogus, just keeps compilor happy
            {
                result.Hue = (color.Green - color.Blue) / delta; // between yellow & magenta
            }
            else if (color.Green >= max)
            {
                result.Hue = (ushort)(2.0 + (color.Blue - color.Red) / delta); // between cyan & yellow
            }
            else
            {
                result.Hue = (ushort)(4.0 + (color.Red - color.Green) / delta); // between magenta & cyan
            }

            result.Hue *= 60.0; // degrees

            if (result.Hue < 0.0)
            {
                result.Hue += 360.0;
            }

            return result;
        }
Esempio n. 3
0
 public static LifxRgbColor ToRgb(LifxHsbkColor color)
 {
     return ToRgb(color.Hue, color.Saturation, color.Brightness);
 }
Esempio n. 4
0
 public LifxLightStateRequest(LifxPacket packet)
     : base(packet)
 {
     this.color = LifxHsbkColor.FromBytes(this.Packet.Payload, 1);
     this.Duration = BitHelper.ReadUInt16(this.Packet.Payload, 1 + LifxHsbkColor.Size);
 }
Esempio n. 5
0
        private static LifxRgbColor Fade(LifxHsbkColor from, LifxHsbkColor to, int step, int steps)
        {
            var hue = Fade(from.Hue, to.Hue, step, steps);
            var saturation = Fade(from.Saturation, to.Saturation, step, steps);
            var value = Fade(from.Brightness, to.Brightness, step, steps);

            return null;// ToRgbColor(hue, saturation, value);
        }
Esempio n. 6
0
        public void FadeTo(LifxHsbkColor toColor, TimeSpan delay)
        {
            this.fadingStep = 0;
            this.fadeFromHsv = this.colorHsv;
            this.fadeToHsv = toColor;

            this.StartFading(this.FadeDelay);
        }
Esempio n. 7
0
 public void FadeTo(LifxHsbkColor toColor)
 {
 }
Esempio n. 8
0
        private static LifxHsbkColor Fade(LifxHsbkColor from, LifxHsbkColor to, int step, int steps)
        {
            var hue = Fade(from.Hue, to.Hue, step, steps);
            var saturation = Fade(from.Saturation, to.Saturation, step, steps);
            var value = Fade(from.Brightness, to.Brightness, step, steps);

            return new LifxHsbkColor { Hue = hue, Saturation = saturation, Brightness = value, Kelvin = to.Kelvin };
        }