using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace HDL_ON.Entity
{
public class Light
{
#region RGB
///
/// 获取rgb颜色
///
///
public int GetRGBcolor(Function function )
{
var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
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 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]);
}
#endregion
}
}