Commit 8c3ccddffca4d5aadaf4bdbbb5cd8a7ec82a27b1

Authored by Nodeduino
Committed by Moritz Wirger
1 parent ba007030

Add new constant and normal getter functions for some light attributes like colo…

…r hue saturation, color xy, brightness, color temperature. Also add new functions for checking whether a light has brightness control, temperature control or color control.
hueplusplus/SimpleBrightnessStrategy.cpp
... ... @@ -96,3 +96,8 @@ unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const
96 96 light.refreshState();
97 97 return light.state["state"]["bri"].asUInt();
98 98 }
  99 +
  100 +unsigned int SimpleBrightnessStrategy::getBrightness(const HueLight& light) const
  101 +{
  102 + return light.state["state"]["bri"].asUInt();
  103 +}
... ...
hueplusplus/SimpleColorHueStrategy.cpp
... ... @@ -492,11 +492,21 @@ std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLi
492 492 return std::pair<uint16_t, uint8_t>(static_cast<uint16_t>(light.state["state"]["hue"].asUInt()), static_cast<uint8_t>(light.state["state"]["sat"].asUInt()));
493 493 }
494 494  
  495 +std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(const HueLight & light) const
  496 +{
  497 + return std::pair<uint16_t, uint8_t>(static_cast<uint16_t>(light.state["state"]["hue"].asUInt()), static_cast<uint8_t>(light.state["state"]["sat"].asUInt()));
  498 +}
  499 +
495 500 std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight & light) const
496 501 {
497 502 light.refreshState();
498 503 return std::pair<float, float>(light.state["state"]["xy"][0].asFloat(), light.state["state"]["xy"][1].asFloat());
499 504 }
  505 +
  506 +std::pair<float, float> SimpleColorHueStrategy::getColorXY(const HueLight & light) const
  507 +{
  508 + return std::pair<float, float>(light.state["state"]["xy"][0].asFloat(), light.state["state"]["xy"][1].asFloat());
  509 +}
500 510 /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2)
501 511 {
502 512 float A = (-y1 * x2 + y0*(-x1 + x2) + x0*(y1 - y2) + x1 * y1);
... ...
hueplusplus/SimpleColorTemperatureStrategy.cpp
... ... @@ -121,3 +121,8 @@ unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight&amp; light
121 121 light.refreshState();
122 122 return light.state["state"]["ct"].asUInt();
123 123 }
  124 +
  125 +unsigned int SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const
  126 +{
  127 + return light.state["state"]["ct"].asUInt();
  128 +}
... ...
hueplusplus/include/BrightnessStrategy.h
... ... @@ -36,9 +36,16 @@ public:
36 36 virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0;
37 37 //! \brief Virtual function that returns the current brightnessof the light
38 38 //!
  39 + //! Should update the lights state by calling refreshState()
39 40 //! \param light A reference of the light
40 41 //! \return Unsigned int representing the brightness
41 42 virtual unsigned int getBrightness(HueLight& light) const = 0;
  43 + //! \brief Virtual function that returns the current brightness of the light
  44 + //!
  45 + //! \note This should not update the lights state
  46 + //! \param light A const reference of the light
  47 + //! \return Unsigned int representing the brightness
  48 + virtual unsigned int getBrightness(const HueLight& light) const = 0;
42 49 //! \brief Virtual dtor
43 50 virtual ~BrightnessStrategy() = default;
44 51 };
... ...
hueplusplus/include/ColorHueStrategy.h
... ... @@ -103,14 +103,28 @@ public:
103 103 virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0;
104 104 //! \brief Virtual function that returns the current color of the light as hue and saturation
105 105 //!
  106 + //! Should update the lights state by calling refreshState()
106 107 //! \param light A reference of the light
107 108 //! \return Pair containing the hue as first value and saturation as second value
108 109 virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const = 0;
  110 + //! \brief Virtual function that returns the current color of the light as hue and saturation
  111 + //!
  112 + //! \note This should not update the lights state
  113 + //! \param light A const reference of the light
  114 + //! \return Pair containing the hue as first value and saturation as second value
  115 + virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(const HueLight& light) const = 0;
109 116 //! \brief Virtual function that returns the current color of the light as xy
110 117 //!
  118 + //! Should update the lights state by calling refreshState()
111 119 //! \param light A reference of the light
112 120 //! \return Pair containing the x as first value and y as second value
113 121 virtual std::pair<float, float> getColorXY(HueLight& light) const = 0;
  122 + //! \brief Virtual function that returns the current color of the light as xy
  123 + //!
  124 + //! \note This should not update the lights state
  125 + //! \param light A const reference of the light
  126 + //! \return Pair containing the x as first value and y as second value
  127 + virtual std::pair<float, float> getColorXY(const HueLight& light) const = 0;
114 128 //! \brief Virtual dtor
115 129 virtual ~ColorHueStrategy() = default;
116 130 };
... ...
hueplusplus/include/ColorTemperatureStrategy.h
... ... @@ -43,10 +43,18 @@ public:
43 43 virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0;
44 44 //! \brief Virtual function that returns the current color temperature of the light
45 45 //!
  46 + //! Should update the lights state by calling refreshState()
46 47 //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm.
47 48 //! \param light A reference of the light
48 49 //! \return Unsigned int representing the color temperature in mired
49 50 virtual unsigned int getColorTemperature(HueLight& light) const = 0;
  51 + //! \brief Virtual function that returns the current color temperature of the light
  52 + //!
  53 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm.
  54 + //! \note This should not update the lights state
  55 + //! \param light A const reference of the light
  56 + //! \return Unsigned int representing the color temperature in mired
  57 + virtual unsigned int getColorTemperature(const HueLight& light) const = 0;
50 58 //! \brief Virtual dtor
51 59 virtual ~ColorTemperatureStrategy() = default;
52 60 };
... ...
hueplusplus/include/HueLight.h
... ... @@ -133,6 +133,30 @@ public:
133 133 //! \return ColorType containig the color type of the light
134 134 ColorType getColorType();
135 135  
  136 + //! \brief Function to check whether this light has brightness control
  137 + //!
  138 + //! \return Bool that is true when the light has specified abilities and false when not
  139 + bool hasBrightnessControl()
  140 + {
  141 + return brightnessStrategy != nullptr;
  142 + };
  143 +
  144 + //! \brief Function to check whether this light has color temperature control
  145 + //!
  146 + //! \return Bool that is true when the light has specified abilities and false when not
  147 + bool hasTemperatureControl()
  148 + {
  149 + return colorTemperatureStrategy != nullptr;
  150 + };
  151 +
  152 + //! \brief Function to check whether this light has full color control
  153 + //!
  154 + //! \return Bool that is true when the light has specified abilities and false when not
  155 + bool hasColorControl()
  156 + {
  157 + return colorHueStrategy != nullptr;
  158 + };
  159 +
136 160 //! \brief Function that converts Kelvin to Mired.
137 161 //!
138 162 //! \param kelvin Unsigned integer value in Kelvin
... ... @@ -147,7 +171,7 @@ public:
147 171  
148 172 //! \brief Function that sets the brightness of this light.
149 173 //!
150   - //! Notice the brightness will only be set if the light has a reference to a specific \ref BrightnessStrategy.
  174 + //! \note The brightness will only be set if the light has a reference to a specific \ref BrightnessStrategy.
151 175 //! The brightness can range from 0 = off to 254 = fully lit.
152 176 //! \param bri Unsigned int that specifies the brightness
153 177 //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
... ... @@ -161,9 +185,24 @@ public:
161 185 return false;
162 186 };
163 187  
  188 + //! \brief Const function that returns the brightness of this light.
  189 + //!
  190 + //! \note The brightness will only be returned if the light has a reference to a specific \ref BrightnessStrategy.
  191 + //! \note This will not refresh the light state
  192 + //! The brightness can range from 0 = off to 254 = fully lit.
  193 + //! \return Unsigned int that is 0 when function failed
  194 + unsigned int getBrightness() const
  195 + {
  196 + if (brightnessStrategy)
  197 + {
  198 + return brightnessStrategy->getBrightness(*this);
  199 + }
  200 + return 0;
  201 + };
  202 +
164 203 //! \brief Function that returns the brightness of this light.
165 204 //!
166   - //! Notice the brightness will only be returned if the light has a reference to a specific \ref BrightnessStrategy.
  205 + //! \note The brightness will only be returned if the light has a reference to a specific \ref BrightnessStrategy.
167 206 //! The brightness can range from 0 = off to 254 = fully lit.
168 207 //! \return Unsigned int that is 0 when function failed
169 208 unsigned int getBrightness()
... ... @@ -177,7 +216,7 @@ public:
177 216  
178 217 //! \brief Fucntion that sets the color temperature of this light in mired.
179 218 //!
180   - //! Notice the color temperature will only be set if the light has a reference to a specific \ref ColorTemperatureStrategy.
  219 + //! \note The color temperature will only be set if the light has a reference to a specific \ref ColorTemperatureStrategy.
181 220 //! The color temperature can range from 153 to 500.
182 221 //! \param mired Unsigned int that specifies the color temperature in Mired
183 222 //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
... ... @@ -191,9 +230,41 @@ public:
191 230 return false;
192 231 };
193 232  
  233 + //! \brief Const function that returns the current color temperature of the light
  234 + //!
  235 + //! \note The color temperature will only be returned when the light has a reference to a specific \ref ColorTemperatureStrategy.
  236 + //! \note This will not refresh the light state
  237 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm.
  238 + //! \param light A reference of the light
  239 + //! \return Unsigned int representing the color temperature in mired or 0 when failed
  240 + unsigned int getColorTemperature() const
  241 + {
  242 + if (colorTemperatureStrategy)
  243 + {
  244 + return colorTemperatureStrategy->getColorTemperature(*this);
  245 + }
  246 + return 0;
  247 + };
  248 +
  249 + //! \brief Function that returns the current color temperature of the light
  250 + //!
  251 + //! \note The color temperature will only be returned when the light has a reference to a specific \ref ColorTemperatureStrategy.
  252 + //! Updates the lights state by calling refreshState()
  253 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm.
  254 + //! \param light A reference of the light
  255 + //! \return Unsigned int representing the color temperature in mired or 0 when failed
  256 + unsigned int getColorTemperature()
  257 + {
  258 + if (colorTemperatureStrategy)
  259 + {
  260 + return colorTemperatureStrategy->getColorTemperature(*this);
  261 + }
  262 + return 0;
  263 + };
  264 +
194 265 //! \brief Function to set the color of this light with specified hue.
195 266 //!
196   - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
  267 + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
197 268 //! The hue can range from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue.
198 269 //! \param hue uint16_t that specifies the hue
199 270 //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
... ... @@ -209,7 +280,7 @@ public:
209 280  
210 281 //! \brief Function to set the color of this light with specified saturation.
211 282 //!
212   - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
  283 + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
213 284 //! The saturation can range from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated.
214 285 //! \param sat uint8_t that specifies the saturation
215 286 //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
... ... @@ -225,7 +296,7 @@ public:
225 296  
226 297 //! \brief Function to set the color of this light with specified hue and saturation.
227 298 //!
228   - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
  299 + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
229 300 //! \param hue uint16_t that specifies the hue
230 301 //! \param sat uint8_t that specifies the saturation
231 302 //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms.
... ... @@ -239,9 +310,39 @@ public:
239 310 return false;
240 311 };
241 312  
  313 + //! \brief Const function that returns the current color of the light as hue and saturation
  314 + //!
  315 + //! \note The color hue and saturation will only be returned when the light has a reference to a specific \ref ColorHueStrategy.
  316 + //! \note This will not refresh the light state
  317 + //! \param light A reference of the light
  318 + //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed
  319 + std::pair<uint16_t, uint8_t> getColorHueSaturation() const
  320 + {
  321 + if(colorHueStrategy)
  322 + {
  323 + return colorHueStrategy->getColorHueSaturation(*this);
  324 + }
  325 + return {};
  326 + };
  327 +
  328 + //! \brief Function that returns the current color of the light as hue and saturation
  329 + //!
  330 + //! \note The color hue and saturation will only be returned when the light has a reference to a specific \ref ColorHueStrategy.
  331 + //! Updates the lights state by calling refreshState()
  332 + //! \param light A const reference of the light
  333 + //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed
  334 + std::pair<uint16_t, uint8_t> getColorHueSaturation()
  335 + {
  336 + if(colorHueStrategy)
  337 + {
  338 + return colorHueStrategy->getColorHueSaturation(*this);
  339 + }
  340 + return {};
  341 + };
  342 +
242 343 //! \brief Function to set the color of this light in CIE with specified x y.
243 344 //!
244   - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
  345 + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
245 346 //! The values of x and y are ranging from 0 to 1.
246 347 //! \param x float that specifies the x coordinate in CIE
247 348 //! \param y float that specifies the y coordinate in CIE
... ... @@ -256,9 +357,39 @@ public:
256 357 return false;
257 358 };
258 359  
  360 + //! \brief Const function that returns the current color of the light as xy
  361 + //!
  362 + //! \note The color x and y will only be returned when the light has a reference to a specific \ref ColorHueStrategy.
  363 + //! \note This does not update the lights state
  364 + //! \param light A const reference of the light
  365 + //! \return Pair containing the x as first value and y as second value or an empty one when failed
  366 + std::pair<float, float> getColorXY() const
  367 + {
  368 + if(colorHueStrategy)
  369 + {
  370 + return colorHueStrategy->getColorXY(*this);
  371 + }
  372 + return {};
  373 + };
  374 +
  375 + //! \brief Function that returns the current color of the light as xy
  376 + //!
  377 + //! \note The color x and y will only be returned when the light has a reference to a specific \ref ColorHueStrategy.
  378 + //! Updates the lights state by calling refreshState()
  379 + //! \param light A reference of the light
  380 + //! \return Pair containing the x as first value and y as second value or an empty one when failed
  381 + std::pair<float, float> getColorXY()
  382 + {
  383 + if(colorHueStrategy)
  384 + {
  385 + return colorHueStrategy->getColorXY(*this);
  386 + }
  387 + return {};
  388 + };
  389 +
259 390 //! \brief Function to set the color of this light with red green and blue values.
260 391 //!
261   - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
  392 + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy.
262 393 //! The values of red, green and blue are ranging from 0 to 255.
263 394 //! \param r uint8_t that specifies the red color value
264 395 //! \param g uint8_t that specifies the green color value
... ... @@ -282,7 +413,7 @@ public:
282 413  
283 414 //! \brief Function that lets the light perform one breath cycle in specified color temperature.
284 415 //!
285   - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorTemperatureStrategy.
  416 + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorTemperatureStrategy.
286 417 //! \param mired Color temperature in mired
287 418 //! \return Bool that is true on success
288 419 bool alertTemperature(unsigned int mired)
... ... @@ -296,7 +427,7 @@ public:
296 427  
297 428 //! \brief Function that lets the light perform one breath cycle in specified color.
298 429 //!
299   - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy.
  430 + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy.
300 431 //! \param hue uint16_t that specifies the hue
301 432 //! \param sat uint8_t that specifies the saturation
302 433 //! \return Bool that is true on success
... ... @@ -311,7 +442,7 @@ public:
311 442  
312 443 //! \brief Function that lets the light perform one breath cycle in specified color.
313 444 //!
314   - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy.
  445 + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy.
315 446 //! The values of x and y are ranging from 0 to 1.
316 447 //! \param x float that specifies the x coordinate in CIE
317 448 //! \param y float that specifies the y coordinate in CIE
... ... @@ -327,7 +458,7 @@ public:
327 458  
328 459 //! \brief Function that lets the light perform one breath cycle in specified color.
329 460 //!
330   - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy.
  461 + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy.
331 462 //! The values of red, green and blue are ranging from 0 to 255.
332 463 //! \param r uint8_t that specifies the red color value
333 464 //! \param g uint8_t that specifies the green color value
... ...
hueplusplus/include/SimpleBrightnessStrategy.h
... ... @@ -33,11 +33,18 @@ public:
33 33 //! \param transition The time it takes to fade to the new brightness in multiples of 100ms, 4 = 400ms and should be seen as the default
34 34 //! \param light A reference of the light
35 35 bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const override;
36   - //! \brief Function that returns the current brightnessof the light
  36 + //! \brief Function that returns the current brightness of the light
37 37 //!
  38 + //! Updates the lights state by calling refreshState()
38 39 //! \param light A reference of the light
39 40 //! \return Unsigned int representing the brightness
40 41 unsigned int getBrightness(HueLight& light) const override;
  42 + //! \brief Function that returns the current brightness of the light
  43 + //!
  44 + //! \note This does not update the lights state
  45 + //! \param light A const reference of the light
  46 + //! \return Unsigned int representing the brightness
  47 + unsigned int getBrightness(const HueLight& light) const override;
41 48 };
42 49  
43 50 #endif
... ...
hueplusplus/include/SimpleColorHueStrategy.h
... ... @@ -104,14 +104,28 @@ public:
104 104 bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override;
105 105 //! \brief Function that returns the current color of the light as hue and saturation
106 106 //!
  107 + //! Updates the lights state by calling refreshState()
107 108 //! \param light A reference of the light
108 109 //! \return Pair containing the hue as first value and saturation as second value
109 110 std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const override;
  111 + //! \brief Function that returns the current color of the light as hue and saturation
  112 + //!
  113 + //! \note This does not update the lights state
  114 + //! \param light A const reference of the light
  115 + //! \return Pair containing the hue as first value and saturation as second value
  116 + std::pair<uint16_t, uint8_t> getColorHueSaturation(const HueLight& light) const override;
110 117 //! \brief Function that returns the current color of the light as xy
111 118 //!
  119 + //! Updates the lights state by calling refreshState()
112 120 //! \param light A reference of the light
113 121 //! \return Pair containing the x as first value and y as second value
114 122 std::pair<float, float> getColorXY(HueLight& light) const override;
  123 + //! \brief Function that returns the current color of the light as xy
  124 + //!
  125 + //! \note This does not update the lights state
  126 + //! \param light A const reference of the light
  127 + //! \return Pair containing the x as first value and y as second value
  128 + std::pair<float, float> getColorXY(const HueLight& light) const override;
115 129 };
116 130  
117 131 #endif
... ...
hueplusplus/include/SimpleColorTemperatureStrategy.h
... ... @@ -43,10 +43,18 @@ public:
43 43 bool alertTemperature(unsigned int mired, HueLight& light) const override;
44 44 //! \brief Function that returns the current color temperature of the light
45 45 //!
  46 + //! Updates the lights state by calling refreshState()
46 47 //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm.
47 48 //! \param light A reference of the light
48 49 //! \return Unsigned int representing the color temperature in mired
49 50 unsigned int getColorTemperature(HueLight& light) const override;
  51 + //! \brief Function that returns the current color temperature of the light
  52 + //!
  53 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm.
  54 + //! \note This does not update the lights state
  55 + //! \param light A const reference of the light
  56 + //! \return Unsigned int representing the color temperature in mired
  57 + unsigned int getColorTemperature(const HueLight& light) const override;
50 58 };
51 59  
52 60 #endif
... ...