Commit d58597aae9ce764f9aed2468e6b50599ed5a25f0
Committed by
Moritz Wirger
1 parent
fe8e67eb
Fix unneeded calculation in setBrightness(), add new functions for getting diffe…
…rent light states, move delays for advanced alerts into HueConfig.h, Fix problem with advanced alerts where the last light state was overriden
Showing
11 changed files
with
291 additions
and
201 deletions
hueplusplus/ExtendedColorHueStrategy.cpp
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | #include "include/ExtendedColorHueStrategy.h" |
| 21 | +#include "include/HueConfig.h" | |
| 21 | 22 | |
| 22 | 23 | #include <cmath> |
| 23 | 24 | #include <iostream> |
| ... | ... | @@ -36,14 +37,15 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue |
| 36 | 37 | { |
| 37 | 38 | return false; |
| 38 | 39 | } |
| 39 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 40 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 40 | 41 | if (!light.alert()) |
| 41 | 42 | { |
| 42 | 43 | return false; |
| 43 | 44 | } |
| 44 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 45 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 45 | 46 | if (!on) |
| 46 | 47 | { |
| 48 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 47 | 49 | return light.OffNoRefresh(1); |
| 48 | 50 | } |
| 49 | 51 | else |
| ... | ... | @@ -59,14 +61,15 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue |
| 59 | 61 | { |
| 60 | 62 | return false; |
| 61 | 63 | } |
| 62 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 64 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 63 | 65 | if (!light.alert()) |
| 64 | 66 | { |
| 65 | 67 | return false; |
| 66 | 68 | } |
| 67 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 69 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 68 | 70 | if (!on) |
| 69 | 71 | { |
| 72 | + light.setColorXY(oldX, oldY, 1); | |
| 70 | 73 | return light.OffNoRefresh(1); |
| 71 | 74 | } |
| 72 | 75 | else |
| ... | ... | @@ -81,14 +84,15 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue |
| 81 | 84 | { |
| 82 | 85 | return false; |
| 83 | 86 | } |
| 84 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 87 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 85 | 88 | if (!light.alert()) |
| 86 | 89 | { |
| 87 | 90 | return false; |
| 88 | 91 | } |
| 89 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 92 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 90 | 93 | if (!on) |
| 91 | 94 | { |
| 95 | + light.setColorTemperature(oldCT, 1); | |
| 92 | 96 | return light.OffNoRefresh(1); |
| 93 | 97 | } |
| 94 | 98 | else |
| ... | ... | @@ -115,14 +119,15 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 115 | 119 | { |
| 116 | 120 | return false; |
| 117 | 121 | } |
| 118 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 122 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 119 | 123 | if (!light.alert()) |
| 120 | 124 | { |
| 121 | 125 | return false; |
| 122 | 126 | } |
| 123 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 127 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 124 | 128 | if (!on) |
| 125 | 129 | { |
| 130 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 126 | 131 | return light.OffNoRefresh(1); |
| 127 | 132 | } |
| 128 | 133 | else |
| ... | ... | @@ -138,14 +143,15 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 138 | 143 | { |
| 139 | 144 | return false; |
| 140 | 145 | } |
| 141 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 146 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 142 | 147 | if (!light.alert()) |
| 143 | 148 | { |
| 144 | 149 | return false; |
| 145 | 150 | } |
| 146 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 151 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 147 | 152 | if (!on) |
| 148 | 153 | { |
| 154 | + light.setColorXY(oldX, oldY, 1); | |
| 149 | 155 | return light.OffNoRefresh(1); |
| 150 | 156 | } |
| 151 | 157 | else |
| ... | ... | @@ -160,14 +166,15 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 160 | 166 | { |
| 161 | 167 | return false; |
| 162 | 168 | } |
| 163 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 169 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 164 | 170 | if (!light.alert()) |
| 165 | 171 | { |
| 166 | 172 | return false; |
| 167 | 173 | } |
| 168 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 174 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 169 | 175 | if (!on) |
| 170 | 176 | { |
| 177 | + light.setColorTemperature(oldCT, 1); | |
| 171 | 178 | return light.OffNoRefresh(1); |
| 172 | 179 | } |
| 173 | 180 | else |
| ... | ... | @@ -194,14 +201,15 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh |
| 194 | 201 | { |
| 195 | 202 | return false; |
| 196 | 203 | } |
| 197 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 204 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 198 | 205 | if (!light.alert()) |
| 199 | 206 | { |
| 200 | 207 | return false; |
| 201 | 208 | } |
| 202 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 209 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 203 | 210 | if (!on) |
| 204 | 211 | { |
| 212 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 205 | 213 | return light.OffNoRefresh(1); |
| 206 | 214 | } |
| 207 | 215 | else |
| ... | ... | @@ -217,14 +225,15 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh |
| 217 | 225 | { |
| 218 | 226 | return false; |
| 219 | 227 | } |
| 220 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 228 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 221 | 229 | if (!light.alert()) |
| 222 | 230 | { |
| 223 | 231 | return false; |
| 224 | 232 | } |
| 225 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 233 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 226 | 234 | if (!on) |
| 227 | 235 | { |
| 236 | + light.setColorXY(oldX, oldY, 1); | |
| 228 | 237 | return light.OffNoRefresh(1); |
| 229 | 238 | } |
| 230 | 239 | else |
| ... | ... | @@ -239,14 +248,15 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh |
| 239 | 248 | { |
| 240 | 249 | return false; |
| 241 | 250 | } |
| 242 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 251 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 243 | 252 | if (!light.alert()) |
| 244 | 253 | { |
| 245 | 254 | return false; |
| 246 | 255 | } |
| 247 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 256 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 248 | 257 | if (!on) |
| 249 | 258 | { |
| 259 | + light.setColorTemperature(oldCT, 1); | |
| 250 | 260 | return light.OffNoRefresh(1); |
| 251 | 261 | } |
| 252 | 262 | else |
| ... | ... | @@ -258,4 +268,4 @@ bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLigh |
| 258 | 268 | { |
| 259 | 269 | return false; |
| 260 | 270 | } |
| 261 | -} | |
| 262 | 271 | \ No newline at end of file |
| 272 | +} | ... | ... |
hueplusplus/ExtendedColorTemperatureStrategy.cpp
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | #include "include/ExtendedColorTemperatureStrategy.h" |
| 21 | +#include "include/HueConfig.h" | |
| 21 | 22 | |
| 22 | 23 | #include <cmath> |
| 23 | 24 | #include <iostream> |
| ... | ... | @@ -55,7 +56,7 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature(unsigned int mired, u |
| 55 | 56 | return true; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - Json::Value reply = light.SendPutRequest(request); | |
| 59 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 59 | 60 | |
| 60 | 61 | //Check whether request was successful |
| 61 | 62 | std::string path = "/lights/" + std::to_string(light.id) + "/state/"; |
| ... | ... | @@ -94,14 +95,15 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL |
| 94 | 95 | { |
| 95 | 96 | return false; |
| 96 | 97 | } |
| 97 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 98 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 98 | 99 | if (!light.alert()) |
| 99 | 100 | { |
| 100 | 101 | return false; |
| 101 | 102 | } |
| 102 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 103 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 103 | 104 | if (!on) |
| 104 | 105 | { |
| 106 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 105 | 107 | return light.OffNoRefresh(1); |
| 106 | 108 | } |
| 107 | 109 | else |
| ... | ... | @@ -117,14 +119,15 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL |
| 117 | 119 | { |
| 118 | 120 | return false; |
| 119 | 121 | } |
| 120 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 122 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 121 | 123 | if (!light.alert()) |
| 122 | 124 | { |
| 123 | 125 | return false; |
| 124 | 126 | } |
| 125 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 127 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 126 | 128 | if (!on) |
| 127 | 129 | { |
| 130 | + light.setColorXY(oldX, oldY, 1); | |
| 128 | 131 | return light.OffNoRefresh(1); |
| 129 | 132 | } |
| 130 | 133 | else |
| ... | ... | @@ -139,14 +142,15 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL |
| 139 | 142 | { |
| 140 | 143 | return false; |
| 141 | 144 | } |
| 142 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 145 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 143 | 146 | if (!light.alert()) |
| 144 | 147 | { |
| 145 | 148 | return false; |
| 146 | 149 | } |
| 147 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 150 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 148 | 151 | if (!on) |
| 149 | 152 | { |
| 153 | + light.setColorTemperature(oldCT, 1); | |
| 150 | 154 | return light.OffNoRefresh(1); |
| 151 | 155 | } |
| 152 | 156 | else |
| ... | ... | @@ -159,4 +163,3 @@ bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueL |
| 159 | 163 | return false; |
| 160 | 164 | } |
| 161 | 165 | } |
| 162 | - | ... | ... |
hueplusplus/SimpleBrightnessStrategy.cpp
| ... | ... | @@ -51,7 +51,6 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio |
| 51 | 51 | } |
| 52 | 52 | if (light.state["state"]["bri"].asUInt() != bri) |
| 53 | 53 | { |
| 54 | - bri -= 1; | |
| 55 | 54 | if (bri > 254) |
| 56 | 55 | { |
| 57 | 56 | bri = 254; |
| ... | ... | @@ -65,7 +64,7 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio |
| 65 | 64 | return true; |
| 66 | 65 | } |
| 67 | 66 | |
| 68 | - Json::Value reply = light.SendPutRequest(request); | |
| 67 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 69 | 68 | |
| 70 | 69 | //Check whether request was successful |
| 71 | 70 | std::string path = "/lights/" + std::to_string(light.id) + "/state/"; |
| ... | ... | @@ -91,3 +90,9 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio |
| 91 | 90 | return success; |
| 92 | 91 | } |
| 93 | 92 | } |
| 93 | + | |
| 94 | +unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const | |
| 95 | +{ | |
| 96 | + light.refreshState(); | |
| 97 | + return light.state["state"]["bri"].asUInt(); | |
| 98 | +} | ... | ... |
hueplusplus/SimpleColorHueStrategy.cpp
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | #include "include/SimpleColorHueStrategy.h" |
| 21 | +#include "include/HueConfig.h" | |
| 21 | 22 | |
| 22 | 23 | #include <cmath> |
| 23 | 24 | #include <iostream> |
| ... | ... | @@ -47,7 +48,7 @@ bool SimpleColorHueStrategy::setColorHue(uint16_t hue, uint8_t transistion, HueL |
| 47 | 48 | return true; |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - Json::Value reply = light.SendPutRequest(request); | |
| 51 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 51 | 52 | |
| 52 | 53 | //Check whether request was successful |
| 53 | 54 | std::string path = "/lights/" + std::to_string(light.id) + "/state/"; |
| ... | ... | @@ -100,7 +101,7 @@ bool SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_t transistion |
| 100 | 101 | return true; |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | - Json::Value reply = light.SendPutRequest(request); | |
| 104 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 104 | 105 | |
| 105 | 106 | //Check whether request was successful |
| 106 | 107 | std::string path = "/lights/" + std::to_string(light.id) + "/state/"; |
| ... | ... | @@ -159,7 +160,7 @@ bool SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, ui |
| 159 | 160 | return true; |
| 160 | 161 | } |
| 161 | 162 | |
| 162 | - Json::Value reply = light.SendPutRequest(request); | |
| 163 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 163 | 164 | |
| 164 | 165 | //Check whether request was successful |
| 165 | 166 | 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 |
| 216 | 217 | return true; |
| 217 | 218 | } |
| 218 | 219 | |
| 219 | - Json::Value reply = light.SendPutRequest(request); | |
| 220 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 220 | 221 | |
| 221 | 222 | //Check whether request was successful |
| 222 | 223 | 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 |
| 248 | 249 | |
| 249 | 250 | bool SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transistion, HueLight& light) const |
| 250 | 251 | { |
| 251 | - float red = float(r) / 255; | |
| 252 | - float green = float(g) / 255; | |
| 253 | - float blue = float(b) / 255; | |
| 252 | + const float red = float(r) / 255; | |
| 253 | + const float green = float(g) / 255; | |
| 254 | + const float blue = float(b) / 255; | |
| 254 | 255 | |
| 255 | 256 | // gamma correction |
| 256 | - red = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); | |
| 257 | - green = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); | |
| 258 | - blue = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f); | |
| 257 | + const float redCorrected = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); | |
| 258 | + const float greenCorrected = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); | |
| 259 | + const float blueCorrected = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f); | |
| 259 | 260 | |
| 260 | - float X = red * 0.664511f + green * 0.154324f + blue * 0.162028f; | |
| 261 | - float Y = red * 0.283881f + green * 0.668433f + blue * 0.047685f; | |
| 262 | - float Z = red * 0.000088f + green * 0.072310f + blue * 0.986039f; | |
| 261 | + const float X = redCorrected * 0.664511f + greenCorrected * 0.154324f + blueCorrected * 0.162028f; | |
| 262 | + const float Y = redCorrected * 0.283881f + greenCorrected * 0.668433f + blueCorrected * 0.047685f; | |
| 263 | + const float Z = redCorrected * 0.000088f + greenCorrected * 0.072310f + blueCorrected * 0.986039f; | |
| 263 | 264 | |
| 264 | - float x = X / (X + Y + Z); | |
| 265 | - float y = Y / (X + Y + Z); | |
| 265 | + const float x = X / (X + Y + Z); | |
| 266 | + const float y = Y / (X + Y + Z); | |
| 266 | 267 | |
| 267 | 268 | return light.setColorXY(x, y, transistion); |
| 268 | 269 | } |
| ... | ... | @@ -288,7 +289,7 @@ bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const |
| 288 | 289 | return true; |
| 289 | 290 | } |
| 290 | 291 | |
| 291 | - Json::Value reply = light.SendPutRequest(request); | |
| 292 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 292 | 293 | |
| 293 | 294 | //Check whether request was successful |
| 294 | 295 | std::string path = "/lights/" + std::to_string(light.id) + "/state/"; |
| ... | ... | @@ -321,14 +322,15 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi |
| 321 | 322 | { |
| 322 | 323 | return false; |
| 323 | 324 | } |
| 324 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 325 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 325 | 326 | if (!light.alert()) |
| 326 | 327 | { |
| 327 | 328 | return false; |
| 328 | 329 | } |
| 329 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 330 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 330 | 331 | if (!on) |
| 331 | 332 | { |
| 333 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 332 | 334 | return light.OffNoRefresh(1); |
| 333 | 335 | } |
| 334 | 336 | else |
| ... | ... | @@ -344,14 +346,15 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi |
| 344 | 346 | { |
| 345 | 347 | return false; |
| 346 | 348 | } |
| 347 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 349 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 348 | 350 | if (!light.alert()) |
| 349 | 351 | { |
| 350 | 352 | return false; |
| 351 | 353 | } |
| 352 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 354 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 353 | 355 | if (!on) |
| 354 | 356 | { |
| 357 | + light.setColorXY(oldX, oldY, 1); | |
| 355 | 358 | return light.OffNoRefresh(1); |
| 356 | 359 | } |
| 357 | 360 | else |
| ... | ... | @@ -378,14 +381,15 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 378 | 381 | { |
| 379 | 382 | return false; |
| 380 | 383 | } |
| 381 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 384 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 382 | 385 | if (!light.alert()) |
| 383 | 386 | { |
| 384 | 387 | return false; |
| 385 | 388 | } |
| 386 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 389 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 387 | 390 | if (!on) |
| 388 | 391 | { |
| 392 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 389 | 393 | return light.OffNoRefresh(1); |
| 390 | 394 | } |
| 391 | 395 | else |
| ... | ... | @@ -401,14 +405,15 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const |
| 401 | 405 | { |
| 402 | 406 | return false; |
| 403 | 407 | } |
| 404 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 408 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 405 | 409 | if (!light.alert()) |
| 406 | 410 | { |
| 407 | 411 | return false; |
| 408 | 412 | } |
| 409 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 413 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 410 | 414 | if (!on) |
| 411 | 415 | { |
| 416 | + light.setColorXY(oldX, oldY, 1); | |
| 412 | 417 | return light.OffNoRefresh(1); |
| 413 | 418 | } |
| 414 | 419 | else |
| ... | ... | @@ -435,14 +440,15 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& |
| 435 | 440 | { |
| 436 | 441 | return false; |
| 437 | 442 | } |
| 438 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 443 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 439 | 444 | if (!light.alert()) |
| 440 | 445 | { |
| 441 | 446 | return false; |
| 442 | 447 | } |
| 443 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 448 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 444 | 449 | if (!on) |
| 445 | 450 | { |
| 451 | + light.setColorHueSaturation(oldHue, oldSat, 1); | |
| 446 | 452 | return light.OffNoRefresh(1); |
| 447 | 453 | } |
| 448 | 454 | else |
| ... | ... | @@ -458,14 +464,15 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& |
| 458 | 464 | { |
| 459 | 465 | return false; |
| 460 | 466 | } |
| 461 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 467 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 462 | 468 | if (!light.alert()) |
| 463 | 469 | { |
| 464 | 470 | return false; |
| 465 | 471 | } |
| 466 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 472 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 467 | 473 | if (!on) |
| 468 | 474 | { |
| 475 | + light.setColorXY(oldX, oldY, 1); | |
| 469 | 476 | return light.OffNoRefresh(1); |
| 470 | 477 | } |
| 471 | 478 | else |
| ... | ... | @@ -479,6 +486,17 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& |
| 479 | 486 | } |
| 480 | 487 | } |
| 481 | 488 | |
| 489 | +std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLight & light) const | |
| 490 | +{ | |
| 491 | + light.refreshState(); | |
| 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 | +} | |
| 494 | + | |
| 495 | +std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight & light) const | |
| 496 | +{ | |
| 497 | + light.refreshState(); | |
| 498 | + return std::pair<float, float>(light.state["state"]["xy"][0].asFloat(), light.state["state"]["xy"][1].asFloat()); | |
| 499 | +} | |
| 482 | 500 | /*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2) |
| 483 | 501 | { |
| 484 | 502 | float A = (-y1 * x2 + y0*(-x1 + x2) + x0*(y1 - y2) + x1 * y1); | ... | ... |
hueplusplus/SimpleColorTemperatureStrategy.cpp
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | #include "include/SimpleColorTemperatureStrategy.h" |
| 21 | +#include "include/HueConfig.h" | |
| 21 | 22 | |
| 22 | 23 | #include <cmath> |
| 23 | 24 | #include <iostream> |
| ... | ... | @@ -55,7 +56,7 @@ bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uin |
| 55 | 56 | return true; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - Json::Value reply = light.SendPutRequest(request); | |
| 59 | + Json::Value reply = light.SendPutRequest(request, "/state"); | |
| 59 | 60 | |
| 60 | 61 | //Check whether request was successful |
| 61 | 62 | std::string path = "/lights/" + std::to_string(light.id) + "/state/"; |
| ... | ... | @@ -93,14 +94,15 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig |
| 93 | 94 | { |
| 94 | 95 | return false; |
| 95 | 96 | } |
| 96 | - std::this_thread::sleep_for(std::chrono::milliseconds(110)); | |
| 97 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_PRE_ALERT_DELAY)); | |
| 97 | 98 | if (!light.alert()) |
| 98 | 99 | { |
| 99 | 100 | return false; |
| 100 | 101 | } |
| 101 | - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); | |
| 102 | + std::this_thread::sleep_for(std::chrono::milliseconds(c_POST_ALERT_DELAY)); | |
| 102 | 103 | if (!on) |
| 103 | 104 | { |
| 105 | + light.setColorTemperature(oldCT, 1); | |
| 104 | 106 | return light.OffNoRefresh(1); |
| 105 | 107 | } |
| 106 | 108 | else |
| ... | ... | @@ -114,3 +116,8 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig |
| 114 | 116 | } |
| 115 | 117 | } |
| 116 | 118 | |
| 119 | +unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const | |
| 120 | +{ | |
| 121 | + light.refreshState(); | |
| 122 | + return light.state["state"]["ct"].asUInt(); | |
| 123 | +} | ... | ... |
hueplusplus/include/ExtendedColorHueStrategy.h
| ... | ... | @@ -26,32 +26,32 @@ |
| 26 | 26 | //! Class extending the implementation of SimpleColorHueStrategy |
| 27 | 27 | class ExtendedColorHueStrategy : public SimpleColorHueStrategy |
| 28 | 28 | { |
| 29 | - public: | |
| 30 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 31 | - //! | |
| 32 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 33 | - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 34 | - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 35 | - //! \param hue The hue of the color | |
| 36 | - //! \param sat The saturation of the color | |
| 37 | - //! \param light A reference of the light | |
| 38 | - bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const; | |
| 39 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 40 | - //! | |
| 41 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 42 | - //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 43 | - //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 44 | - //! \param light A reference of the light | |
| 45 | - bool alertXY(float x, float y, HueLight& light) const; | |
| 46 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 47 | - //! | |
| 48 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 49 | - //! Red, green and blue are ranging from 0 to 255. | |
| 50 | - //! \param r The red portion of the color | |
| 51 | - //! \param g The green portion of the color | |
| 52 | - //! \param b The blue portion of the color | |
| 53 | - //! \param light A reference of the light | |
| 54 | - bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const; | |
| 29 | +public: | |
| 30 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 31 | + //! | |
| 32 | + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 33 | + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 34 | + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 35 | + //! \param hue The hue of the color | |
| 36 | + //! \param sat The saturation of the color | |
| 37 | + //! \param light A reference of the light | |
| 38 | + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override; | |
| 39 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 40 | + //! | |
| 41 | + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 42 | + //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 43 | + //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 44 | + //! \param light A reference of the light | |
| 45 | + bool alertXY(float x, float y, HueLight& light) const override; | |
| 46 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 47 | + //! | |
| 48 | + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 49 | + //! Red, green and blue are ranging from 0 to 255. | |
| 50 | + //! \param r The red portion of the color | |
| 51 | + //! \param g The green portion of the color | |
| 52 | + //! \param b The blue portion of the color | |
| 53 | + //! \param light A reference of the light | |
| 54 | + bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override; | |
| 55 | 55 | }; |
| 56 | 56 | |
| 57 | 57 | #endif | ... | ... |
hueplusplus/include/ExtendedColorTemperatureStrategy.h
| ... | ... | @@ -20,27 +20,27 @@ |
| 20 | 20 | #ifndef _EXTENDED_COLOR_TEMPERATURE_STRATEGY_H |
| 21 | 21 | #define _EXTENDED_COLOR_TEMPERATURE_STRATEGY_H |
| 22 | 22 | |
| 23 | -#include "ColorTemperatureStrategy.h" | |
| 23 | +#include "SimpleColorTemperatureStrategy.h" | |
| 24 | 24 | #include "HueLight.h" |
| 25 | 25 | |
| 26 | 26 | //! Class implementing the functions of ColorTemperatureStrategy |
| 27 | -class ExtendedColorTemperatureStrategy : public ColorTemperatureStrategy | |
| 27 | +class ExtendedColorTemperatureStrategy : public SimpleColorTemperatureStrategy | |
| 28 | 28 | { |
| 29 | - public: | |
| 30 | - //! \brief Function for changing a lights color temperature in mired with a specified transition. | |
| 31 | - //! | |
| 32 | - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 33 | - //! \param mired The color temperature in mired | |
| 34 | - //! \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 | |
| 35 | - //! \param light A reference of the light | |
| 36 | - bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const; | |
| 37 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 38 | - //! | |
| 39 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | - bool alertTemperature(unsigned int mired, HueLight& light) const; | |
| 29 | +public: | |
| 30 | + //! \brief Function for changing a lights color temperature in mired with a specified transition. | |
| 31 | + //! | |
| 32 | + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 33 | + //! \param mired The color temperature in mired | |
| 34 | + //! \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 | |
| 35 | + //! \param light A reference of the light | |
| 36 | + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override; | |
| 37 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 38 | + //! | |
| 39 | + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | + bool alertTemperature(unsigned int mired, HueLight& light) const override; | |
| 44 | 44 | }; |
| 45 | 45 | |
| 46 | 46 | #endif | ... | ... |
hueplusplus/include/HueConfig.h
0 → 100755
| 1 | +/** | |
| 2 | + \file HueConfig.h | |
| 3 | + Copyright Notice\n | |
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | |
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | |
| 6 | + | |
| 7 | + This program is free software; you can redistribute it and/or modify | |
| 8 | + it under the terms of the GNU General Public License as published by | |
| 9 | + the Free Software Foundation; either version 3 of the License, or | |
| 10 | + (at your option) any later version. | |
| 11 | + This program is distributed in the hope that it will be useful, | |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + GNU General Public License for more details. | |
| 15 | + You should have received a copy of the GNU General Public License | |
| 16 | + along with this program; if not, write to the Free Software Foundation, | |
| 17 | + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | +**/ | |
| 19 | + | |
| 20 | +#ifndef _HUE_CONFIG_H | |
| 21 | +#define _HUE_CONFIG_H | |
| 22 | + | |
| 23 | +const uint16_t c_PRE_ALERT_DELAY = 120; //!< Delay for advanced alerts before the actual alert | |
| 24 | +const uint16_t c_POST_ALERT_DELAY = 1600; //!< Delay for advanced alerts after the actual alert | |
| 25 | + | |
| 26 | +#endif | ... | ... |
hueplusplus/include/SimpleBrightnessStrategy.h
| ... | ... | @@ -26,13 +26,18 @@ |
| 26 | 26 | //! Class implementing the functions of BrightnessStrategy |
| 27 | 27 | class SimpleBrightnessStrategy : public BrightnessStrategy |
| 28 | 28 | { |
| 29 | - public: | |
| 30 | - //! \brief Function for changing a lights brightness with a specified transition. | |
| 31 | - //! | |
| 32 | - //! \param bri The brightness raning from 0 = off to 255 = fully lit | |
| 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 | |
| 35 | - bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const; | |
| 29 | +public: | |
| 30 | + //! \brief Function for changing a lights brightness with a specified transition. | |
| 31 | + //! | |
| 32 | + //! \param bri The brightness raning from 0 = off to 255 = fully lit | |
| 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 | |
| 35 | + bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const override; | |
| 36 | + //! \brief Function that returns the current brightnessof the light | |
| 37 | + //! | |
| 38 | + //! \param light A reference of the light | |
| 39 | + //! \return Unsigned int representing the brightness | |
| 40 | + unsigned int getBrightness(HueLight& light) const override; | |
| 36 | 41 | }; |
| 37 | 42 | |
| 38 | 43 | #endif | ... | ... |
hueplusplus/include/SimpleColorHueStrategy.h
| ... | ... | @@ -26,82 +26,92 @@ |
| 26 | 26 | //! Class implementing the functions of ColorHueStrategy |
| 27 | 27 | class SimpleColorHueStrategy : public ColorHueStrategy |
| 28 | 28 | { |
| 29 | - public: | |
| 30 | - //! \brief Function for changing a lights color in hue with a specified transition. | |
| 31 | - //! | |
| 32 | - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 33 | - //! \param hue The hue of the color | |
| 34 | - //! \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 | |
| 35 | - //! \param light A reference of the light | |
| 36 | - bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const; | |
| 37 | - //! \brief Virtual function for changing a lights color in saturation with a specified transition. | |
| 38 | - //! | |
| 39 | - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 40 | - //! \param sat The saturation of the color | |
| 41 | - //! \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 | |
| 42 | - //! \param light A reference of the light | |
| 43 | - bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const; | |
| 44 | - //! \brief Virtual function for changing a lights color in hue and saturation format with a specified transition. | |
| 45 | - //! | |
| 46 | - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 47 | - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 48 | - //! \param hue The hue of the color | |
| 49 | - //! \param sat The saturation of the color | |
| 50 | - //! \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 | |
| 51 | - //! \param light A reference of the light | |
| 52 | - bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const; | |
| 53 | - //! \brief Virtual function for changing a lights color in CIE format with a specified transition. | |
| 54 | - //! | |
| 55 | - //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 56 | - //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 57 | - //! \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 | |
| 58 | - //! \param light A reference of the light | |
| 59 | - bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const; | |
| 60 | - //! \brief Virtual function for changing a lights color in rgb format with a specified transition. | |
| 61 | - //! | |
| 62 | - //! Red, green and blue are ranging from 0 to 255. | |
| 63 | - //! \param r The red portion of the color | |
| 64 | - //! \param g The green portion of the color | |
| 65 | - //! \param b The blue portion of the color | |
| 66 | - //! \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 | |
| 67 | - //! \param light A reference of the light | |
| 68 | - bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const; | |
| 69 | - //! \brief Virtual function for turning on/off the color loop feature of a light. | |
| 70 | - //! | |
| 71 | - //! Can be theoretically set for any light, but it only works for lights that support this feature. | |
| 72 | - //! When this feature is activated the light will fade through every color on the current hue and saturation settings. | |
| 73 | - //! Notice that none of the setter functions check whether this feature is enabled and | |
| 74 | - //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh() | |
| 75 | - //! and then On()/OnNoRefresh(), so you could alternatively call Off() and | |
| 76 | - //! then use any of the setter functions. | |
| 77 | - //! \param on Boolean to turn this feature on or off, true/1 for on and false/0 for off | |
| 78 | - //! \param light A reference of the light | |
| 79 | - bool setColorLoop(bool on, HueLight& light) const; | |
| 80 | - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 81 | - //! | |
| 82 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | - bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const; | |
| 89 | - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 90 | - //! | |
| 91 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | - bool alertXY(float x, float y, HueLight& light) const; | |
| 96 | - //! \brief Virtual function that lets the light perform one breath cycle in the specified color. | |
| 97 | - //! | |
| 98 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 99 | - //! Red, green and blue are ranging from 0 to 255. | |
| 100 | - //! \param r The red portion of the color | |
| 101 | - //! \param g The green portion of the color | |
| 102 | - //! \param b The blue portion of the color | |
| 103 | - //! \param light A reference of the light | |
| 104 | - bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const; | |
| 29 | +public: | |
| 30 | + //! \brief Function for changing a lights color in hue with a specified transition. | |
| 31 | + //! | |
| 32 | + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 33 | + //! \param hue The hue of the color | |
| 34 | + //! \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 | |
| 35 | + //! \param light A reference of the light | |
| 36 | + bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const override; | |
| 37 | + //! \brief Function for changing a lights color in saturation with a specified transition. | |
| 38 | + //! | |
| 39 | + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 40 | + //! \param sat The saturation of the color | |
| 41 | + //! \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 | |
| 42 | + //! \param light A reference of the light | |
| 43 | + bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const override; | |
| 44 | + //! \brief Function for changing a lights color in hue and saturation format with a specified transition. | |
| 45 | + //! | |
| 46 | + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue. | |
| 47 | + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated (vibrant). | |
| 48 | + //! \param hue The hue of the color | |
| 49 | + //! \param sat The saturation of the color | |
| 50 | + //! \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 | |
| 51 | + //! \param light A reference of the light | |
| 52 | + bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const override; | |
| 53 | + //! \brief Function for changing a lights color in CIE format with a specified transition. | |
| 54 | + //! | |
| 55 | + //! \param x The x coordinate in CIE, ranging from 0 to 1 | |
| 56 | + //! \param y The y coordinate in CIE, ranging from 0 to 1 | |
| 57 | + //! \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 | |
| 58 | + //! \param light A reference of the light | |
| 59 | + bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const override; | |
| 60 | + //! \brief Function for changing a lights color in rgb format with a specified transition. | |
| 61 | + //! | |
| 62 | + //! Red, green and blue are ranging from 0 to 255. | |
| 63 | + //! \param r The red portion of the color | |
| 64 | + //! \param g The green portion of the color | |
| 65 | + //! \param b The blue portion of the color | |
| 66 | + //! \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 | |
| 67 | + //! \param light A reference of the light | |
| 68 | + bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const override; | |
| 69 | + //! \brief Function for turning on/off the color loop feature of a light. | |
| 70 | + //! | |
| 71 | + //! Can be theoretically set for any light, but it only works for lights that support this feature. | |
| 72 | + //! When this feature is activated the light will fade through every color on the current hue and saturation settings. | |
| 73 | + //! Notice that none of the setter functions check whether this feature is enabled and | |
| 74 | + //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh() | |
| 75 | + //! and then On()/OnNoRefresh(), so you could alternatively call Off() and | |
| 76 | + //! then use any of the setter functions. | |
| 77 | + //! \param on Boolean to turn this feature on or off, true/1 for on and false/0 for off | |
| 78 | + //! \param light A reference of the light | |
| 79 | + bool setColorLoop(bool on, HueLight& light) const override; | |
| 80 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 81 | + //! | |
| 82 | + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override; | |
| 89 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 90 | + //! | |
| 91 | + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | + bool alertXY(float x, float y, HueLight& light) const override; | |
| 96 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 97 | + //! | |
| 98 | + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 99 | + //! Red, green and blue are ranging from 0 to 255. | |
| 100 | + //! \param r The red portion of the color | |
| 101 | + //! \param g The green portion of the color | |
| 102 | + //! \param b The blue portion of the color | |
| 103 | + //! \param light A reference of the light | |
| 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 | |
| 106 | + //! | |
| 107 | + //! \param light A reference of the light | |
| 108 | + //! \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 | + //! \brief Function that returns the current color of the light as xy | |
| 111 | + //! | |
| 112 | + //! \param light A reference of the light | |
| 113 | + //! \return Pair containing the x as first value and y as second value | |
| 114 | + std::pair<float, float> getColorXY(HueLight& light) const override; | |
| 105 | 115 | }; |
| 106 | 116 | |
| 107 | 117 | #endif | ... | ... |
hueplusplus/include/SimpleColorTemperatureStrategy.h
| ... | ... | @@ -26,21 +26,27 @@ |
| 26 | 26 | //! Class implementing the functions of ColorTemperatureStrategy |
| 27 | 27 | class SimpleColorTemperatureStrategy : public ColorTemperatureStrategy |
| 28 | 28 | { |
| 29 | - public: | |
| 30 | - //! \brief Function for changing a lights color temperature in mired with a specified transition. | |
| 31 | - //! | |
| 32 | - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 33 | - //! \param mired The color temperature in mired | |
| 34 | - //! \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 | |
| 35 | - //! \param light A reference of the light | |
| 36 | - bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const; | |
| 37 | - //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 38 | - //! | |
| 39 | - //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | - bool alertTemperature(unsigned int mired, HueLight& light) const; | |
| 29 | +public: | |
| 30 | + //! \brief Function for changing a lights color temperature in mired with a specified transition. | |
| 31 | + //! | |
| 32 | + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold and 500 is warm. | |
| 33 | + //! \param mired The color temperature in mired | |
| 34 | + //! \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 | |
| 35 | + //! \param light A reference of the light | |
| 36 | + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override; | |
| 37 | + //! \brief Function that lets the light perform one breath cycle in the specified color. | |
| 38 | + //! | |
| 39 | + //! It uses this_thread::sleep_for to accomodate for the time an \ref HueLight::alert() needs | |
| 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 | + bool alertTemperature(unsigned int mired, HueLight& light) const override; | |
| 44 | + //! \brief 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 | + unsigned int getColorTemperature(HueLight& light) const override; | |
| 44 | 50 | }; |
| 45 | 51 | |
| 46 | 52 | #endif | ... | ... |