/// <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}"); } }
public static HSB GetHSB(this RGBColor rgb) { var hsb = new HSB { Hue = (int)rgb.GetHue(), Saturation = (int)rgb.GetSaturation(), Brightness = (int)rgb.GetBrightness() }; return(hsb); }
public static HSB GetHSB(this RGBColor rgb) { var hsb = new HSB ( (int)rgb.GetHue(), (int)rgb.GetSaturation(), (int)rgb.GetBrightness() ); return(hsb); }
private RGBColor ClampBrightness(string colorString, LightData lightData, int brightness) { var oColor = new RGBColor(colorString); // Clamp our brightness based on settings long bClamp = 255 * brightness / 100; if (lightData.OverrideBrightness) { var newB = lightData.Brightness; bClamp = 255 * newB / 100; } var hsb = new HSB((int)oColor.GetHue(), (int)oColor.GetSaturation(), (int)oColor.GetBrightness()); if (hsb.Brightness > bClamp) { hsb.Brightness = (int)bClamp; } oColor = hsb.GetRGB(); return(oColor); }