Beispiel #1
0
		public static State DefaultState()
		{
			var state = new State();
			state.Alert = Alert.None;
			state.Brightness = 254;
			state.Hex = "FFB672";
			state.ColorMode = "hs";
			state.ColorTemperature = 369;
			state.Effect = Effect.None;
			state.Hue = 14922;
			state.On = true;
			state.Saturation = 144;

			return state;
		}
    /// <summary>
    /// Returns hexvalue from Light State
    /// </summary>
    /// <param name="state"></param>
    /// <returns></returns>
    public static string HexFromState(State state)
    {
      if (state == null)
        throw new ArgumentNullException("state");
      if (state.On == false || state.Brightness <= 5) //Off or low brightness
        return "000000";
      if(state.ColorCoordinates != null && state.ColorCoordinates.Length == 2) //Based on XY value
        return HexFromXy(state.ColorCoordinates[0], state.ColorCoordinates[1]);

      return "FFFFFF"; //White
    }
		/// <summary>
		/// Returns hexvalue from Light State
		/// </summary>
		/// <param name="state"></param>
		/// <returns></returns>
		public static RGBColor RgbFromState(State state, string model)
		{
			if (state == null)
				throw new ArgumentNullException("state");
			if (state.On == false || state.Brightness <= 5) //Off or low brightness
				return new RGBColor(0,0,0);
			if (state.ColorCoordinates != null && state.ColorCoordinates.Length == 2) //Based on XY value
			{
				var color = XYToRgb(new CIE1931Point(state.ColorCoordinates[0], state.ColorCoordinates[1]), model);
				return color;
			}

			return new RGBColor(1, 1, 1); ;
		}
		/// <summary>
		/// Returns hexvalue from Light State
		/// </summary>
		/// <param name="state"></param>
		/// <returns></returns>
		public static string HexFromState(State state, string model)
		{
			var rgb = RgbFromState(state, model);

			return rgb.ToHex();
		}
		/// <summary>
		/// Returns hexvalue from Light State
		/// </summary>
		/// <param name="state"></param>
		/// <returns></returns>
		public static string HexFromState(State state, string model)
		{
			if (state == null)
				throw new ArgumentNullException("state");
			if (state.On == false || state.Brightness <= 5) //Off or low brightness
				return "000000";
			if (state.ColorCoordinates != null && state.ColorCoordinates.Length == 2) //Based on XY value
			{
				var color = ColorFromXY(new CGPoint(state.ColorCoordinates[0], state.ColorCoordinates[1]), model);
				return string.Format("{0}{1}{2}", color.R.ToString("X2"), color.G.ToString("X2"), color.B.ToString("X2"));
			}

			return "FFFFFF"; //White
		}
		/// <summary>
		/// Returns hexvalue from Light State
		/// </summary>
		/// <param name="state"></param>
		/// <returns></returns>
		public static string HexFromState(State state, string model)
		{
			if (state == null)
				throw new ArgumentNullException("state");
			if (state.On == false || state.Brightness <= 5) //Off or low brightness
				return "000000";
			if (state.ColorCoordinates != null && state.ColorCoordinates.Length == 2) //Based on XY value
			{
				var color = XYToRgb(new CIE1931Point(state.ColorCoordinates[0], state.ColorCoordinates[1]), model);
                return color.ToHex();
			}

			return "FFFFFF"; //White
		}
Beispiel #7
0
 /// <summary>
 /// Returns hexvalue from Light State
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 public static string HexFromState(State state)
 {
   if (state == null)
     throw new ArgumentNullException("state");
   if (state.On == false || state.Brightness <= 5)
     return "000000";
   return HexFromXy(state.ColorCoordinates[0], state.ColorCoordinates[1]);
 }