1 #pragma once
2 
3 namespace Json
4 {
5 	class Value;
6 };
7 
8 #define pTypeColorSwitch		0xF1
9 #define sTypeColor_RGB_W		0x01 // RGB + white, either RGB or white can be lit
10 #define sTypeColor_RGB			0x02 // RGB
11 #define sTypeColor_White		0x03 // Monochrome white
12 #define sTypeColor_RGB_CW_WW	0x04 // RGB + cold white + warm white, either RGB or white can be lit
13 #define sTypeColor_LivCol		0x05
14 #define sTypeColor_RGB_W_Z		0x06 // Like RGBW, but allows combining RGB and white
15 #define sTypeColor_RGB_CW_WW_Z	0x07 // Like RGBWW, but allows combining RGB and white
16 #define sTypeColor_CW_WW		0x08 // Cold white + Warm white
17 
18 enum ColorMode {
19 	ColorModeNone = 0, // Illegal
20 	ColorModeWhite,    // White. Valid fields: none
21 	ColorModeTemp,     // White with color temperature. Valid fields: t
22 	ColorModeRGB,      // Color. Valid fields: r, g, b.
23 	                   // Note: The color will be normalized to full brightness in this mode before sent to HW
24 	                   // due to limitations in multiple HW types. Normalization is done automatically by Domoticz MQTT
25 	                   // and WebServer command handlers, and the brightness is adjusted accordingly.
26 	ColorModeCustom,   // Custom (color + white). Valid fields: r, g, b, cw, ww, depending on device capabilities
27 	ColorModeLast = ColorModeCustom,
28 };
29 
30 struct _tColor {
31 	ColorMode mode;
32 	//uint8_t level; // Range:0..255, Master brightness (potential for future use)
33 	uint8_t t;     // Range:0..255, Color temperature (warm / cold ratio, 0 is coldest, 255 is warmest)
34 	uint8_t r;     // Range:0..255, Red level
35 	uint8_t g;     // Range:0..255, Green level
36 	uint8_t b;     // Range:0..255, Blue level
37 	uint8_t cw;    // Range:0..255, Cold white level
38 	uint8_t ww;    // Range:0..255, Warm white level (also used as level for monochrome white)
39 
40 	_tColor();
41 	explicit _tColor(const Json::Value &json);
42 	explicit _tColor(const std::string &sRaw); //explicit to avoid unintentional conversion of string to _tColor
43 	explicit _tColor(const uint8_t ir, const uint8_t ig, const uint8_t ib, const uint8_t icw, const uint8_t iww, ColorMode imode);
44 	explicit _tColor(uint8_t x, ColorMode imode);
45 	std::string getrgbwwhex() const;
46 	void fromJSON(const Json::Value &root);
47 	void fromString(const std::string &s);
48 	std::string toJSONString() const;
49 	Json::Value toJSONValue() const;
50 	std::string toString() const;
51 };
52 
53 const _tColor NoColor = _tColor();
54 
55 struct _tColorSwitch {
56 	uint8_t len;
57 	uint8_t type;
58 	uint8_t subtype;
59 	uint32_t id;
60 	uint8_t dunit; //0=All, 1=Group1,2=Group2,3=Group3,4=Group4, 5=IboxLed
61 	uint8_t command;
62 	uint32_t value;  // Value of command
63 	_tColor color;   // Color
64 
65 	template <class Archive>
serialize_tColorSwitch66 	void serialize(Archive & ar)
67 	{
68 		ar & cereal::make_nvp("len", len);
69 		ar & cereal::make_nvp("type", type);
70 		ar & cereal::make_nvp("subtype", subtype);
71 		ar & cereal::make_nvp("id", id);
72 		ar & cereal::make_nvp("dunit", dunit);
73 		ar & cereal::make_nvp("command", command);
74 		ar & cereal::make_nvp("value", value);
75 		ar & cereal::make_nvp("color", color);
76 	}
77 
_tColorSwitch_tColorSwitch78 	_tColorSwitch()
79 	{
80 		id = 1;
81 		dunit = 1;
82 		len=sizeof(_tColorSwitch)-1;
83 		type=pTypeColorSwitch;
84 		subtype=sTypeColor_RGB_W;
85 		command=0;
86 		value=0;
87 		color=NoColor;
88 	}
89 };
90 
91 #define Color_LedOff 0
92 #define Color_LedOn 1
93 #define Color_LedNight 2
94 #define Color_LedFull 3
95 #define Color_BrightnessUp 4
96 #define Color_BrightnessDown 5
97 #define Color_ColorTempUp 6
98 #define Color_ColorTempDown 7
99 #define Color_RGBDiscoNext 8
100 #define Color_RGBDiscoPrevious 9
101 #define Color_SetColor 10
102 #define Color_DiscoSpeedSlower 11
103 #define Color_DiscoSpeedFaster 12
104 #define Color_DiscoMode 13
105 #define Color_SetColorToWhite 14
106 #define Color_SetBrightnessLevel 15
107 #define Color_SetBrightUp 16
108 #define Color_SetBrightDown 17
109 #define Color_WarmWhiteIncrease 18
110 #define Color_CoolWhiteIncrease 19
111 #define Color_NightMode 20
112 #define Color_FullBrightness 21
113 #define Color_DiscoSpeedFasterLong 22 //exclude RGB
114 //#define Color_SetHEXColor 23
115 #define Color_DiscoMode_1 24
116 #define Color_DiscoMode_2 25
117 #define Color_DiscoMode_3 26
118 #define Color_DiscoMode_4 27
119 #define Color_DiscoMode_5 28
120 #define Color_DiscoMode_6 29
121 #define Color_DiscoMode_7 30
122 #define Color_DiscoMode_8 31
123 #define Color_DiscoMode_9 32
124 //#define Color_SetKelvinLevel 33
125 #define Color_DiscoSpeedMinimal 34
126 #define Color_DiscoSpeedMaximal 35
127