using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace HDL_ON.Entity
{
public class Light
{
#region RGB
///
/// 获取rgb颜色
///
///
public int GetRGBcolor(string rgbString)
{
//var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
//if(!string.IsNullOrEmpty(rgbString))
//{
var color = rgbString.Split(",");
//}
if(color.Length!= 3)
{
color = new string[] {"255", "255", "255" };
}
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
int.TryParse(color[0], out redColor);
int.TryParse(color[1], out greenColor);
int.TryParse(color[2], out blueColor);
int recolor = redColor * 256 * 256 + greenColor * 256 + blueColor;
return recolor;
}
///
/// 获取rgb颜色数组
///
///
///
public byte[] GetRGBbytes(Function function)
{
var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
if (color.Length != 3)
{
color = new string[] { "100", "100", "100" };
}
byte redColor = 0;
byte greenColor = 0;
byte blueColor = 0;
byte.TryParse(color[0], out redColor);
byte.TryParse(color[1], out greenColor);
byte.TryParse(color[2], out blueColor);
return new byte[] { redColor, greenColor, blueColor };
}
///
/// 获取rgb 控制字符串
///
///
public string GetRGBcolorString(Function function)
{
var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
return color[0] + "," + color[1] + "," + color[2];
}
///
/// 获取rgb颜色
///
/// 0:red 1:green 2:blue
///
public int GetColor( int index,Function function)
{
int color = 0;
if (index <= 2)
{
try
{
int.TryParse(function.GetAttrState(FunctionAttributeKey.RGB).Split(",")[index], out color);
}
catch { }
}
return color;
}
///
/// 设置rgb颜色
///
public void SetRGBcolor(byte[] color,Function function)
{
function.SetAttrState(FunctionAttributeKey.RGB, color[0] + "," + color[1] + "," + color[2]);
}
///
/// 设置色温
///
///
///
public void SetCCT(byte[] cct,Function function)
{
function.SetAttrState(FunctionAttributeKey.CCT, cct[0] * 256 + cct[1]);
}
#endregion
}
}