diff --git a/hueplusplus/SimpleBrightnessStrategy.cpp b/hueplusplus/SimpleBrightnessStrategy.cpp index caa9944..73a304b 100755 --- a/hueplusplus/SimpleBrightnessStrategy.cpp +++ b/hueplusplus/SimpleBrightnessStrategy.cpp @@ -96,3 +96,8 @@ unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const light.refreshState(); return light.state["state"]["bri"].asUInt(); } + +unsigned int SimpleBrightnessStrategy::getBrightness(const HueLight& light) const +{ + return light.state["state"]["bri"].asUInt(); +} diff --git a/hueplusplus/SimpleColorHueStrategy.cpp b/hueplusplus/SimpleColorHueStrategy.cpp index 30d413b..df7da51 100755 --- a/hueplusplus/SimpleColorHueStrategy.cpp +++ b/hueplusplus/SimpleColorHueStrategy.cpp @@ -492,11 +492,21 @@ std::pair SimpleColorHueStrategy::getColorHueSaturation(HueLi return std::pair(static_cast(light.state["state"]["hue"].asUInt()), static_cast(light.state["state"]["sat"].asUInt())); } +std::pair SimpleColorHueStrategy::getColorHueSaturation(const HueLight & light) const +{ + return std::pair(static_cast(light.state["state"]["hue"].asUInt()), static_cast(light.state["state"]["sat"].asUInt())); +} + std::pair SimpleColorHueStrategy::getColorXY(HueLight & light) const { light.refreshState(); return std::pair(light.state["state"]["xy"][0].asFloat(), light.state["state"]["xy"][1].asFloat()); } + +std::pair SimpleColorHueStrategy::getColorXY(const HueLight & light) const +{ + return std::pair(light.state["state"]["xy"][0].asFloat(), light.state["state"]["xy"][1].asFloat()); +} /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2) { float A = (-y1 * x2 + y0*(-x1 + x2) + x0*(y1 - y2) + x1 * y1); diff --git a/hueplusplus/SimpleColorTemperatureStrategy.cpp b/hueplusplus/SimpleColorTemperatureStrategy.cpp index 7c24370..4e3e24d 100755 --- a/hueplusplus/SimpleColorTemperatureStrategy.cpp +++ b/hueplusplus/SimpleColorTemperatureStrategy.cpp @@ -121,3 +121,8 @@ unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light light.refreshState(); return light.state["state"]["ct"].asUInt(); } + +unsigned int SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const +{ + return light.state["state"]["ct"].asUInt(); +} diff --git a/hueplusplus/include/BrightnessStrategy.h b/hueplusplus/include/BrightnessStrategy.h index ff29224..dcf97eb 100755 --- a/hueplusplus/include/BrightnessStrategy.h +++ b/hueplusplus/include/BrightnessStrategy.h @@ -36,9 +36,16 @@ public: virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0; //! \brief Virtual function that returns the current brightnessof the light //! + //! Should update the lights state by calling refreshState() //! \param light A reference of the light //! \return Unsigned int representing the brightness virtual unsigned int getBrightness(HueLight& light) const = 0; + //! \brief Virtual function that returns the current brightness of the light + //! + //! \note This should not update the lights state + //! \param light A const reference of the light + //! \return Unsigned int representing the brightness + virtual unsigned int getBrightness(const HueLight& light) const = 0; //! \brief Virtual dtor virtual ~BrightnessStrategy() = default; }; diff --git a/hueplusplus/include/ColorHueStrategy.h b/hueplusplus/include/ColorHueStrategy.h index 3d848db..062ca4c 100755 --- a/hueplusplus/include/ColorHueStrategy.h +++ b/hueplusplus/include/ColorHueStrategy.h @@ -103,14 +103,28 @@ public: virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0; //! \brief Virtual function that returns the current color of the light as hue and saturation //! + //! Should update the lights state by calling refreshState() //! \param light A reference of the light //! \return Pair containing the hue as first value and saturation as second value virtual std::pair getColorHueSaturation(HueLight& light) const = 0; + //! \brief Virtual function that returns the current color of the light as hue and saturation + //! + //! \note This should not update the lights state + //! \param light A const reference of the light + //! \return Pair containing the hue as first value and saturation as second value + virtual std::pair getColorHueSaturation(const HueLight& light) const = 0; //! \brief Virtual function that returns the current color of the light as xy //! + //! Should update the lights state by calling refreshState() //! \param light A reference of the light //! \return Pair containing the x as first value and y as second value virtual std::pair getColorXY(HueLight& light) const = 0; + //! \brief Virtual function that returns the current color of the light as xy + //! + //! \note This should not update the lights state + //! \param light A const reference of the light + //! \return Pair containing the x as first value and y as second value + virtual std::pair getColorXY(const HueLight& light) const = 0; //! \brief Virtual dtor virtual ~ColorHueStrategy() = default; }; diff --git a/hueplusplus/include/ColorTemperatureStrategy.h b/hueplusplus/include/ColorTemperatureStrategy.h index 58dc0a9..7d26a19 100755 --- a/hueplusplus/include/ColorTemperatureStrategy.h +++ b/hueplusplus/include/ColorTemperatureStrategy.h @@ -43,10 +43,18 @@ public: virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0; //! \brief Virtual function that returns the current color temperature of the light //! + //! Should update the lights state by calling refreshState() //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. //! \param light A reference of the light //! \return Unsigned int representing the color temperature in mired virtual unsigned int getColorTemperature(HueLight& light) const = 0; + //! \brief Virtual function that returns the current color temperature of the light + //! + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \note This should not update the lights state + //! \param light A const reference of the light + //! \return Unsigned int representing the color temperature in mired + virtual unsigned int getColorTemperature(const HueLight& light) const = 0; //! \brief Virtual dtor virtual ~ColorTemperatureStrategy() = default; }; diff --git a/hueplusplus/include/HueLight.h b/hueplusplus/include/HueLight.h index 5783a1f..2a238cb 100755 --- a/hueplusplus/include/HueLight.h +++ b/hueplusplus/include/HueLight.h @@ -133,6 +133,30 @@ public: //! \return ColorType containig the color type of the light ColorType getColorType(); + //! \brief Function to check whether this light has brightness control + //! + //! \return Bool that is true when the light has specified abilities and false when not + bool hasBrightnessControl() + { + return brightnessStrategy != nullptr; + }; + + //! \brief Function to check whether this light has color temperature control + //! + //! \return Bool that is true when the light has specified abilities and false when not + bool hasTemperatureControl() + { + return colorTemperatureStrategy != nullptr; + }; + + //! \brief Function to check whether this light has full color control + //! + //! \return Bool that is true when the light has specified abilities and false when not + bool hasColorControl() + { + return colorHueStrategy != nullptr; + }; + //! \brief Function that converts Kelvin to Mired. //! //! \param kelvin Unsigned integer value in Kelvin @@ -147,7 +171,7 @@ public: //! \brief Function that sets the brightness of this light. //! - //! Notice the brightness will only be set if the light has a reference to a specific \ref BrightnessStrategy. + //! \note The brightness will only be set if the light has a reference to a specific \ref BrightnessStrategy. //! The brightness can range from 0 = off to 254 = fully lit. //! \param bri Unsigned int that specifies the brightness //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms @@ -161,9 +185,24 @@ public: return false; }; + //! \brief Const function that returns the brightness of this light. + //! + //! \note The brightness will only be returned if the light has a reference to a specific \ref BrightnessStrategy. + //! \note This will not refresh the light state + //! The brightness can range from 0 = off to 254 = fully lit. + //! \return Unsigned int that is 0 when function failed + unsigned int getBrightness() const + { + if (brightnessStrategy) + { + return brightnessStrategy->getBrightness(*this); + } + return 0; + }; + //! \brief Function that returns the brightness of this light. //! - //! Notice the brightness will only be returned if the light has a reference to a specific \ref BrightnessStrategy. + //! \note The brightness will only be returned if the light has a reference to a specific \ref BrightnessStrategy. //! The brightness can range from 0 = off to 254 = fully lit. //! \return Unsigned int that is 0 when function failed unsigned int getBrightness() @@ -177,7 +216,7 @@ public: //! \brief Fucntion that sets the color temperature of this light in mired. //! - //! Notice the color temperature will only be set if the light has a reference to a specific \ref ColorTemperatureStrategy. + //! \note The color temperature will only be set if the light has a reference to a specific \ref ColorTemperatureStrategy. //! The color temperature can range from 153 to 500. //! \param mired Unsigned int that specifies the color temperature in Mired //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms @@ -191,9 +230,41 @@ public: return false; }; + //! \brief Const function that returns the current color temperature of the light + //! + //! \note The color temperature will only be returned when the light has a reference to a specific \ref ColorTemperatureStrategy. + //! \note This will not refresh the light state + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \param light A reference of the light + //! \return Unsigned int representing the color temperature in mired or 0 when failed + unsigned int getColorTemperature() const + { + if (colorTemperatureStrategy) + { + return colorTemperatureStrategy->getColorTemperature(*this); + } + return 0; + }; + + //! \brief Function that returns the current color temperature of the light + //! + //! \note The color temperature will only be returned when the light has a reference to a specific \ref ColorTemperatureStrategy. + //! Updates the lights state by calling refreshState() + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \param light A reference of the light + //! \return Unsigned int representing the color temperature in mired or 0 when failed + unsigned int getColorTemperature() + { + if (colorTemperatureStrategy) + { + return colorTemperatureStrategy->getColorTemperature(*this); + } + return 0; + }; + //! \brief Function to set the color of this light with specified hue. //! - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy. //! The hue can range from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. //! \param hue uint16_t that specifies the hue //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms @@ -209,7 +280,7 @@ public: //! \brief Function to set the color of this light with specified saturation. //! - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy. //! The saturation can range from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated. //! \param sat uint8_t that specifies the saturation //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms @@ -225,7 +296,7 @@ public: //! \brief Function to set the color of this light with specified hue and saturation. //! - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy. //! \param hue uint16_t that specifies the hue //! \param sat uint8_t that specifies the saturation //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms. @@ -239,9 +310,39 @@ public: return false; }; + //! \brief Const function that returns the current color of the light as hue and saturation + //! + //! \note The color hue and saturation will only be returned when the light has a reference to a specific \ref ColorHueStrategy. + //! \note This will not refresh the light state + //! \param light A reference of the light + //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed + std::pair getColorHueSaturation() const + { + if(colorHueStrategy) + { + return colorHueStrategy->getColorHueSaturation(*this); + } + return {}; + }; + + //! \brief Function that returns the current color of the light as hue and saturation + //! + //! \note The color hue and saturation will only be returned when the light has a reference to a specific \ref ColorHueStrategy. + //! Updates the lights state by calling refreshState() + //! \param light A const reference of the light + //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed + std::pair getColorHueSaturation() + { + if(colorHueStrategy) + { + return colorHueStrategy->getColorHueSaturation(*this); + } + return {}; + }; + //! \brief Function to set the color of this light in CIE with specified x y. //! - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy. //! The values of x and y are ranging from 0 to 1. //! \param x float that specifies the x coordinate in CIE //! \param y float that specifies the y coordinate in CIE @@ -256,9 +357,39 @@ public: return false; }; + //! \brief Const function that returns the current color of the light as xy + //! + //! \note The color x and y will only be returned when the light has a reference to a specific \ref ColorHueStrategy. + //! \note This does not update the lights state + //! \param light A const reference of the light + //! \return Pair containing the x as first value and y as second value or an empty one when failed + std::pair getColorXY() const + { + if(colorHueStrategy) + { + return colorHueStrategy->getColorXY(*this); + } + return {}; + }; + + //! \brief Function that returns the current color of the light as xy + //! + //! \note The color x and y will only be returned when the light has a reference to a specific \ref ColorHueStrategy. + //! Updates the lights state by calling refreshState() + //! \param light A reference of the light + //! \return Pair containing the x as first value and y as second value or an empty one when failed + std::pair getColorXY() + { + if(colorHueStrategy) + { + return colorHueStrategy->getColorXY(*this); + } + return {}; + }; + //! \brief Function to set the color of this light with red green and blue values. //! - //! Notice the color will only be set if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The color will only be set if the light has a reference to a specific \ref ColorHueStrategy. //! The values of red, green and blue are ranging from 0 to 255. //! \param r uint8_t that specifies the red color value //! \param g uint8_t that specifies the green color value @@ -282,7 +413,7 @@ public: //! \brief Function that lets the light perform one breath cycle in specified color temperature. //! - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorTemperatureStrategy. + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorTemperatureStrategy. //! \param mired Color temperature in mired //! \return Bool that is true on success bool alertTemperature(unsigned int mired) @@ -296,7 +427,7 @@ public: //! \brief Function that lets the light perform one breath cycle in specified color. //! - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy. //! \param hue uint16_t that specifies the hue //! \param sat uint8_t that specifies the saturation //! \return Bool that is true on success @@ -311,7 +442,7 @@ public: //! \brief Function that lets the light perform one breath cycle in specified color. //! - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy. //! The values of x and y are ranging from 0 to 1. //! \param x float that specifies the x coordinate in CIE //! \param y float that specifies the y coordinate in CIE @@ -327,7 +458,7 @@ public: //! \brief Function that lets the light perform one breath cycle in specified color. //! - //! Notice the breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy. + //! \note The breath cylce will only be performed if the light has a reference to a specific \ref ColorHueStrategy. //! The values of red, green and blue are ranging from 0 to 255. //! \param r uint8_t that specifies the red color value //! \param g uint8_t that specifies the green color value diff --git a/hueplusplus/include/SimpleBrightnessStrategy.h b/hueplusplus/include/SimpleBrightnessStrategy.h index 0fc6405..10b1bd7 100755 --- a/hueplusplus/include/SimpleBrightnessStrategy.h +++ b/hueplusplus/include/SimpleBrightnessStrategy.h @@ -33,11 +33,18 @@ public: //! \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 //! \param light A reference of the light bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const override; - //! \brief Function that returns the current brightnessof the light + //! \brief Function that returns the current brightness of the light //! + //! Updates the lights state by calling refreshState() //! \param light A reference of the light //! \return Unsigned int representing the brightness unsigned int getBrightness(HueLight& light) const override; + //! \brief Function that returns the current brightness of the light + //! + //! \note This does not update the lights state + //! \param light A const reference of the light + //! \return Unsigned int representing the brightness + unsigned int getBrightness(const HueLight& light) const override; }; #endif diff --git a/hueplusplus/include/SimpleColorHueStrategy.h b/hueplusplus/include/SimpleColorHueStrategy.h index 96ac649..5766c81 100755 --- a/hueplusplus/include/SimpleColorHueStrategy.h +++ b/hueplusplus/include/SimpleColorHueStrategy.h @@ -104,14 +104,28 @@ public: bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override; //! \brief Function that returns the current color of the light as hue and saturation //! + //! Updates the lights state by calling refreshState() //! \param light A reference of the light //! \return Pair containing the hue as first value and saturation as second value std::pair getColorHueSaturation(HueLight& light) const override; + //! \brief Function that returns the current color of the light as hue and saturation + //! + //! \note This does not update the lights state + //! \param light A const reference of the light + //! \return Pair containing the hue as first value and saturation as second value + std::pair getColorHueSaturation(const HueLight& light) const override; //! \brief Function that returns the current color of the light as xy //! + //! Updates the lights state by calling refreshState() //! \param light A reference of the light //! \return Pair containing the x as first value and y as second value std::pair getColorXY(HueLight& light) const override; + //! \brief Function that returns the current color of the light as xy + //! + //! \note This does not update the lights state + //! \param light A const reference of the light + //! \return Pair containing the x as first value and y as second value + std::pair getColorXY(const HueLight& light) const override; }; #endif diff --git a/hueplusplus/include/SimpleColorTemperatureStrategy.h b/hueplusplus/include/SimpleColorTemperatureStrategy.h index 03b6e52..cf37765 100755 --- a/hueplusplus/include/SimpleColorTemperatureStrategy.h +++ b/hueplusplus/include/SimpleColorTemperatureStrategy.h @@ -43,10 +43,18 @@ public: bool alertTemperature(unsigned int mired, HueLight& light) const override; //! \brief Function that returns the current color temperature of the light //! + //! Updates the lights state by calling refreshState() //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. //! \param light A reference of the light //! \return Unsigned int representing the color temperature in mired unsigned int getColorTemperature(HueLight& light) const override; + //! \brief Function that returns the current color temperature of the light + //! + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \note This does not update the lights state + //! \param light A const reference of the light + //! \return Unsigned int representing the color temperature in mired + unsigned int getColorTemperature(const HueLight& light) const override; }; #endif