6565 }
6666
6767// Color capabilities bit flags (matching ZCL spec) - can be combined with bitwise OR
68- # define ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION (1 << 0 ) // Bit 0: Hue/saturation supported
69- # define ZIGBEE_COLOR_CAPABILITY_ENHANCED_HUE (1 << 1 ) // Bit 1: Enhanced hue supported
70- # define ZIGBEE_COLOR_CAPABILITY_COLOR_LOOP (1 << 2 ) // Bit 2: Color loop supported
71- # define ZIGBEE_COLOR_CAPABILITY_X_Y ( 1 << 3 ) // Bit 3: X/Y supported
72- # define ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP (1 << 4 ) // Bit 4: Color temperature supported
68+ static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION = (1 << 0 ); // Bit 0: Hue/saturation supported
69+ static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_ENHANCED_HUE = (1 << 1 ); // Bit 1: Enhanced hue supported
70+ static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_COLOR_LOOP = (1 << 2 ); // Bit 2: Color loop supported
71+ static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_X_Y = ( 1 << 3 ); // Bit 3: X/Y supported
72+ static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP = (1 << 4 ); // Bit 4: Color temperature supported
7373
7474// Color mode enum values (matching ZCL spec)
7575enum ZigbeeColorMode {
@@ -78,6 +78,14 @@ enum ZigbeeColorMode {
7878 ZIGBEE_COLOR_MODE_TEMPERATURE = 0x02 , // ColorTemperature
7979};
8080
81+ // Callback function type definitions for better readability and type safety
82+ // RGB callback: (state, red, green, blue, level)
83+ typedef void (*ZigbeeColorLightRgbCallback)(bool state, uint8_t red, uint8_t green, uint8_t blue, uint8_t level);
84+ // HSV callback: (state, hue, saturation, value) - value represents brightness (0-255)
85+ typedef void (*ZigbeeColorLightHsvCallback)(bool state, uint8_t hue, uint8_t saturation, uint8_t value);
86+ // Temperature callback: (state, level, color_temperature_in_mireds)
87+ typedef void (*ZigbeeColorLightTempCallback)(bool state, uint8_t level, uint16_t color_temperature);
88+
8189class ZigbeeColorDimmableLight : public ZigbeeEP {
8290public:
8391 ZigbeeColorDimmableLight (uint8_t endpoint);
@@ -87,16 +95,16 @@ class ZigbeeColorDimmableLight : public ZigbeeEP {
8795 bool setLightColorCapabilities (uint16_t capabilities);
8896
8997 [[deprecated(" Use onLightChangeRgb() instead. This will be removed in a future major version." )]]
90- void onLightChange (void (* callback)( bool , uint8_t , uint8_t , uint8_t , uint8_t ) ) {
91- _on_light_change = callback;
98+ void onLightChange (ZigbeeColorLightRgbCallback callback) {
99+ _on_light_change_rgb = callback;
92100 }
93- void onLightChangeRgb (void (* callback)( bool , uint8_t , uint8_t , uint8_t , uint8_t ) ) {
101+ void onLightChangeRgb (ZigbeeColorLightRgbCallback callback) {
94102 _on_light_change_rgb = callback;
95103 }
96- void onLightChangeHsv (void (* callback)( bool , uint8_t , uint8_t , uint8_t , uint8_t ) ) {
104+ void onLightChangeHsv (ZigbeeColorLightHsvCallback callback) {
97105 _on_light_change_hsv = callback;
98106 }
99- void onLightChangeTemp (void (* callback)( bool , uint8_t , uint16_t ) ) {
107+ void onLightChangeTemp (ZigbeeColorLightTempCallback callback) {
100108 _on_light_change_temp = callback;
101109 }
102110 void restoreLight () {
@@ -156,19 +164,17 @@ class ZigbeeColorDimmableLight : public ZigbeeEP {
156164 uint8_t getCurrentColorSaturation ();
157165 uint16_t getCurrentColorTemperature ();
158166
159- void lightChanged ();
160167 void lightChangedRgb ();
161168 void lightChangedHsv ();
162169 void lightChangedTemp ();
163170 void lightChangedByMode ();
164- // callback function to be called on light change (State, R, G, B, Level) - legacy
165- void (*_on_light_change)(bool , uint8_t , uint8_t , uint8_t , uint8_t );
171+
166172 // callback function to be called on light change for RGB (State, R, G, B, Level)
167- void (* _on_light_change_rgb)( bool , uint8_t , uint8_t , uint8_t , uint8_t ) ;
173+ ZigbeeColorLightRgbCallback _on_light_change_rgb;
168174 // callback function to be called on light change for HSV (State, H, S, V, Level)
169- void (* _on_light_change_hsv)( bool , uint8_t , uint8_t , uint8_t , uint8_t ) ;
175+ ZigbeeColorLightHsvCallback _on_light_change_hsv;
170176 // callback function to be called on light change for TEMP (State, Level, Temperature)
171- void (* _on_light_change_temp)( bool , uint8_t , uint16_t ) ;
177+ ZigbeeColorLightTempCallback _on_light_change_temp;
172178
173179 bool _current_state;
174180 uint8_t _current_level;
0 commit comments