예제 #1
0
        public void SetColor(List <System.Drawing.Color> inputs, double fadeTime = 0)
        {
            if (!Streaming)
            {
                return;
            }
            if (inputs == null || _client == null)
            {
                throw new ArgumentException("Invalid color inputs.");
            }
            //var capCount = _captureMode == 0 ? 12 : 28;
            //if (inputs.Count < capCount) throw new ArgumentOutOfRangeException($"Error, we have {inputs.Count} inputs, but should have {capCount}.");
            var input = inputs[_targetSector];

            if (Brightness < 100)
            {
                input = ColorTransformUtil.ClampBrightness(input, Brightness);
            }
            var nC = new Color {
                R = input.R, G = input.G, B = input.B
            };
            var fadeSpan = TimeSpan.FromSeconds(fadeTime);

            _client.SetColorAsync(B, nC, 7500, fadeSpan);
        }
예제 #2
0
        /// <summary>
        ///     Update lights in entertainment layer
        /// </summary>
        /// <param name="colors">An array of 12 colors corresponding to sector data</param>
        /// <param name="fadeTime">Optional: how long to fade to next state</param>
        public void SetColor(List <Color> colors, double fadeTime = 0)
        {
            if (!Streaming)
            {
                return;
            }
            if (colors == null)
            {
                LogUtil.Write("Error with color array!", "ERROR");
                return;
            }

            if (_entLayer != null)
            {
                var lightMappings = Bd.Lights;
                // Loop through lights in entertainment layer
                //LogUtil.Write(@"Sending to bridge...");
                foreach (var entLight in _entLayer)
                {
                    // Get data for our light from map
                    var lightData = lightMappings.SingleOrDefault(item =>
                                                                  item.Id == entLight.Id.ToString(CultureInfo.InvariantCulture));
                    // Return if not mapped
                    if (lightData == null)
                    {
                        continue;
                    }
                    // Otherwise, get the corresponding sector color
                    var tSector  = _captureMode == 0 ? lightData.TargetSector : lightData.TargetSectorV2;
                    var colorInt = tSector - 1;
                    var color    = colors[colorInt];
                    var mb       = lightData.OverrideBrightness ? lightData.Brightness : Brightness;
                    if (mb < 100)
                    {
                        color = ColorTransformUtil.ClampBrightness(color, mb);
                    }

                    var oColor = new RGBColor(color.R, color.G, color.B);

                    // If we're currently using a scene, animate it
                    if (Math.Abs(fadeTime) > 0.00001)
                    {
                        // Our start color is the last color we had}
                        entLight.SetState(CancellationToken.None, oColor, oColor.GetBrightness(),
                                          TimeSpan.FromSeconds(fadeTime));
                    }
                    else
                    {
                        // Otherwise, if we're streaming, just set the color
                        entLight.SetState(CancellationToken.None, oColor, oColor.GetBrightness());
                    }
                }
            }
            else
            {
                LogUtil.Write($@"Hue: Unable to fetch entertainment layer. {IpAddress}");
            }
        }
예제 #3
0
        public void SetColor(List <Color> colors, double fadeTime = 1)
        {
            int ft = (int)fadeTime;

            if (!Streaming)
            {
                LogUtil.Write("Streaming is  not active?");
                return;
            }

            var capCount = _captureMode == 0 ? 12 : 28;

            if (colors == null || colors.Count < capCount)
            {
                throw new ArgumentException("Invalid color list.");
            }

            var byteString = new List <byte>();

            if (_streamMode == 2)
            {
                byteString.AddRange(ByteUtils.PadInt(_layout.NumPanels));
            }
            else
            {
                byteString.Add(ByteUtils.IntByte(_layout.NumPanels));
            }
            foreach (var pd in _layout.PositionData)
            {
                var id       = pd.PanelId;
                var colorInt = _captureMode == 0 ?  pd.TargetSector - 1 : pd.TargetSectorV2 - 1;
                if (_streamMode == 2)
                {
                    byteString.AddRange(ByteUtils.PadInt(id));
                }
                else
                {
                    byteString.Add(ByteUtils.IntByte(id));
                }

                if (pd.TargetSector == -1)
                {
                    continue;
                }
                //LogUtil.Write("Sector for light " + id + " is " + pd.Sector);
                var color = colors[colorInt];
                if (Brightness < 100)
                {
                    color = ColorTransformUtil.ClampBrightness(color, Brightness);
                }

                // Add rgb values
                byteString.Add(ByteUtils.IntByte(color.R));
                byteString.Add(ByteUtils.IntByte(color.G));
                byteString.Add(ByteUtils.IntByte(color.B));
                // White value
                byteString.AddRange(ByteUtils.PadInt(0, 1));
                // Pad duration time
                byteString.AddRange(_streamMode == 2 ? ByteUtils.PadInt(ft) : ByteUtils.PadInt(ft, 1));
            }
            SendUdpUnicast(byteString.ToArray());
        }