Commit 8c3ccddffca4d5aadaf4bdbbb5cd8a7ec82a27b1
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.
Showing
10 changed files
with
222 additions
and
13 deletions
hueplusplus/SimpleBrightnessStrategy.cpp
| @@ -96,3 +96,8 @@ unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const | @@ -96,3 +96,8 @@ unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const | ||
| 96 | light.refreshState(); | 96 | light.refreshState(); |
| 97 | return light.state["state"]["bri"].asUInt(); | 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,11 +492,21 @@ std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLi | ||
| 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())); | 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 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight & light) const | 500 | std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight & light) const |
| 496 | { | 501 | { |
| 497 | light.refreshState(); | 502 | light.refreshState(); |
| 498 | return std::pair<float, float>(light.state["state"]["xy"][0].asFloat(), light.state["state"]["xy"][1].asFloat()); | 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 | /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2) | 510 | /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2) |
| 501 | { | 511 | { |
| 502 | float A = (-y1 * x2 + y0*(-x1 + x2) + x0*(y1 - y2) + x1 * y1); | 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& light | @@ -121,3 +121,8 @@ unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light | ||
| 121 | light.refreshState(); | 121 | light.refreshState(); |
| 122 | return light.state["state"]["ct"].asUInt(); | 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,9 +36,16 @@ public: | ||
| 36 | virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0; | 36 | virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0; |
| 37 | //! \brief Virtual function that returns the current brightnessof the light | 37 | //! \brief Virtual function that returns the current brightnessof the light |
| 38 | //! | 38 | //! |
| 39 | + //! Should update the lights state by calling refreshState() | ||
| 39 | //! \param light A reference of the light | 40 | //! \param light A reference of the light |
| 40 | //! \return Unsigned int representing the brightness | 41 | //! \return Unsigned int representing the brightness |
| 41 | virtual unsigned int getBrightness(HueLight& light) const = 0; | 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 | //! \brief Virtual dtor | 49 | //! \brief Virtual dtor |
| 43 | virtual ~BrightnessStrategy() = default; | 50 | virtual ~BrightnessStrategy() = default; |
| 44 | }; | 51 | }; |
hueplusplus/include/ColorHueStrategy.h
| @@ -103,14 +103,28 @@ public: | @@ -103,14 +103,28 @@ public: | ||
| 103 | virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0; | 103 | virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0; |
| 104 | //! \brief Virtual function that returns the current color of the light as hue and saturation | 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 | //! \param light A reference of the light | 107 | //! \param light A reference of the light |
| 107 | //! \return Pair containing the hue as first value and saturation as second value | 108 | //! \return Pair containing the hue as first value and saturation as second value |
| 108 | virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const = 0; | 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 | //! \brief Virtual function that returns the current color of the light as xy | 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 | //! \param light A reference of the light | 119 | //! \param light A reference of the light |
| 112 | //! \return Pair containing the x as first value and y as second value | 120 | //! \return Pair containing the x as first value and y as second value |
| 113 | virtual std::pair<float, float> getColorXY(HueLight& light) const = 0; | 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 | //! \brief Virtual dtor | 128 | //! \brief Virtual dtor |
| 115 | virtual ~ColorHueStrategy() = default; | 129 | virtual ~ColorHueStrategy() = default; |
| 116 | }; | 130 | }; |
hueplusplus/include/ColorTemperatureStrategy.h
| @@ -43,10 +43,18 @@ public: | @@ -43,10 +43,18 @@ public: | ||
| 43 | virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0; | 43 | virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0; |
| 44 | //! \brief Virtual function that returns the current color temperature of the light | 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 | //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | 47 | //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. |
| 47 | //! \param light A reference of the light | 48 | //! \param light A reference of the light |
| 48 | //! \return Unsigned int representing the color temperature in mired | 49 | //! \return Unsigned int representing the color temperature in mired |
| 49 | virtual unsigned int getColorTemperature(HueLight& light) const = 0; | 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 | //! \brief Virtual dtor | 58 | //! \brief Virtual dtor |
| 51 | virtual ~ColorTemperatureStrategy() = default; | 59 | virtual ~ColorTemperatureStrategy() = default; |
| 52 | }; | 60 | }; |
hueplusplus/include/HueLight.h
| @@ -133,6 +133,30 @@ public: | @@ -133,6 +133,30 @@ public: | ||
| 133 | //! \return ColorType containig the color type of the light | 133 | //! \return ColorType containig the color type of the light |
| 134 | ColorType getColorType(); | 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 | //! \brief Function that converts Kelvin to Mired. | 160 | //! \brief Function that converts Kelvin to Mired. |
| 137 | //! | 161 | //! |
| 138 | //! \param kelvin Unsigned integer value in Kelvin | 162 | //! \param kelvin Unsigned integer value in Kelvin |
| @@ -147,7 +171,7 @@ public: | @@ -147,7 +171,7 @@ public: | ||
| 147 | 171 | ||
| 148 | //! \brief Function that sets the brightness of this light. | 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 | //! The brightness can range from 0 = off to 254 = fully lit. | 175 | //! The brightness can range from 0 = off to 254 = fully lit. |
| 152 | //! \param bri Unsigned int that specifies the brightness | 176 | //! \param bri Unsigned int that specifies the brightness |
| 153 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms | 177 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms |
| @@ -161,9 +185,24 @@ public: | @@ -161,9 +185,24 @@ public: | ||
| 161 | return false; | 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 | //! \brief Function that returns the brightness of this light. | 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 | //! The brightness can range from 0 = off to 254 = fully lit. | 206 | //! The brightness can range from 0 = off to 254 = fully lit. |
| 168 | //! \return Unsigned int that is 0 when function failed | 207 | //! \return Unsigned int that is 0 when function failed |
| 169 | unsigned int getBrightness() | 208 | unsigned int getBrightness() |
| @@ -177,7 +216,7 @@ public: | @@ -177,7 +216,7 @@ public: | ||
| 177 | 216 | ||
| 178 | //! \brief Fucntion that sets the color temperature of this light in mired. | 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 | //! The color temperature can range from 153 to 500. | 220 | //! The color temperature can range from 153 to 500. |
| 182 | //! \param mired Unsigned int that specifies the color temperature in Mired | 221 | //! \param mired Unsigned int that specifies the color temperature in Mired |
| 183 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms | 222 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms |
| @@ -191,9 +230,41 @@ public: | @@ -191,9 +230,41 @@ public: | ||
| 191 | return false; | 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 | //! \brief Function to set the color of this light with specified hue. | 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 | //! The hue can range from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | 268 | //! The hue can range from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. |
| 198 | //! \param hue uint16_t that specifies the hue | 269 | //! \param hue uint16_t that specifies the hue |
| 199 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms | 270 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms |
| @@ -209,7 +280,7 @@ public: | @@ -209,7 +280,7 @@ public: | ||
| 209 | 280 | ||
| 210 | //! \brief Function to set the color of this light with specified saturation. | 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 | //! The saturation can range from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated. | 284 | //! The saturation can range from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated. |
| 214 | //! \param sat uint8_t that specifies the saturation | 285 | //! \param sat uint8_t that specifies the saturation |
| 215 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms | 286 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms |
| @@ -225,7 +296,7 @@ public: | @@ -225,7 +296,7 @@ public: | ||
| 225 | 296 | ||
| 226 | //! \brief Function to set the color of this light with specified hue and saturation. | 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 | //! \param hue uint16_t that specifies the hue | 300 | //! \param hue uint16_t that specifies the hue |
| 230 | //! \param sat uint8_t that specifies the saturation | 301 | //! \param sat uint8_t that specifies the saturation |
| 231 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms. | 302 | //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms. |
| @@ -239,9 +310,39 @@ public: | @@ -239,9 +310,39 @@ public: | ||
| 239 | return false; | 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 | //! \brief Function to set the color of this light in CIE with specified x y. | 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 | //! The values of x and y are ranging from 0 to 1. | 346 | //! The values of x and y are ranging from 0 to 1. |
| 246 | //! \param x float that specifies the x coordinate in CIE | 347 | //! \param x float that specifies the x coordinate in CIE |
| 247 | //! \param y float that specifies the y coordinate in CIE | 348 | //! \param y float that specifies the y coordinate in CIE |
| @@ -256,9 +357,39 @@ public: | @@ -256,9 +357,39 @@ public: | ||
| 256 | return false; | 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 | //! \brief Function to set the color of this light with red green and blue values. | 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 | //! The values of red, green and blue are ranging from 0 to 255. | 393 | //! The values of red, green and blue are ranging from 0 to 255. |
| 263 | //! \param r uint8_t that specifies the red color value | 394 | //! \param r uint8_t that specifies the red color value |
| 264 | //! \param g uint8_t that specifies the green color value | 395 | //! \param g uint8_t that specifies the green color value |
| @@ -282,7 +413,7 @@ public: | @@ -282,7 +413,7 @@ public: | ||
| 282 | 413 | ||
| 283 | //! \brief Function that lets the light perform one breath cycle in specified color temperature. | 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 | //! \param mired Color temperature in mired | 417 | //! \param mired Color temperature in mired |
| 287 | //! \return Bool that is true on success | 418 | //! \return Bool that is true on success |
| 288 | bool alertTemperature(unsigned int mired) | 419 | bool alertTemperature(unsigned int mired) |
| @@ -296,7 +427,7 @@ public: | @@ -296,7 +427,7 @@ public: | ||
| 296 | 427 | ||
| 297 | //! \brief Function that lets the light perform one breath cycle in specified color. | 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 | //! \param hue uint16_t that specifies the hue | 431 | //! \param hue uint16_t that specifies the hue |
| 301 | //! \param sat uint8_t that specifies the saturation | 432 | //! \param sat uint8_t that specifies the saturation |
| 302 | //! \return Bool that is true on success | 433 | //! \return Bool that is true on success |
| @@ -311,7 +442,7 @@ public: | @@ -311,7 +442,7 @@ public: | ||
| 311 | 442 | ||
| 312 | //! \brief Function that lets the light perform one breath cycle in specified color. | 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 | //! The values of x and y are ranging from 0 to 1. | 446 | //! The values of x and y are ranging from 0 to 1. |
| 316 | //! \param x float that specifies the x coordinate in CIE | 447 | //! \param x float that specifies the x coordinate in CIE |
| 317 | //! \param y float that specifies the y coordinate in CIE | 448 | //! \param y float that specifies the y coordinate in CIE |
| @@ -327,7 +458,7 @@ public: | @@ -327,7 +458,7 @@ public: | ||
| 327 | 458 | ||
| 328 | //! \brief Function that lets the light perform one breath cycle in specified color. | 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 | //! The values of red, green and blue are ranging from 0 to 255. | 462 | //! The values of red, green and blue are ranging from 0 to 255. |
| 332 | //! \param r uint8_t that specifies the red color value | 463 | //! \param r uint8_t that specifies the red color value |
| 333 | //! \param g uint8_t that specifies the green color value | 464 | //! \param g uint8_t that specifies the green color value |
hueplusplus/include/SimpleBrightnessStrategy.h
| @@ -33,11 +33,18 @@ public: | @@ -33,11 +33,18 @@ public: | ||
| 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 | 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 | //! \param light A reference of the light | 34 | //! \param light A reference of the light |
| 35 | bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const override; | 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 | //! \param light A reference of the light | 39 | //! \param light A reference of the light |
| 39 | //! \return Unsigned int representing the brightness | 40 | //! \return Unsigned int representing the brightness |
| 40 | unsigned int getBrightness(HueLight& light) const override; | 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 | #endif | 50 | #endif |
hueplusplus/include/SimpleColorHueStrategy.h
| @@ -104,14 +104,28 @@ public: | @@ -104,14 +104,28 @@ public: | ||
| 104 | bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override; | 104 | bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override; |
| 105 | //! \brief Function that returns the current color of the light as hue and saturation | 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 | //! \param light A reference of the light | 108 | //! \param light A reference of the light |
| 108 | //! \return Pair containing the hue as first value and saturation as second value | 109 | //! \return Pair containing the hue as first value and saturation as second value |
| 109 | std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const override; | 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 | //! \brief Function that returns the current color of the light as xy | 117 | //! \brief Function that returns the current color of the light as xy |
| 111 | //! | 118 | //! |
| 119 | + //! Updates the lights state by calling refreshState() | ||
| 112 | //! \param light A reference of the light | 120 | //! \param light A reference of the light |
| 113 | //! \return Pair containing the x as first value and y as second value | 121 | //! \return Pair containing the x as first value and y as second value |
| 114 | std::pair<float, float> getColorXY(HueLight& light) const override; | 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 | #endif | 131 | #endif |
hueplusplus/include/SimpleColorTemperatureStrategy.h
| @@ -43,10 +43,18 @@ public: | @@ -43,10 +43,18 @@ public: | ||
| 43 | bool alertTemperature(unsigned int mired, HueLight& light) const override; | 43 | bool alertTemperature(unsigned int mired, HueLight& light) const override; |
| 44 | //! \brief Function that returns the current color temperature of the light | 44 | //! \brief Function that returns the current color temperature of the light |
| 45 | //! | 45 | //! |
| 46 | + //! Updates the lights state by calling refreshState() | ||
| 46 | //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | 47 | //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. |
| 47 | //! \param light A reference of the light | 48 | //! \param light A reference of the light |
| 48 | //! \return Unsigned int representing the color temperature in mired | 49 | //! \return Unsigned int representing the color temperature in mired |
| 49 | unsigned int getColorTemperature(HueLight& light) const override; | 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 | #endif | 60 | #endif |