using System;
|
using System.Collections.Generic;
|
using Newtonsoft.Json.Linq;
|
|
namespace HDL_ON.Entity
|
{
|
public class Light
|
{
|
#region RGB
|
/// <summary>
|
/// 获取rgb颜色
|
/// </summary>
|
/// <returns></returns>
|
public int GetRGBcolor(Function function )
|
{
|
var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
|
|
if(color.Length!= 3)
|
{
|
color = new string[] {"100", "100", "100" };
|
}
|
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;
|
}
|
/// <summary>
|
/// 获取rgb 控制字符串
|
/// </summary>
|
/// <returns></returns>
|
public string GetRGBcolorString(Function function )
|
{
|
var color = function.GetAttrState(FunctionAttributeKey.RGB).Split(",");
|
return color[0] + "," + color[1] + "," + color[2];
|
}
|
|
/// <summary>
|
/// 获取rgb颜色
|
/// </summary>
|
/// <param name="index">0:red 1:green 2:blue</param>
|
/// <returns></returns>
|
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;
|
}
|
|
/// <summary>
|
/// 设置rgb颜色
|
/// </summary>
|
public void SetRGBcolor(byte[] color,Function function)
|
{
|
function.SetAttrState(FunctionAttributeKey.RGB, color[0] + "," + color[1] + "," + color[2]);
|
}
|
|
#endregion
|
|
}
|
}
|