From 452e8cef1c740d18ee398be6971d9952e41dbd4a Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期三, 12 四月 2023 16:11:50 +0800
Subject: [PATCH] 1
---
HDL_ON/Entity/Function/Light.cs | 94 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 1 deletions(-)
diff --git a/HDL_ON/Entity/Function/Light.cs b/HDL_ON/Entity/Function/Light.cs
index 021d510..9d03759 100644
--- a/HDL_ON/Entity/Function/Light.cs
+++ b/HDL_ON/Entity/Function/Light.cs
@@ -18,7 +18,7 @@
//{
var color = rgbString.Split(",");
//}
- if(color.Length!= 3)
+ if(color.Length < 3)
{
color = new string[] {"255", "255", "255" };
}
@@ -107,5 +107,97 @@
#endregion
+ #region RGBW
+ /// <summary>
+ /// 鑾峰彇rgbw棰滆壊
+ /// </summary>
+ /// <returns></returns>
+ public int GetRGBWcolor(string rgbwString)
+ {
+ var color = rgbwString.Split(",");
+ //}
+ if (color.Length != 4)
+ {
+ 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;
+ }
+ /// <summary>
+ /// 鑾峰彇rgb棰滆壊鏁扮粍
+ /// </summary>
+ /// <param name="function"></param>
+ /// <returns></returns>
+ public byte[] GetRGBWbytes(Function function)
+ {
+ var color = function.GetAttrState(FunctionAttributeKey.RGBW).Split(",");
+
+ if (color.Length != 4)
+ {
+ color = new string[] { "100", "100", "100","100" };
+ }
+ byte redColor = 0;
+ byte greenColor = 0;
+ byte blueColor = 0;
+ byte wColor = 0;
+
+ byte.TryParse(color[0], out redColor);
+ byte.TryParse(color[1], out greenColor);
+ byte.TryParse(color[2], out blueColor);
+ byte.TryParse(color[3], out wColor);
+
+ return new byte[] { redColor, greenColor, blueColor,wColor };
+ }
+
+ /// <summary>
+ /// 鑾峰彇rgbw 鎺у埗瀛楃涓�
+ /// </summary>
+ /// <returns></returns>
+ public string GetRGBWcolorString(Function function)
+ {
+ var color = function.GetAttrState(FunctionAttributeKey.RGBW).Split(",");
+ return color[0] + "," + color[1] + "," + color[2] + "," + color[3];
+ }
+
+ /// <summary>
+ /// 鑾峰彇rgbW棰滆壊
+ /// </summary>
+ /// <param name="index">0:red 1:green 2:blue</param>
+ /// <returns></returns>
+ public int GetRGBWColor(int index, Function function)
+ {
+ int color = 0;
+ if (index <= 2)
+ {
+ try
+ {
+ int.TryParse(function.GetAttrState(FunctionAttributeKey.RGBW).Split(",")[index], out color);
+ }
+ catch { }
+ }
+ return color;
+ }
+
+ /// <summary>
+ /// 璁剧疆rgbw棰滆壊
+ /// </summary>
+ public void SetRGBWcolor(byte[] color, Function function)
+ {
+
+ function.SetAttrState(FunctionAttributeKey.RGBW, color[0] + "," + color[1] + "," + color[2] + "," + color[3]);
+ }
+
+
+ #endregion
+
}
}
--
Gitblit v1.8.0