Commit fe8e67ebcdc9b36d7168aadaf4a54468c9166ed2
Committed by
Moritz Wirger
1 parent
54cb817f
Cleanup Strategies and add new functions for getting some light states
Showing
3 changed files
with
122 additions
and
100 deletions
hueplusplus/include/BrightnessStrategy.h
| ... | ... | @@ -27,15 +27,20 @@ class HueLight; |
| 27 | 27 | //! Virtual base class for all BrightnessStrategies |
| 28 | 28 | class BrightnessStrategy |
| 29 | 29 | { |
| 30 | - public: | |
| 31 | - //! \brief Virtual function for changing a lights brightness with a specified transition. | |
| 32 | - //! | |
| 33 | - //! \param bri The brightness raning from 0 = off to 255 = fully lit | |
| 34 | - //! \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 | |
| 35 | - //! \param light A reference of the light | |
| 36 | - virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0; | |
| 37 | - //! \brief Virtual dtor | |
| 38 | - virtual ~BrightnessStrategy() = default; | |
| 30 | +public: | |
| 31 | + //! \brief Virtual function for changing a lights brightness with a specified transition. | |
| 32 | + //! | |
| 33 | + //! \param bri The brightness raning from 0 = off to 255 = fully lit | |
| 34 | + //! \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 | |
| 35 | + //! \param light A reference of the light | |
| 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 | |
| 38 | + //! | |
| 39 | + //! \param light A reference of the light | |
| 40 | + //! \return Unsigned int representing the brightness | |
| 41 | + virtual unsigned int getBrightness(HueLight& light) const = 0; | |
| 42 | + //! \brief Virtual dtor | |
| 43 | + virtual ~BrightnessStrategy() = default; | |
| 39 | 44 | }; |
| 40 | 45 | |
| 41 | 46 | #endif | ... | ... |
hueplusplus/include/ColorHueStrategy.h
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | #ifndef _COLOR_HUE_STRATEGY_H |
| 21 | 21 | #define _COLOR_HUE_STRATEGY_H |
| 22 | 22 | |
| 23 | +#include <memory> | |
| 23 | 24 | #include <stdint.h> |
| 24 | 25 | |
| 25 | 26 | class HueLight; |
| ... | ... | @@ -27,81 +28,91 @@ class HueLight; |
| 27 | 28 | //! Virtual base class for all ColorHueStrategies |
| 28 | 29 | class ColorHueStrategy |
| 29 | 30 | { |
| 30 | - public: | |
| 31 | - //! \brief Function for changing a lights color in hue with a specified transition. | |
| 32 | - //! | |
| 33 | - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 34 | - //! \param hue The hue of the color | |
| 35 | - //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 36 | - //! \param light A reference of the light | |
| 37 | - virtual bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const = 0; | |
| 38 | - //! \brief Function for changing a lights color in saturation with a specified transition. | |
| 39 | - //! | |
| 40 | - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 41 | - //! \param sat The saturation of the color | |
| 42 | - //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 43 | - //! \param light A reference of the light | |
| 44 | - virtual bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const = 0; | |
| 45 | - //! \brief Function for changing a lights color in hue and saturation format with a specified transition. | |
| 46 | - //! | |
| 47 | - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 48 | - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 49 | - //! \param hue The hue of the color | |
| 50 | - //! \param sat The saturation of the color | |
| 51 | - //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 52 | - //! \param light A reference of the light | |
| 53 | - virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const = 0; | |
| 54 | - //! \brief Function for changing a lights color in CIE format with a specified transition. | |
| 55 | - //! | |
| 56 | - //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 57 | - //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 58 | - //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 59 | - //! \param light A reference of the light | |
| 60 | - virtual bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const = 0; | |
| 61 | - //! \brief Function for changing a lights color in rgb format with a specified transition. | |
| 62 | - //! | |
| 63 | - //! Red, green and blue are ranging from 0 to 255. | |
| 64 | - //! \param r The red portion of the color | |
| 65 | - //! \param g The green portion of the color | |
| 66 | - //! \param b The blue portion of the color | |
| 67 | - //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 68 | - //! \param light A reference of the light | |
| 69 | - virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const = 0; | |
| 70 | - //! \brief Function for turning on/off the color loop feature of a light. | |
| 71 | - //! | |
| 72 | - //! Can be theoretically set for any light, but it only works for lights that support this feature. | |
| 73 | - //! When this feature is activated the light will fade through every color on the current hue and saturation settings. | |
| 74 | - //! Notice that none of the setter functions check whether this feature is enabled and | |
| 75 | - //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh() | |
| 76 | - //! and then On()/OnNoRefresh(), so you could alternatively call Off() and | |
| 77 | - //! then use any of the setter functions. | |
| 78 | - //! \param on Boolean to turn this feature on or off, true/1 for on and false/0 for off | |
| 79 | - //! \param light A reference of the light | |
| 80 | - virtual bool setColorLoop(bool on, HueLight& light) const = 0; | |
| 81 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 82 | - //! | |
| 83 | - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 84 | - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 85 | - //! \param hue The hue of the color | |
| 86 | - //! \param sat The saturation of the color | |
| 87 | - //! \param light A reference of the light | |
| 88 | - virtual bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const = 0; | |
| 89 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 90 | - //! | |
| 91 | - //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 92 | - //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 93 | - //! \param light A reference of the light | |
| 94 | - virtual bool alertXY(float x, float y, HueLight& light) const = 0; | |
| 95 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 96 | - //! | |
| 97 | - //! Red, green and blue are ranging from 0 to 255. | |
| 98 | - //! \param r The red portion of the color | |
| 99 | - //! \param g The green portion of the color | |
| 100 | - //! \param b The blue portion of the color | |
| 101 | - //! \param light A reference of the light | |
| 102 | - virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0; | |
| 103 | - //! \brief Virtual dtor | |
| 104 | - virtual ~ColorHueStrategy() = default; | |
| 31 | +public: | |
| 32 | + //! \brief Virtual function for changing a lights color in hue with a specified transition. | |
| 33 | + //! | |
| 34 | + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 35 | + //! \param hue The hue of the color | |
| 36 | + //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 37 | + //! \param light A reference of the light | |
| 38 | + virtual bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const = 0; | |
| 39 | + //! \brief Virtual function for changing a lights color in saturation with a specified transition. | |
| 40 | + //! | |
| 41 | + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 42 | + //! \param sat The saturation of the color | |
| 43 | + //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 44 | + //! \param light A reference of the light | |
| 45 | + virtual bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const = 0; | |
| 46 | + //! \brief Virtual function for changing a lights color in hue and saturation format with a specified transition. | |
| 47 | + //! | |
| 48 | + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 49 | + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 50 | + //! \param hue The hue of the color | |
| 51 | + //! \param sat The saturation of the color | |
| 52 | + //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 53 | + //! \param light A reference of the light | |
| 54 | + virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const = 0; | |
| 55 | + //! \brief Virtual function for changing a lights color in CIE format with a specified transition. | |
| 56 | + //! | |
| 57 | + //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 58 | + //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 59 | + //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 60 | + //! \param light A reference of the light | |
| 61 | + virtual bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const = 0; | |
| 62 | + //! \brief Virtual function for changing a lights color in rgb format with a specified transition. | |
| 63 | + //! | |
| 64 | + //! Red, green and blue are ranging from 0 to 255. | |
| 65 | + //! \param r The red portion of the color | |
| 66 | + //! \param g The green portion of the color | |
| 67 | + //! \param b The blue portion of the color | |
| 68 | + //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 69 | + //! \param light A reference of the light | |
| 70 | + virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const = 0; | |
| 71 | + //! \brief Virtual function for turning on/off the color loop feature of a light. | |
| 72 | + //! | |
| 73 | + //! Can be theoretically set for any light, but it only works for lights that support this feature. | |
| 74 | + //! When this feature is activated the light will fade through every color on the current hue and saturation settings. | |
| 75 | + //! Notice that none of the setter functions check whether this feature is enabled and | |
| 76 | + //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh() | |
| 77 | + //! and then On()/OnNoRefresh(), so you could alternatively call Off() and | |
| 78 | + //! then use any of the setter functions. | |
| 79 | + //! \param on Boolean to turn this feature on or off, true/1 for on and false/0 for off | |
| 80 | + //! \param light A reference of the light | |
| 81 | + virtual bool setColorLoop(bool on, HueLight& light) const = 0; | |
| 82 | + //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 83 | + //! | |
| 84 | + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 85 | + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 86 | + //! \param hue The hue of the color | |
| 87 | + //! \param sat The saturation of the color | |
| 88 | + //! \param light A reference of the light | |
| 89 | + virtual bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const = 0; | |
| 90 | + //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 91 | + //! | |
| 92 | + //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 93 | + //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 94 | + //! \param light A reference of the light | |
| 95 | + virtual bool alertXY(float x, float y, HueLight& light) const = 0; | |
| 96 | + //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 97 | + //! | |
| 98 | + //! Red, green and blue are ranging from 0 to 255. | |
| 99 | + //! \param r The red portion of the color | |
| 100 | + //! \param g The green portion of the color | |
| 101 | + //! \param b The blue portion of the color | |
| 102 | + //! \param light A reference of the light | |
| 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 | |
| 105 | + //! | |
| 106 | + //! \param light A reference of the light | |
| 107 | + //! \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 | + //! \brief Virtual function that returns the current color of the light as xy | |
| 110 | + //! | |
| 111 | + //! \param light A reference of the light | |
| 112 | + //! \return Pair containing the x as first value and y as second value | |
| 113 | + virtual std::pair<float, float> getColorXY(HueLight& light) const = 0; | |
| 114 | + //! \brief Virtual dtor | |
| 115 | + virtual ~ColorHueStrategy() = default; | |
| 105 | 116 | }; |
| 106 | 117 | |
| 107 | 118 | #endif | ... | ... |
hueplusplus/include/ColorTemperatureStrategy.h
| ... | ... | @@ -27,22 +27,28 @@ class HueLight; |
| 27 | 27 | //! Virtual base class for all ColorTemperatureStrategies |
| 28 | 28 | class ColorTemperatureStrategy |
| 29 | 29 | { |
| 30 | - public: | |
| 31 | - //! \brief Virtual function for changing a lights color temperature in mired with a specified transition. | |
| 32 | - //! | |
| 33 | - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 34 | - //! \param mired The color temperature in mired | |
| 35 | - //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 36 | - //! \param light A reference of the light | |
| 37 | - virtual bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const = 0; | |
| 38 | - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 39 | - //! | |
| 40 | - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 41 | - //! \param mired The color temperature in mired | |
| 42 | - //! \param light A reference of the light | |
| 43 | - virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0; | |
| 44 | - //! \brief Virtual dtor | |
| 45 | - virtual ~ColorTemperatureStrategy() = default; | |
| 30 | +public: | |
| 31 | + //! \brief Virtual function for changing a lights color temperature in mired with a specified transition. | |
| 32 | + //! | |
| 33 | + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 34 | + //! \param mired The color temperature in mired | |
| 35 | + //! \param transition The time it takes to fade to the new color in multiples of 100ms, 4 = 400ms and should be seen as the default | |
| 36 | + //! \param light A reference of the light | |
| 37 | + virtual bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const = 0; | |
| 38 | + //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 39 | + //! | |
| 40 | + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 41 | + //! \param mired The color temperature in mired | |
| 42 | + //! \param light A reference of the light | |
| 43 | + virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0; | |
| 44 | + //! \brief Virtual function that returns the current color temperature of the light | |
| 45 | + //! | |
| 46 | + //! 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 | + //! \return Unsigned int representing the color temperature in mired | |
| 49 | + virtual unsigned int getColorTemperature(HueLight& light) const = 0; | |
| 50 | + //! \brief Virtual dtor | |
| 51 | + virtual ~ColorTemperatureStrategy() = default; | |
| 46 | 52 | }; |
| 47 | 53 | |
| 48 | 54 | #endif | ... | ... |