diff --git a/hueplusplus/ExtendedColorHueStrategy.cpp b/hueplusplus/ExtendedColorHueStrategy.cpp index 856941b..6c90ad7 100755 --- a/hueplusplus/ExtendedColorHueStrategy.cpp +++ b/hueplusplus/ExtendedColorHueStrategy.cpp @@ -18,6 +18,7 @@ **/ #include "include/ExtendedColorHueStrategy.h" +#include "include/HueConfig.h" #include #include @@ -36,14 +37,15 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -59,14 +61,15 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -81,14 +84,15 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorTemperature(oldCT, 1); return light.OffNoRefresh(1); } else @@ -115,14 +119,15 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -138,14 +143,15 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -160,14 +166,15 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorTemperature(oldCT, 1); return light.OffNoRefresh(1); } else @@ -194,14 +201,15 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -217,14 +225,15 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -239,14 +248,15 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorTemperature(oldCT, 1); return light.OffNoRefresh(1); } else @@ -258,4 +268,4 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh { return false; } -} \ No newline at end of file +} diff --git a/hueplusplus/ExtendedColorTemperatureStrategy.cpp b/hueplusplus/ExtendedColorTemperatureStrategy.cpp index 5cc7bdf..5cf0352 100755 --- a/hueplusplus/ExtendedColorTemperatureStrategy.cpp +++ b/hueplusplus/ExtendedColorTemperatureStrategy.cpp @@ -18,6 +18,7 @@ **/ #include "include/ExtendedColorTemperatureStrategy.h" +#include "include/HueConfig.h" #include #include @@ -55,7 +56,7 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature(unsigned int mired, u return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -94,14 +95,15 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -117,14 +119,15 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -139,14 +142,15 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorTemperature(oldCT, 1); return light.OffNoRefresh(1); } else @@ -159,4 +163,3 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL return false; } } - diff --git a/hueplusplus/SimpleBrightnessStrategy.cpp b/hueplusplus/SimpleBrightnessStrategy.cpp index 733ea0d..caa9944 100755 --- a/hueplusplus/SimpleBrightnessStrategy.cpp +++ b/hueplusplus/SimpleBrightnessStrategy.cpp @@ -51,7 +51,6 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio } if (light.state["state"]["bri"].asUInt() != bri) { - bri -= 1; if (bri > 254) { bri = 254; @@ -65,7 +64,7 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -91,3 +90,9 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio return success; } } + +unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const +{ + light.refreshState(); + return light.state["state"]["bri"].asUInt(); +} diff --git a/hueplusplus/SimpleColorHueStrategy.cpp b/hueplusplus/SimpleColorHueStrategy.cpp index 23fe7c8..30d413b 100755 --- a/hueplusplus/SimpleColorHueStrategy.cpp +++ b/hueplusplus/SimpleColorHueStrategy.cpp @@ -18,6 +18,7 @@ **/ #include "include/SimpleColorHueStrategy.h" +#include "include/HueConfig.h" #include #include @@ -47,7 +48,7 @@ bool SimpleColorHueStrategy::setColorHue(uint16_t hue, uint8_t transistion, HueL return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -100,7 +101,7 @@ bool SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_t transistion return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -159,7 +160,7 @@ bool SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, ui return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -216,7 +217,7 @@ bool SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t transistion, H return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -248,21 +249,21 @@ bool SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t transistion, H bool SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transistion, HueLight& light) const { - float red = float(r) / 255; - float green = float(g) / 255; - float blue = float(b) / 255; + const float red = float(r) / 255; + const float green = float(g) / 255; + const float blue = float(b) / 255; // gamma correction - red = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); - green = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); - blue = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f); + const float redCorrected = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); + const float greenCorrected = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); + const float blueCorrected = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f); - float X = red * 0.664511f + green * 0.154324f + blue * 0.162028f; - float Y = red * 0.283881f + green * 0.668433f + blue * 0.047685f; - float Z = red * 0.000088f + green * 0.072310f + blue * 0.986039f; + const float X = redCorrected * 0.664511f + greenCorrected * 0.154324f + blueCorrected * 0.162028f; + const float Y = redCorrected * 0.283881f + greenCorrected * 0.668433f + blueCorrected * 0.047685f; + const float Z = redCorrected * 0.000088f + greenCorrected * 0.072310f + blueCorrected * 0.986039f; - float x = X / (X + Y + Z); - float y = Y / (X + Y + Z); + const float x = X / (X + Y + Z); + const float y = Y / (X + Y + Z); return light.setColorXY(x, y, transistion); } @@ -288,7 +289,7 @@ bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -321,14 +322,15 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -344,14 +346,15 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -378,14 +381,15 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -401,14 +405,15 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -435,14 +440,15 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorHueSaturation(oldHue, oldSat, 1); return light.OffNoRefresh(1); } else @@ -458,14 +464,15 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorXY(oldX, oldY, 1); return light.OffNoRefresh(1); } else @@ -479,6 +486,17 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& } } +std::pair SimpleColorHueStrategy::getColorHueSaturation(HueLight & light) const +{ + light.refreshState(); + 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()); +} /*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 a6decd4..7c24370 100755 --- a/hueplusplus/SimpleColorTemperatureStrategy.cpp +++ b/hueplusplus/SimpleColorTemperatureStrategy.cpp @@ -18,6 +18,7 @@ **/ #include "include/SimpleColorTemperatureStrategy.h" +#include "include/HueConfig.h" #include #include @@ -55,7 +56,7 @@ bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uin return true; } - Json::Value reply = light.SendPutRequest(request); + Json::Value reply = light.SendPutRequest(request, "/state"); //Check whether request was successful std::string path = "/lights/" + std::to_string(light.id) + "/state/"; @@ -93,14 +94,15 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(110)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); if (!light.alert()) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); if (!on) { + light.setColorTemperature(oldCT, 1); return light.OffNoRefresh(1); } else @@ -114,3 +116,8 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig } } +unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const +{ + light.refreshState(); + return light.state["state"]["ct"].asUInt(); +} diff --git a/hueplusplus/include/ExtendedColorHueStrategy.h b/hueplusplus/include/ExtendedColorHueStrategy.h index 420bb42..15e850a 100755 --- a/hueplusplus/include/ExtendedColorHueStrategy.h +++ b/hueplusplus/include/ExtendedColorHueStrategy.h @@ -26,32 +26,32 @@ //! Class extending the implementation of SimpleColorHueStrategy class ExtendedColorHueStrategy : public SimpleColorHueStrategy { - public: - //! \brief Function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). - //! \param hue The hue of the color - //! \param sat The saturation of the color - //! \param light A reference of the light - bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const; - //! \brief Function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! \param x The x coordinate in CIE, ranging from 0 to 1 - //! \param y The y coordinate in CIE, ranging from 0 to 1 - //! \param light A reference of the light - bool alertXY(float x, float y, HueLight& light) const; - //! \brief Function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! Red, green and blue are ranging from 0 to 255. - //! \param r The red portion of the color - //! \param g The green portion of the color - //! \param b The blue portion of the color - //! \param light A reference of the light - bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const; +public: + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). + //! \param hue The hue of the color + //! \param sat The saturation of the color + //! \param light A reference of the light + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! \param x The x coordinate in CIE, ranging from 0 to 1 + //! \param y The y coordinate in CIE, ranging from 0 to 1 + //! \param light A reference of the light + bool alertXY(float x, float y, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! Red, green and blue are ranging from 0 to 255. + //! \param r The red portion of the color + //! \param g The green portion of the color + //! \param b The blue portion of the color + //! \param light A reference of the light + bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override; }; #endif diff --git a/hueplusplus/include/ExtendedColorTemperatureStrategy.h b/hueplusplus/include/ExtendedColorTemperatureStrategy.h index f9396ea..ec3afc2 100755 --- a/hueplusplus/include/ExtendedColorTemperatureStrategy.h +++ b/hueplusplus/include/ExtendedColorTemperatureStrategy.h @@ -20,27 +20,27 @@ #ifndef _EXTENDED_COLOR_TEMPERATURE_STRATEGY_H #define _EXTENDED_COLOR_TEMPERATURE_STRATEGY_H -#include "ColorTemperatureStrategy.h" +#include "SimpleColorTemperatureStrategy.h" #include "HueLight.h" //! Class implementing the functions of ColorTemperatureStrategy -class ExtendedColorTemperatureStrategy : public ColorTemperatureStrategy +class ExtendedColorTemperatureStrategy : public SimpleColorTemperatureStrategy { - public: - //! \brief Function for changing a lights color temperature in mired with a specified transition. - //! - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. - //! \param mired The color temperature in mired - //! \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 - //! \param light A reference of the light - bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const; - //! \brief Function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. - //! \param mired The color temperature in mired - //! \param light A reference of the light - bool alertTemperature(unsigned int mired, HueLight& light) const; +public: + //! \brief Function for changing a lights color temperature in mired with a specified transition. + //! + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \param mired The color temperature in mired + //! \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 + //! \param light A reference of the light + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \param mired The color temperature in mired + //! \param light A reference of the light + bool alertTemperature(unsigned int mired, HueLight& light) const override; }; #endif diff --git a/hueplusplus/include/HueConfig.h b/hueplusplus/include/HueConfig.h new file mode 100755 index 0000000..965bb70 --- /dev/null +++ b/hueplusplus/include/HueConfig.h @@ -0,0 +1,26 @@ +/** + \file HueConfig.h + Copyright Notice\n + Copyright (C) 2017 Jan Rogall - developer\n + Copyright (C) 2017 Moritz Wirger - developer\n + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +**/ + +#ifndef _HUE_CONFIG_H +#define _HUE_CONFIG_H + +const uint16_t c_PRE_ALERT_DELAY = 120; //!< Delay for advanced alerts before the actual alert +const uint16_t c_POST_ALERT_DELAY = 1600; //!< Delay for advanced alerts after the actual alert + +#endif diff --git a/hueplusplus/include/SimpleBrightnessStrategy.h b/hueplusplus/include/SimpleBrightnessStrategy.h index 401f74c..0fc6405 100755 --- a/hueplusplus/include/SimpleBrightnessStrategy.h +++ b/hueplusplus/include/SimpleBrightnessStrategy.h @@ -26,13 +26,18 @@ //! Class implementing the functions of BrightnessStrategy class SimpleBrightnessStrategy : public BrightnessStrategy { - public: - //! \brief Function for changing a lights brightness with a specified transition. - //! - //! \param bri The brightness raning from 0 = off to 255 = fully lit - //! \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; +public: + //! \brief Function for changing a lights brightness with a specified transition. + //! + //! \param bri The brightness raning from 0 = off to 255 = fully lit + //! \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 + //! + //! \param light A reference of the light + //! \return Unsigned int representing the brightness + unsigned int getBrightness(HueLight& light) const override; }; #endif diff --git a/hueplusplus/include/SimpleColorHueStrategy.h b/hueplusplus/include/SimpleColorHueStrategy.h index 7a0b3ad..96ac649 100755 --- a/hueplusplus/include/SimpleColorHueStrategy.h +++ b/hueplusplus/include/SimpleColorHueStrategy.h @@ -26,82 +26,92 @@ //! Class implementing the functions of ColorHueStrategy class SimpleColorHueStrategy : public ColorHueStrategy { - public: - //! \brief Function for changing a lights color in hue with a specified transition. - //! - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. - //! \param hue The hue of the color - //! \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 - //! \param light A reference of the light - bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const; - //! \brief Virtual function for changing a lights color in saturation with a specified transition. - //! - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). - //! \param sat The saturation of the color - //! \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 - //! \param light A reference of the light - bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const; - //! \brief Virtual function for changing a lights color in hue and saturation format with a specified transition. - //! - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). - //! \param hue The hue of the color - //! \param sat The saturation of the color - //! \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 - //! \param light A reference of the light - bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const; - //! \brief Virtual function for changing a lights color in CIE format with a specified transition. - //! - //! \param x The x coordinate in CIE, ranging from 0 to 1 - //! \param y The y coordinate in CIE, ranging from 0 to 1 - //! \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 - //! \param light A reference of the light - bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const; - //! \brief Virtual function for changing a lights color in rgb format with a specified transition. - //! - //! Red, green and blue are ranging from 0 to 255. - //! \param r The red portion of the color - //! \param g The green portion of the color - //! \param b The blue portion of the color - //! \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 - //! \param light A reference of the light - bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const; - //! \brief Virtual function for turning on/off the color loop feature of a light. - //! - //! Can be theoretically set for any light, but it only works for lights that support this feature. - //! When this feature is activated the light will fade through every color on the current hue and saturation settings. - //! Notice that none of the setter functions check whether this feature is enabled and - //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh() - //! and then On()/OnNoRefresh(), so you could alternatively call Off() and - //! then use any of the setter functions. - //! \param on Boolean to turn this feature on or off, true/1 for on and false/0 for off - //! \param light A reference of the light - bool setColorLoop(bool on, HueLight& light) const; - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). - //! \param hue The hue of the color - //! \param sat The saturation of the color - //! \param light A reference of the light - bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const; - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! \param x The x coordinate in CIE, ranging from 0 to 1 - //! \param y The y coordinate in CIE, ranging from 0 to 1 - //! \param light A reference of the light - bool alertXY(float x, float y, HueLight& light) const; - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! Red, green and blue are ranging from 0 to 255. - //! \param r The red portion of the color - //! \param g The green portion of the color - //! \param b The blue portion of the color - //! \param light A reference of the light - bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const; +public: + //! \brief Function for changing a lights color in hue with a specified transition. + //! + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. + //! \param hue The hue of the color + //! \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 + //! \param light A reference of the light + bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const override; + //! \brief Function for changing a lights color in saturation with a specified transition. + //! + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). + //! \param sat The saturation of the color + //! \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 + //! \param light A reference of the light + bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const override; + //! \brief Function for changing a lights color in hue and saturation format with a specified transition. + //! + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). + //! \param hue The hue of the color + //! \param sat The saturation of the color + //! \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 + //! \param light A reference of the light + bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const override; + //! \brief Function for changing a lights color in CIE format with a specified transition. + //! + //! \param x The x coordinate in CIE, ranging from 0 to 1 + //! \param y The y coordinate in CIE, ranging from 0 to 1 + //! \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 + //! \param light A reference of the light + bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const override; + //! \brief Function for changing a lights color in rgb format with a specified transition. + //! + //! Red, green and blue are ranging from 0 to 255. + //! \param r The red portion of the color + //! \param g The green portion of the color + //! \param b The blue portion of the color + //! \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 + //! \param light A reference of the light + bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const override; + //! \brief Function for turning on/off the color loop feature of a light. + //! + //! Can be theoretically set for any light, but it only works for lights that support this feature. + //! When this feature is activated the light will fade through every color on the current hue and saturation settings. + //! Notice that none of the setter functions check whether this feature is enabled and + //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh() + //! and then On()/OnNoRefresh(), so you could alternatively call Off() and + //! then use any of the setter functions. + //! \param on Boolean to turn this feature on or off, true/1 for on and false/0 for off + //! \param light A reference of the light + bool setColorLoop(bool on, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). + //! \param hue The hue of the color + //! \param sat The saturation of the color + //! \param light A reference of the light + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! \param x The x coordinate in CIE, ranging from 0 to 1 + //! \param y The y coordinate in CIE, ranging from 0 to 1 + //! \param light A reference of the light + bool alertXY(float x, float y, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! Red, green and blue are ranging from 0 to 255. + //! \param r The red portion of the color + //! \param g The green portion of the color + //! \param b The blue portion of the color + //! \param light A reference of the light + 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 + //! + //! \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 xy + //! + //! \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; }; #endif diff --git a/hueplusplus/include/SimpleColorTemperatureStrategy.h b/hueplusplus/include/SimpleColorTemperatureStrategy.h index 2f865fe..03b6e52 100755 --- a/hueplusplus/include/SimpleColorTemperatureStrategy.h +++ b/hueplusplus/include/SimpleColorTemperatureStrategy.h @@ -26,21 +26,27 @@ //! Class implementing the functions of ColorTemperatureStrategy class SimpleColorTemperatureStrategy : public ColorTemperatureStrategy { - public: - //! \brief Function for changing a lights color temperature in mired with a specified transition. - //! - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. - //! \param mired The color temperature in mired - //! \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 - //! \param light A reference of the light - bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const; - //! \brief Function that lets the light perform one breath cycle in the specified color. - //! - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. - //! \param mired The color temperature in mired - //! \param light A reference of the light - bool alertTemperature(unsigned int mired, HueLight& light) const; +public: + //! \brief Function for changing a lights color temperature in mired with a specified transition. + //! + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \param mired The color temperature in mired + //! \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 + //! \param light A reference of the light + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override; + //! \brief Function that lets the light perform one breath cycle in the specified color. + //! + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. + //! \param mired The color temperature in mired + //! \param light A reference of the light + bool alertTemperature(unsigned int mired, 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. + //! \param light A reference of the light + //! \return Unsigned int representing the color temperature in mired + unsigned int getColorTemperature(HueLight& light) const override; }; #endif