Commit ba70464b53f6230d367c012ff5fd6c7c5e95d08e

Authored by Moritz Wirger
1 parent 21b6f464

Refactor HueLight with strategy pattern and remove old HueLight classes

hueplusplus/ExtendedColorHueStrategy.cpp 0 โ†’ 100755
  1 +/**
  2 + \file ExtendedColorHueStrategy.cpp
  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 +#include "include/ExtendedColorHueStrategy.h"
  21 +
  22 +#include <cmath>
  23 +#include <iostream>
  24 +#include <thread>
  25 +
  26 +bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const
  27 +{
  28 + light.refreshState();
  29 + std::string cType = light.state["state"]["colormode"].asString();
  30 + bool on = light.state["state"]["on"].asBool();
  31 + if (cType == "hs")
  32 + {
  33 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  34 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  35 + if (!light.setColorHueSaturation(hue, sat, 1))
  36 + {
  37 + return false;
  38 + }
  39 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  40 + if (!light.alert())
  41 + {
  42 + return false;
  43 + }
  44 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  45 + if (!on)
  46 + {
  47 + return light.OffNoRefresh(1);
  48 + }
  49 + else
  50 + {
  51 + return light.setColorHueSaturation(oldHue, oldSat, 1);
  52 + }
  53 + }
  54 + else if (cType == "xy")
  55 + {
  56 + float oldX = light.state["state"]["xy"][0].asFloat();
  57 + float oldY = light.state["state"]["xy"][1].asFloat();
  58 + if (!light.setColorHueSaturation(hue, sat, 1))
  59 + {
  60 + return false;
  61 + }
  62 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  63 + if (!light.alert())
  64 + {
  65 + return false;
  66 + }
  67 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  68 + if (!on)
  69 + {
  70 + return light.OffNoRefresh(1);
  71 + }
  72 + else
  73 + {
  74 + return light.setColorXY(oldX, oldY, 1);
  75 + }
  76 + }
  77 + else if (cType == "ct")
  78 + {
  79 + uint16_t oldCT = light.state["state"]["ct"].asUInt();
  80 + if (!light.setColorHueSaturation(hue, sat, 1))
  81 + {
  82 + return false;
  83 + }
  84 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  85 + if (!light.alert())
  86 + {
  87 + return false;
  88 + }
  89 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  90 + if (!on)
  91 + {
  92 + return light.OffNoRefresh(1);
  93 + }
  94 + else
  95 + {
  96 + return light.setColorTemperature(oldCT, 1);
  97 + }
  98 + }
  99 + else
  100 + {
  101 + return false;
  102 + }
  103 +}
  104 +
  105 +bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const
  106 +{
  107 + light.refreshState();
  108 + std::string cType = light.state["state"]["colormode"].asString();
  109 + bool on = light.state["state"]["on"].asBool();
  110 + if (cType == "hs")
  111 + {
  112 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  113 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  114 + if (!light.setColorXY(x, y, 1))
  115 + {
  116 + return false;
  117 + }
  118 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  119 + if (!light.alert())
  120 + {
  121 + return false;
  122 + }
  123 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  124 + if (!on)
  125 + {
  126 + return light.OffNoRefresh(1);
  127 + }
  128 + else
  129 + {
  130 + return light.setColorHueSaturation(oldHue, oldSat, 1);
  131 + }
  132 + }
  133 + else if (cType == "xy")
  134 + {
  135 + float oldX = light.state["state"]["xy"][0].asFloat();
  136 + float oldY = light.state["state"]["xy"][1].asFloat();
  137 + if (!light.setColorXY(x, y, 1))
  138 + {
  139 + return false;
  140 + }
  141 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  142 + if (!light.alert())
  143 + {
  144 + return false;
  145 + }
  146 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  147 + if (!on)
  148 + {
  149 + return light.OffNoRefresh(1);
  150 + }
  151 + else
  152 + {
  153 + return light.setColorXY(oldX, oldY, 1);
  154 + }
  155 + }
  156 + else if (cType == "ct")
  157 + {
  158 + uint16_t oldCT = light.state["state"]["ct"].asUInt();
  159 + if (!light.setColorXY(x, y, 1))
  160 + {
  161 + return false;
  162 + }
  163 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  164 + if (!light.alert())
  165 + {
  166 + return false;
  167 + }
  168 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  169 + if (!on)
  170 + {
  171 + return light.OffNoRefresh(1);
  172 + }
  173 + else
  174 + {
  175 + return light.setColorTemperature(oldCT, 1);
  176 + }
  177 + }
  178 + else
  179 + {
  180 + return false;
  181 + }
  182 +}
  183 +
  184 +bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const
  185 +{
  186 + light.refreshState();
  187 + std::string cType = light.state["state"]["colormode"].asString();
  188 + bool on = light.state["state"]["on"].asBool();
  189 + if (cType == "hs")
  190 + {
  191 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  192 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  193 + if (!light.setColorRGB(r, g, b, 1))
  194 + {
  195 + return false;
  196 + }
  197 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  198 + if (!light.alert())
  199 + {
  200 + return false;
  201 + }
  202 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  203 + if (!on)
  204 + {
  205 + return light.OffNoRefresh(1);
  206 + }
  207 + else
  208 + {
  209 + return light.setColorHueSaturation(oldHue, oldSat, 1);
  210 + }
  211 + }
  212 + else if (cType == "xy")
  213 + {
  214 + float oldX = light.state["state"]["xy"][0].asFloat();
  215 + float oldY = light.state["state"]["xy"][1].asFloat();
  216 + if (!light.setColorRGB(r, g, b, 1))
  217 + {
  218 + return false;
  219 + }
  220 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  221 + if (!light.alert())
  222 + {
  223 + return false;
  224 + }
  225 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  226 + if (!on)
  227 + {
  228 + return light.OffNoRefresh(1);
  229 + }
  230 + else
  231 + {
  232 + return light.setColorXY(oldX, oldY, 1);
  233 + }
  234 + }
  235 + else if (cType == "ct")
  236 + {
  237 + uint16_t oldCT = light.state["state"]["ct"].asUInt();
  238 + if (!light.setColorRGB(r, g, b, 1))
  239 + {
  240 + return false;
  241 + }
  242 + std::this_thread::sleep_for(std::chrono::milliseconds(110));
  243 + if (!light.alert())
  244 + {
  245 + return false;
  246 + }
  247 + std::this_thread::sleep_for(std::chrono::milliseconds(1500));
  248 + if (!on)
  249 + {
  250 + return light.OffNoRefresh(1);
  251 + }
  252 + else
  253 + {
  254 + return light.setColorTemperature(oldCT, 1);
  255 + }
  256 + }
  257 + else
  258 + {
  259 + return false;
  260 + }
  261 +}
0 262 \ No newline at end of file
... ...
hueplusplus/HueExtendedColorLight.cpp renamed to hueplusplus/ExtendedColorTemperatureStrategy.cpp 100644 โ†’ 100755
1 1 /**
2   - \file HueExtendedColorLight.cpp
  2 + \file ExtendedColorTemperatureStrategy.cpp
3 3 Copyright Notice\n
4 4 Copyright (C) 2017 Jan Rogall - developer\n
5 5 Copyright (C) 2017 Moritz Wirger - developer\n
... ... @@ -17,25 +17,26 @@
17 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 18 **/
19 19  
20   -#include "include/HueExtendedColorLight.h"
  20 +#include "include/ExtendedColorTemperatureStrategy.h"
21 21  
22 22 #include <cmath>
23 23 #include <iostream>
24 24 #include <thread>
25 25  
26   -bool HueExtendedColorLight::setColorTemperature(unsigned int mired, uint8_t transistion)
  26 +
  27 +bool ExtendedColorTemperatureStrategy::setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const
27 28 {
28   - refreshState();
  29 + light.refreshState();
29 30 Json::Value request(Json::objectValue);
30   - if (transistion != 4)
  31 + if (transition != 4)
31 32 {
32   - request["transitiontime"] = transistion;
  33 + request["transitiontime"] = transition;
33 34 }
34   - if (state["state"]["on"].asBool() != true)
  35 + if (light.state["state"]["on"].asBool() != true)
35 36 {
36 37 request["on"] = true;
37 38 }
38   - if (state["state"]["ct"].asUInt() != mired || state["state"]["colormode"].asString() != "ct")
  39 + if (light.state["state"]["ct"].asUInt() != mired || light.state["state"]["colormode"].asString() != "ct")
39 40 {
40 41 if (mired > 500)
41 42 {
... ... @@ -54,10 +55,10 @@ bool HueExtendedColorLight::setColorTemperature(unsigned int mired, uint8_t tran
54 55 return true;
55 56 }
56 57  
57   - Json::Value reply = SendPutRequest(request);
  58 + Json::Value reply = light.SendPutRequest(request);
58 59  
59 60 //Check whether request was successful
60   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  61 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
61 62 bool success = true;
62 63 int i = 0;
63 64 if (success && request.isMember("transitiontime"))
... ... @@ -80,235 +81,77 @@ bool HueExtendedColorLight::setColorTemperature(unsigned int mired, uint8_t tran
80 81 return success;
81 82 }
82 83  
83   -bool HueExtendedColorLight::alertTemperature(unsigned int mired)
84   -{
85   - refreshState();
86   - std::string cType = state["state"]["colormode"].asString();
87   - bool on = state["state"]["on"].asBool();
88   - if (cType == "hs")
89   - {
90   - uint16_t oldHue = state["state"]["hue"].asUInt();
91   - uint8_t oldSat = state["state"]["sat"].asUInt();
92   - if (!setColorTemperature(mired, 1))
93   - {
94   - return false;
95   - }
96   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
97   - if (!alert())
98   - {
99   - return false;
100   - }
101   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
102   - if (!on)
103   - {
104   - return OffNoRefresh(1);
105   - }
106   - else
107   - {
108   - return setColorHueSaturation(oldHue, oldSat, 1);
109   - }
110   - }
111   - else if (cType == "xy")
112   - {
113   - float oldX = state["state"]["xy"][0].asFloat();
114   - float oldY = state["state"]["xy"][1].asFloat();
115   - if (!setColorTemperature(mired, 1))
116   - {
117   - return false;
118   - }
119   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
120   - if (!alert())
121   - {
122   - return false;
123   - }
124   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
125   - if (!on)
126   - {
127   - return OffNoRefresh(1);
128   - }
129   - else
130   - {
131   - return setColorXY(oldX, oldY, 1);
132   - }
133   - }
134   - else if (cType == "ct")
135   - {
136   - uint16_t oldCT = state["state"]["ct"].asUInt();
137   - if (!setColorTemperature(mired, 1))
138   - {
139   - return false;
140   - }
141   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
142   - if (!alert())
143   - {
144   - return false;
145   - }
146   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
147   - if (!on)
148   - {
149   - return OffNoRefresh(1);
150   - }
151   - else
152   - {
153   - return setColorTemperature(oldCT, 1);
154   - }
155   - }
156   - else
157   - {
158   - return false;
159   - }
160   -}
161   -
162   -bool HueExtendedColorLight::alertHueSaturation(uint16_t hue, uint8_t sat)
163   -{
164   - refreshState();
165   - std::string cType = state["state"]["colormode"].asString();
166   - bool on = state["state"]["on"].asBool();
167   - if (cType == "hs")
168   - {
169   - uint16_t oldHue = state["state"]["hue"].asUInt();
170   - uint8_t oldSat = state["state"]["sat"].asUInt();
171   - if (!setColorHueSaturation(hue, sat, 1))
172   - {
173   - return false;
174   - }
175   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
176   - if (!alert())
177   - {
178   - return false;
179   - }
180   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
181   - if (!on)
182   - {
183   - return OffNoRefresh(1);
184   - }
185   - else
186   - {
187   - return setColorHueSaturation(oldHue, oldSat, 1);
188   - }
189   - }
190   - else if (cType == "xy")
191   - {
192   - float oldX = state["state"]["xy"][0].asFloat();
193   - float oldY = state["state"]["xy"][1].asFloat();
194   - if (!setColorHueSaturation(hue, sat, 1))
195   - {
196   - return false;
197   - }
198   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
199   - if (!alert())
200   - {
201   - return false;
202   - }
203   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
204   - if (!on)
205   - {
206   - return OffNoRefresh(1);
207   - }
208   - else
209   - {
210   - return setColorXY(oldX, oldY, 1);
211   - }
212   - }
213   - else if (cType == "ct")
214   - {
215   - uint16_t oldCT = state["state"]["ct"].asUInt();
216   - if (!setColorHueSaturation(hue, sat, 1))
217   - {
218   - return false;
219   - }
220   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
221   - if (!alert())
222   - {
223   - return false;
224   - }
225   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
226   - if (!on)
227   - {
228   - return OffNoRefresh(1);
229   - }
230   - else
231   - {
232   - return setColorTemperature(oldCT, 1);
233   - }
234   - }
235   - else
236   - {
237   - return false;
238   - }
239   -}
240   -
241   -bool HueExtendedColorLight::alertXY(float x, float y)
  84 +bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const
242 85 {
243   - refreshState();
244   - std::string cType = state["state"]["colormode"].asString();
245   - bool on = state["state"]["on"].asBool();
  86 + light.refreshState();
  87 + std::string cType = light.state["state"]["colormode"].asString();
  88 + bool on = light.state["state"]["on"].asBool();
246 89 if (cType == "hs")
247 90 {
248   - uint16_t oldHue = state["state"]["hue"].asUInt();
249   - uint8_t oldSat = state["state"]["sat"].asUInt();
250   - if (!setColorXY(x, y, 1))
  91 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  92 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  93 + if (!light.setColorTemperature(mired, 1))
251 94 {
252 95 return false;
253 96 }
254 97 std::this_thread::sleep_for(std::chrono::milliseconds(110));
255   - if (!alert())
  98 + if (!light.alert())
256 99 {
257 100 return false;
258 101 }
259 102 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
260 103 if (!on)
261 104 {
262   - return OffNoRefresh(1);
  105 + return light.OffNoRefresh(1);
263 106 }
264 107 else
265 108 {
266   - return setColorHueSaturation(oldHue, oldSat, 1);
  109 + return light.setColorHueSaturation(oldHue, oldSat, 1);
267 110 }
268 111 }
269 112 else if (cType == "xy")
270 113 {
271   - float oldX = state["state"]["xy"][0].asFloat();
272   - float oldY = state["state"]["xy"][1].asFloat();
273   - if (!setColorXY(x, y, 1))
  114 + float oldX = light.state["state"]["xy"][0].asFloat();
  115 + float oldY = light.state["state"]["xy"][1].asFloat();
  116 + if (!light.setColorTemperature(mired, 1))
274 117 {
275 118 return false;
276 119 }
277 120 std::this_thread::sleep_for(std::chrono::milliseconds(110));
278   - if (!alert())
  121 + if (!light.alert())
279 122 {
280 123 return false;
281 124 }
282 125 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
283 126 if (!on)
284 127 {
285   - return OffNoRefresh(1);
  128 + return light.OffNoRefresh(1);
286 129 }
287 130 else
288 131 {
289   - return setColorXY(oldX, oldY, 1);
  132 + return light.setColorXY(oldX, oldY, 1);
290 133 }
291 134 }
292 135 else if (cType == "ct")
293 136 {
294   - uint16_t oldCT = state["state"]["ct"].asUInt();
295   - if (!setColorXY(x, y, 1))
  137 + uint16_t oldCT = light.state["state"]["ct"].asUInt();
  138 + if (!light.setColorTemperature(mired, 1))
296 139 {
297 140 return false;
298 141 }
299 142 std::this_thread::sleep_for(std::chrono::milliseconds(110));
300   - if (!alert())
  143 + if (!light.alert())
301 144 {
302 145 return false;
303 146 }
304 147 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
305 148 if (!on)
306 149 {
307   - return OffNoRefresh(1);
  150 + return light.OffNoRefresh(1);
308 151 }
309 152 else
310 153 {
311   - return setColorTemperature(oldCT, 1);
  154 + return light.setColorTemperature(oldCT, 1);
312 155 }
313 156 }
314 157 else
... ... @@ -317,81 +160,3 @@ bool HueExtendedColorLight::alertXY(float x, float y)
317 160 }
318 161 }
319 162  
320   -bool HueExtendedColorLight::alertRGB(uint8_t r, uint8_t g, uint8_t b)
321   -{
322   - refreshState();
323   - std::string cType = state["state"]["colormode"].asString();
324   - bool on = state["state"]["on"].asBool();
325   - if (cType == "hs")
326   - {
327   - uint16_t oldHue = state["state"]["hue"].asUInt();
328   - uint8_t oldSat = state["state"]["sat"].asUInt();
329   - if (!setColorRGB(r, g, b, 1))
330   - {
331   - return false;
332   - }
333   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
334   - if (!alert())
335   - {
336   - return false;
337   - }
338   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
339   - if (!on)
340   - {
341   - return OffNoRefresh(1);
342   - }
343   - else
344   - {
345   - return setColorHueSaturation(oldHue, oldSat, 1);
346   - }
347   - }
348   - else if (cType == "xy")
349   - {
350   - float oldX = state["state"]["xy"][0].asFloat();
351   - float oldY = state["state"]["xy"][1].asFloat();
352   - if (!setColorRGB(r, g, b, 1))
353   - {
354   - return false;
355   - }
356   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
357   - if (!alert())
358   - {
359   - return false;
360   - }
361   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
362   - if (!on)
363   - {
364   - return OffNoRefresh(1);
365   - }
366   - else
367   - {
368   - return setColorXY(oldX, oldY, 1);
369   - }
370   - }
371   - else if (cType == "ct")
372   - {
373   - uint16_t oldCT = state["state"]["ct"].asUInt();
374   - if (!setColorRGB(r, g, b, 1))
375   - {
376   - return false;
377   - }
378   - std::this_thread::sleep_for(std::chrono::milliseconds(110));
379   - if (!alert())
380   - {
381   - return false;
382   - }
383   - std::this_thread::sleep_for(std::chrono::milliseconds(1500));
384   - if (!on)
385   - {
386   - return OffNoRefresh(1);
387   - }
388   - else
389   - {
390   - return setColorTemperature(oldCT, 1);
391   - }
392   - }
393   - else
394   - {
395   - return false;
396   - }
397   -}
... ...
hueplusplus/Hue.cpp 100644 โ†’ 100755
... ... @@ -19,10 +19,11 @@
19 19  
20 20 #include "include/Hue.h"
21 21 #include "include/HueLight.h"
22   -#include "include/HueColorLight.h"
23   -#include "include/HueDimmableLight.h"
24   -#include "include/HueExtendedColorLight.h"
25   -#include "include/HueTemperatureLight.h"
  22 +#include "include/SimpleBrightnessStrategy.h"
  23 +#include "include/SimpleColorHueStrategy.h"
  24 +#include "include/ExtendedColorHueStrategy.h"
  25 +#include "include/SimpleColorTemperatureStrategy.h"
  26 +#include "include/ExtendedColorTemperatureStrategy.h"
26 27  
27 28 #include "include/HttpHandler.h"
28 29 #include "include/UPnP.h"
... ... @@ -147,6 +148,7 @@ std::string HueFinder::RequestUsername(const std::string &amp; ip) const
147 148 {
148 149 // [{"success":{"username": "83b7780291a6ceffbe0bd049104df"}}]
149 150 std::cout << "Success! Link button was pressed!\n";
  151 + std::cout << "Username is \"" << answer[0]["success"]["username"].asString() << "\"\n";;
150 152 return answer[0]["success"]["username"].asString();
151 153 }
152 154 if (answer[0]["error"] != Json::nullValue)
... ... @@ -159,8 +161,15 @@ std::string HueFinder::RequestUsername(const std::string &amp; ip) const
159 161 }
160 162  
161 163  
162   -Hue::Hue(const std::string& ip, const std::string& username) : ip(ip), username(username)
  164 +Hue::Hue(const std::string& ip, const std::string& username) :
  165 +ip(ip),
  166 +username(username)
163 167 {
  168 + _simpleBrightnessStrategy = std::shared_ptr<BrightnessStrategy>( new SimpleBrightnessStrategy );
  169 + _simpleColorHueStrategy = std::shared_ptr<ColorHueStrategy>( new SimpleColorHueStrategy );
  170 + _extendedColorHueStrategy = std::shared_ptr<ColorHueStrategy>( new ExtendedColorHueStrategy );
  171 + _simpleColorTemperatureStrategy = std::shared_ptr<ColorTemperatureStrategy>( new SimpleColorTemperatureStrategy );
  172 + _extendedColorTemperatureStrategy = std::shared_ptr<ColorTemperatureStrategy>( new ExtendedColorTemperatureStrategy );
164 173 }
165 174  
166 175 std::string Hue::getBridgeIP()
... ... @@ -233,56 +242,137 @@ void Hue::setIP(const std::string ip)
233 242 this->ip = ip;
234 243 }
235 244  
236   -std::unique_ptr<HueLight> Hue::getLight(int id)
  245 +const HueLight& Hue::getLight(int id)
237 246 {
  247 + if(lights.count(id) > 0)
  248 + {
  249 + return lights.find(id)->second;
  250 + }
238 251 refreshState();
239 252 if (state["lights"][std::to_string(id)] == Json::nullValue)
240 253 {
241 254 std::cout << "Error in Hue getLight(): light with id " << id << " is not valid\n";
242 255 throw(std::runtime_error("Error in Hue getLight(): light id is not valid"));
243 256 }
244   - std::cout << state["lights"][std::to_string(id)] << std::endl;
  257 + //std::cout << state["lights"][std::to_string(id)] << std::endl;
245 258 std::string type = state["lights"][std::to_string(id)]["modelid"].asString();
246   - std::cout << type << std::endl;
  259 + //std::cout << type << std::endl;
247 260 if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001")
248 261 {
249 262 // HueExtendedColorLight Gamut B
250   - std::unique_ptr<HueLight> light(new HueExtendedColorLight(ip, username, id));
251   - light->colorType = ColorType::GAMUT_B;
252   - return light;
  263 + HueLight light = HueLight(ip, username, id);
  264 + light.setBrightnessStrategy(_simpleBrightnessStrategy);
  265 + light.setColorHueStrategy(_extendedColorHueStrategy);
  266 + light.setColorTemperatureStrategy(_extendedColorTemperatureStrategy);
  267 + light.colorType = ColorType::GAMUT_B;
  268 + lights.emplace(id, light);
  269 + return lights.find(id)->second;
253 270 }
254 271 else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002")
255 272 {
256 273 // HueExtendedColorLight Gamut C
257   - std::unique_ptr<HueLight> light(new HueExtendedColorLight(ip, username, id));
258   - light->colorType = ColorType::GAMUT_C;
259   - return light;
  274 + HueLight light = HueLight(ip, username, id);
  275 + light.setBrightnessStrategy(_simpleBrightnessStrategy);
  276 + light.setColorHueStrategy(_extendedColorHueStrategy);
  277 + light.setColorTemperatureStrategy(_extendedColorTemperatureStrategy);
  278 + light.colorType = ColorType::GAMUT_C;
  279 + lights.emplace(id, light);
  280 + return lights.find(id)->second;
260 281 }
261 282 else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013")
262 283 {
263 284 // HueColorLight Gamut A
264   - std::unique_ptr<HueLight> light(new HueColorLight(ip, username, id));
265   - light->colorType = ColorType::GAMUT_A;
266   - return light;
  285 + HueLight light = HueLight(ip, username, id);
  286 + light.setBrightnessStrategy(_simpleBrightnessStrategy);
  287 + light.setColorHueStrategy(_simpleColorHueStrategy);
  288 + light.setColorTemperatureStrategy(_simpleColorTemperatureStrategy);
  289 + light.colorType = ColorType::GAMUT_A;
  290 + lights.emplace(id, light);
  291 + return lights.find(id)->second;
267 292 }
268 293 else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014")
269 294 {
270 295 // HueDimmableLight No Color Type
271   - std::unique_ptr<HueLight> light(new HueDimmableLight(ip, username, id));
272   - light->colorType = ColorType::NONE;
273   - return light;
  296 + HueLight light = HueLight(ip, username, id);
  297 + light.setBrightnessStrategy(_simpleBrightnessStrategy);
  298 + //light.setColorHueStrategy();
  299 + //light.setColorTemperatureStrategy();
  300 + light.colorType = ColorType::NONE;
  301 + lights.emplace(id, light);
  302 + return lights.find(id)->second;
274 303 }
275 304 else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014")
276 305 {
277 306 // HueTemperatureLight
278   - std::unique_ptr<HueLight> light(new HueTemperatureLight(ip, username, id));
279   - light->colorType = ColorType::TEMPERATURE;
280   - return light;
  307 + HueLight light = HueLight(ip, username, id);
  308 + light.setBrightnessStrategy(_simpleBrightnessStrategy);
  309 + //light.setColorHueStrategy();
  310 + light.setColorTemperatureStrategy(_simpleColorTemperatureStrategy);
  311 + light.colorType = ColorType::TEMPERATURE;
  312 + lights.emplace(id, light);
  313 + return lights.find(id)->second;
281 314 }
282 315 std::cout << "Could not determine HueLight type!\n";
283 316 throw(std::runtime_error("Could not determine HueLight type!"));
284 317 }
285 318  
  319 +/*const std::map<uint8_t, ColorType>& Hue::getAllLightTypes()
  320 +{
  321 + refreshState();
  322 + for (const auto& name : state["lights"].getMemberNames())
  323 + {
  324 + std::string type = state["lights"][name]["modelid"].asString();
  325 + int id = std::stoi(name);
  326 +
  327 + if (type == "LCT001" || type == "LCT002" || type == "LCT003" || type == "LCT007" || type == "LLM001")
  328 + {
  329 + // HueExtendedColorLight Gamut B
  330 + lights[id].second = ColorType::GAMUT_B;
  331 + }
  332 + else if (type == "LCT010" || type == "LCT011" || type == "LCT014" || type == "LLC020" || type == "LST002")
  333 + {
  334 + // HueExtendedColorLight Gamut C
  335 + lights[id].second = ColorType::GAMUT_C;
  336 + }
  337 + else if (type == "LST001" || type == "LLC006" || type == "LLC007" || type == "LLC010" || type == "LLC011" || type == "LLC012" || type == "LLC013")
  338 + {
  339 + // HueColorLight Gamut A
  340 + lights[id].second = ColorType::GAMUT_A;
  341 + }
  342 + else if (type == "LWB004" || type == "LWB006" || type == "LWB007" || type == "LWB010" || type == "LWB014")
  343 + {
  344 + // HueDimmableLight No Color Type
  345 + lights[id].second = ColorType::NONE;
  346 + }
  347 + else if (type == "LLM010" || type == "LLM011" || type == "LLM012" || type == "LTW001" || type == "LTW004" || type == "LTW013" || type == "LTW014")
  348 + {
  349 + // HueTemperatureLight
  350 + lights[id].second = ColorType::TEMPERATURE;
  351 + }
  352 + }
  353 + return lights;
  354 +}*/
  355 +
  356 +
  357 +std::vector<std::reference_wrapper<const HueLight>> Hue::getAllLights()
  358 +{
  359 + refreshState();
  360 + for (const auto& name : state["lights"].getMemberNames())
  361 + {
  362 + uint8_t id = std::stoi(name);
  363 + if(lights.count(id)<=0)
  364 + {
  365 + getLight(id);
  366 + }
  367 + }
  368 + std::vector<std::reference_wrapper<const HueLight>> result;
  369 + for (const auto& entry : lights)
  370 + {
  371 + result.emplace_back(entry.second);
  372 + }
  373 + return result;
  374 +}
  375 +
286 376 void Hue::refreshState()
287 377 {
288 378 if (username.empty())
... ... @@ -301,13 +391,13 @@ void Hue::refreshState()
301 391  
302 392 Json::Value answer;
303 393 std::string postAnswer = HttpHandler().sendRequestGetBody(get.c_str(), ip, 80);
304   - std::cout <<"\""<< postAnswer << "\"\n" << std::endl;
  394 + //std::cout <<"\""<< postAnswer << "\"\n" << std::endl;
305 395 if (!reader->parse(postAnswer.c_str(), postAnswer.c_str() + postAnswer.length(), &answer, &error))
306 396 {
307 397 std::cout << "Error while parsing JSON in refreshState of Hue: " << error << std::endl;
308 398 throw(std::runtime_error("Error while parsing JSON in refreshState of Hue"));
309 399 }
310   - if (answer["lights"] != Json::nullValue)
  400 + if (answer.isMember("lights"))
311 401 {
312 402 state = answer;
313 403 }
... ...
hueplusplus/HueLight.cpp 100644 โ†’ 100755
... ... @@ -27,35 +27,18 @@
27 27 #include <iostream>
28 28 #include <thread>
29 29  
30   -bool HueLight::On(uint8_t transistion)
  30 +bool HueLight::On(uint8_t transition)
31 31 {
32 32 std::cout << "Turning lamp with id: " << id << " on\n";
33 33 refreshState();
34   - return OnNoRefresh(transistion);
  34 + return OnNoRefresh(transition);
35 35 }
36 36  
37   -bool HueLight::Off(uint8_t transistion)
  37 +bool HueLight::Off(uint8_t transition)
38 38 {
39 39 std::cout << "Turning lamp with id: " << id << " off\n";
40 40 refreshState();
41   - return OffNoRefresh(transistion);
42   -}
43   -
44   -bool HueLight::alert()
45   -{
46   - std::cout << "alert()\n";
47   -
48   - Json::Value request;
49   - request["alert"] = "select";
50   -
51   - Json::Value reply = SendPutRequest(request);
52   -
53   - if (reply[0]["success"]["/lights/" + std::to_string(id) + "/state/alert"].asString() == "select")
54   - {
55   - return true;
56   - }
57   -
58   - return false;
  41 + return OffNoRefresh(transition);
59 42 }
60 43  
61 44 std::string HueLight::getName()
... ... @@ -74,26 +57,48 @@ unsigned int HueLight::MiredToKelvin(unsigned int mired)
74 57 return int(0.5f + (1000000 / mired));
75 58 }
76 59  
  60 +bool HueLight::alert()
  61 +{
  62 + std::cout << "alert()\n";
  63 +
  64 + Json::Value request;
  65 + request["alert"] = "select";
  66 +
  67 + Json::Value reply = SendPutRequest(request);
  68 +
  69 + if (reply[0]["success"]["/lights/" + std::to_string(id) + "/state/alert"].asString() == "select")
  70 + {
  71 + return true;
  72 + }
  73 +
  74 + return false;
  75 +}
77 76  
78   -HueLight::HueLight(const std::string& ip, const std::string& username, int id) : ip(ip), username(username), id(id)
  77 +HueLight::HueLight(const std::string& ip, const std::string& username, int id) :
  78 +ip(ip),
  79 +username(username),
  80 +id(id),
  81 +_brightnessStrategy(nullptr),
  82 +_colorTemperatureStrategy(nullptr),
  83 +_colorHueStategy(nullptr)
79 84 {
80 85 refreshState();
81 86 }
82 87  
83   -bool HueLight::OnNoRefresh(uint8_t transistion)
  88 +bool HueLight::OnNoRefresh(uint8_t transition)
84 89 {
85 90 std::cout << "\tOnNoRefresh()\n";
86 91 Json::Value request(Json::objectValue);
87   - if (transistion != 4)
  92 + if (transition != 4)
88 93 {
89   - request["transistiontime"] = transistion;
  94 + request["transitiontime"] = transition;
90 95 }
91 96 if (state["state"]["on"].asBool() != true)
92 97 {
93 98 request["on"] = true;
94 99 }
95 100  
96   - if (!request.isMember("on") && !request.isMember("transistiontime"))
  101 + if (!request.isMember("on") && !request.isMember("transitiontime"))
97 102 {
98 103 //Nothing needs to be changed
99 104 return true;
... ... @@ -105,10 +110,10 @@ bool HueLight::OnNoRefresh(uint8_t transistion)
105 110 std::string path = "/lights/" + std::to_string(id) + "/state/";
106 111 bool success = true;
107 112 int i = 0;
108   - if (success && request.isMember("transistiontime"))
  113 + if (success && request.isMember("transitiontime"))
109 114 {
110 115 //Check if success was sent and the value was changed
111   - success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transistiontime"].asUInt() == request["transistiontime"].asUInt();
  116 + success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transitiontime"].asUInt() == request["transitiontime"].asUInt();
112 117 ++i;
113 118 }
114 119 if (success && request.isMember("on"))
... ... @@ -119,20 +124,20 @@ bool HueLight::OnNoRefresh(uint8_t transistion)
119 124 return success;
120 125 }
121 126  
122   -bool HueLight::OffNoRefresh(uint8_t transistion)
  127 +bool HueLight::OffNoRefresh(uint8_t transition)
123 128 {
124 129 std::cout << "\tOffNoRefresh()\n";
125 130 Json::Value request(Json::objectValue);
126   - if (transistion != 4)
  131 + if (transition != 4)
127 132 {
128   - request["transistiontime"] = transistion;
  133 + request["transitiontime"] = transition;
129 134 }
130 135 if (state["state"]["on"].asBool() != false)
131 136 {
132 137 request["on"] = false;
133 138 }
134 139  
135   - if (!request.isMember("on") && !request.isMember("transistiontime"))
  140 + if (!request.isMember("on") && !request.isMember("transitiontime"))
136 141 {
137 142 //Nothing needs to be changed
138 143 return true;
... ... @@ -144,10 +149,10 @@ bool HueLight::OffNoRefresh(uint8_t transistion)
144 149 std::string path = "/lights/" + std::to_string(id) + "/state/";
145 150 bool success = true;
146 151 int i = 0;
147   - if (success && request.isMember("transistiontime"))
  152 + if (success && request.isMember("transitiontime"))
148 153 {
149 154 //Check if success was sent and the value was changed
150   - success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transistiontime"].asUInt() == request["transistiontime"].asUInt();
  155 + success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transitiontime"].asUInt() == request["transitiontime"].asUInt();
151 156 ++i;
152 157 }
153 158 if (success && request.isMember("on"))
... ...
hueplusplus/HueDimmableLight.cpp renamed to hueplusplus/SimpleBrightnessStrategy.cpp 100644 โ†’ 100755
1 1 /**
2   - \file HueDimmableLight.cpp
  2 + \file SimpleBrightnessStrategy.cpp
3 3 Copyright Notice\n
4 4 Copyright (C) 2017 Jan Rogall - developer\n
5 5 Copyright (C) 2017 Moritz Wirger - developer\n
6 6  
7 7 This program is free software; you can redistribute it and/or modify
8 8 it under the terms of the GNU General Public License as published by
9   - the Free SofHueDimmableLighttware Foundation; either version 3 of the License, or
  9 + the Free Software Foundation; either version 3 of the License, or
10 10 (at your option) any later version.
11 11 This program is distributed in the hope that it will be useful,
12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
... ... @@ -17,21 +17,21 @@
17 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 18 **/
19 19  
20   -#include "include/HueDimmableLight.h"
  20 +#include "include/SimpleBrightnessStrategy.h"
21 21  
22 22 #include <cmath>
23 23 #include <iostream>
24 24 #include <thread>
25 25  
26   -bool HueDimmableLight::setBrightness(unsigned int bri, uint8_t transistion)
  26 +bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const
27 27 {
28   - std::cout << "Setting lamp with id: " << id << " to brightness of " << bri << std::endl;
29   - refreshState();
  28 + std::cout << "Setting lamp with id: " << light.id << " to brightness of " << bri << std::endl;
  29 + light.refreshState();
30 30 if (bri == 0)
31 31 {
32   - if (state["state"]["on"] == true)
  32 + if (light.state["state"]["on"] == true)
33 33 {
34   - return OffNoRefresh(transistion);
  34 + return light.OffNoRefresh(transition);
35 35 }
36 36 else
37 37 {
... ... @@ -41,15 +41,15 @@ bool HueDimmableLight::setBrightness(unsigned int bri, uint8_t transistion)
41 41 else
42 42 {
43 43 Json::Value request(Json::objectValue);
44   - if (transistion != 4)
  44 + if (transition != 4)
45 45 {
46   - request["transistiontime"] = transistion;
  46 + request["transitiontime"] = transition;
47 47 }
48   - if (state["state"]["on"].asBool() != true)
  48 + if (light.state["state"]["on"].asBool() != true)
49 49 {
50 50 request["on"] = true;
51 51 }
52   - if (state["state"]["bri"].asUInt() != bri)
  52 + if (light.state["state"]["bri"].asUInt() != bri)
53 53 {
54 54 bri -= 1;
55 55 if (bri > 254)
... ... @@ -65,16 +65,16 @@ bool HueDimmableLight::setBrightness(unsigned int bri, uint8_t transistion)
65 65 return true;
66 66 }
67 67  
68   - Json::Value reply = SendPutRequest(request);
  68 + Json::Value reply = light.SendPutRequest(request);
69 69  
70 70 //Check whether request was successful
71   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  71 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
72 72 bool success = true;
73 73 int i = 0;
74   - if (success && request.isMember("transistiontime"))
  74 + if (success && request.isMember("transitiontime"))
75 75 {
76 76 //Check if success was sent and the value was changed
77   - success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transistiontime"].asUInt() == request["transistiontime"].asUInt();
  77 + success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transitiontime"].asUInt() == request["transitiontime"].asUInt();
78 78 ++i;
79 79 }
80 80 if (success && request.isMember("on"))
... ...
hueplusplus/HueColorLight.cpp renamed to hueplusplus/SimpleColorHueStrategy.cpp 100644 โ†’ 100755
1 1 /**
2   - \file HueColorLight.cpp
  2 + \file SimpleColorHueStrategy.cpp
3 3 Copyright Notice\n
4 4 Copyright (C) 2017 Jan Rogall - developer\n
5 5 Copyright (C) 2017 Moritz Wirger - developer\n
... ... @@ -17,25 +17,25 @@
17 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 18 **/
19 19  
20   -#include "include/HueColorLight.h"
  20 +#include "include/SimpleColorHueStrategy.h"
21 21  
22 22 #include <cmath>
23 23 #include <iostream>
24 24 #include <thread>
25 25  
26   -bool HueColorLight::setColorHue(uint16_t hue, uint8_t transistion)
  26 +bool SimpleColorHueStrategy::setColorHue(uint16_t hue, uint8_t transistion, HueLight& light) const
27 27 {
28   - refreshState();
  28 + light.refreshState();
29 29 Json::Value request(Json::objectValue);
30 30 if (transistion != 4)
31 31 {
32 32 request["transistiontime"] = transistion;
33 33 }
34   - if (state["state"]["on"].asBool() != true)
  34 + if (light.state["state"]["on"].asBool() != true)
35 35 {
36 36 request["on"] = true;
37 37 }
38   - if (state["state"]["hue"].asUInt() != hue || state["state"]["colormode"].asString() != "hs")
  38 + if (light.state["state"]["hue"].asUInt() != hue || light.state["state"]["colormode"].asString() != "hs")
39 39 {
40 40 hue = hue % 65535;
41 41 request["hue"] = hue;
... ... @@ -47,10 +47,10 @@ bool HueColorLight::setColorHue(uint16_t hue, uint8_t transistion)
47 47 return true;
48 48 }
49 49  
50   - Json::Value reply = SendPutRequest(request);
  50 + Json::Value reply = light.SendPutRequest(request);
51 51  
52 52 //Check whether request was successful
53   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  53 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
54 54 bool success = true;
55 55 int i = 0;
56 56 if (success && request.isMember("transistiontime"))
... ... @@ -73,19 +73,19 @@ bool HueColorLight::setColorHue(uint16_t hue, uint8_t transistion)
73 73 return success;
74 74 }
75 75  
76   -bool HueColorLight::setColorSaturation(uint8_t sat, uint8_t transistion)
  76 +bool SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_t transistion, HueLight& light) const
77 77 {
78   - refreshState();
  78 + light.refreshState();
79 79 Json::Value request(Json::objectValue);
80 80 if (transistion != 4)
81 81 {
82 82 request["transistiontime"] = transistion;
83 83 }
84   - if (state["state"]["on"].asBool() != true)
  84 + if (light.state["state"]["on"].asBool() != true)
85 85 {
86 86 request["on"] = true;
87 87 }
88   - if (state["state"]["sat"].asUInt() != sat)
  88 + if (light.state["state"]["sat"].asUInt() != sat)
89 89 {
90 90 if (sat > 254)
91 91 {
... ... @@ -100,10 +100,10 @@ bool HueColorLight::setColorSaturation(uint8_t sat, uint8_t transistion)
100 100 return true;
101 101 }
102 102  
103   - Json::Value reply = SendPutRequest(request);
  103 + Json::Value reply = light.SendPutRequest(request);
104 104  
105 105 //Check whether request was successful
106   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  106 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
107 107 bool success = true;
108 108 int i = 0;
109 109 if (success && request.isMember("transistiontime"))
... ... @@ -126,25 +126,25 @@ bool HueColorLight::setColorSaturation(uint8_t sat, uint8_t transistion)
126 126 return success;
127 127 }
128 128  
129   -bool HueColorLight::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transistion)
  129 +bool SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transistion, HueLight& light) const
130 130 {
131   - refreshState();
  131 + light.refreshState();
132 132 Json::Value request(Json::objectValue);
133 133  
134 134 if (transistion != 4)
135 135 {
136 136 request["transitiontime"] = transistion;
137 137 }
138   - if (state["state"]["on"].asBool() != true)
  138 + if (light.state["state"]["on"].asBool() != true)
139 139 {
140 140 request["on"] = true;
141 141 }
142   - if (state["state"]["hue"].asUInt() != hue || state["state"]["colormode"].asString() != "hs")
  142 + if (light.state["state"]["hue"].asUInt() != hue || light.state["state"]["colormode"].asString() != "hs")
143 143 {
144 144 hue = hue % 65535;
145 145 request["hue"] = hue;
146 146 }
147   - if (state["state"]["sat"].asUInt() != sat || state["state"]["colormode"].asString() != "hs")
  147 + if (light.state["state"]["sat"].asUInt() != sat || light.state["state"]["colormode"].asString() != "hs")
148 148 {
149 149 if (sat > 254)
150 150 {
... ... @@ -159,10 +159,10 @@ bool HueColorLight::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t tra
159 159 return true;
160 160 }
161 161  
162   - Json::Value reply = SendPutRequest(request);
  162 + Json::Value reply = light.SendPutRequest(request);
163 163  
164 164 //Check whether request was successful
165   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  165 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
166 166 bool success = true;
167 167 int i = 0;
168 168 if (success && request.isMember("transitiontime"))
... ... @@ -191,20 +191,20 @@ bool HueColorLight::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t tra
191 191 return success;
192 192 }
193 193  
194   -bool HueColorLight::setColorXY(float x, float y, uint8_t transistion)
  194 +bool SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t transistion, HueLight& light) const
195 195 {
196   - refreshState();
  196 + light.refreshState();
197 197 Json::Value request(Json::objectValue);
198 198  
199 199 if (transistion != 4)
200 200 {
201 201 request["transitiontime"] = transistion;
202 202 }
203   - if (state["state"]["on"].asBool() != true)
  203 + if (light.state["state"]["on"].asBool() != true)
204 204 {
205 205 request["on"] = true;
206 206 }
207   - if (state["state"]["xy"][0].asFloat() != x || state["state"]["xy"][1].asFloat() != y || state["state"]["colormode"].asString() != "xy")
  207 + if (light.state["state"]["xy"][0].asFloat() != x || light.state["state"]["xy"][1].asFloat() != y || light.state["state"]["colormode"].asString() != "xy")
208 208 {
209 209 request["xy"][0] = x;
210 210 request["xy"][1] = y;
... ... @@ -216,10 +216,10 @@ bool HueColorLight::setColorXY(float x, float y, uint8_t transistion)
216 216 return true;
217 217 }
218 218  
219   - Json::Value reply = SendPutRequest(request);
  219 + Json::Value reply = light.SendPutRequest(request);
220 220  
221 221 //Check whether request was successful
222   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  222 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
223 223 bool success = true;
224 224 int i = 0;
225 225 if (success && request.isMember("transitiontime"))
... ... @@ -246,7 +246,7 @@ bool HueColorLight::setColorXY(float x, float y, uint8_t transistion)
246 246 return success;
247 247 }
248 248  
249   -bool HueColorLight::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transistion)
  249 +bool SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transistion, HueLight& light) const
250 250 {
251 251 float red = r / 255;
252 252 float green = g / 255;
... ... @@ -264,21 +264,21 @@ bool HueColorLight::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transis
264 264 float x = X / (X + Y + Z);
265 265 float y = Y / (X + Y + Z);
266 266  
267   - return setColorXY(x, y, transistion);
  267 + return light.setColorXY(x, y, transistion);
268 268 }
269 269  
270   -bool HueColorLight::setColorLoop(bool on)
  270 +bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const
271 271 {
272 272 //colorloop
273   - refreshState();
  273 + light.refreshState();
274 274 Json::Value request(Json::objectValue);
275 275  
276   - if (state["state"]["on"].asBool() != true)
  276 + if (light.state["state"]["on"].asBool() != true)
277 277 {
278 278 request["on"] = true;
279 279 }
280 280 std::string effect;
281   - if ((effect = on ? "colorloop" : "none") != state["state"]["effect"].asString())
  281 + if ((effect = on ? "colorloop" : "none") != light.state["state"]["effect"].asString())
282 282 {
283 283 request["effect"] = effect;
284 284 }
... ... @@ -288,10 +288,10 @@ bool HueColorLight::setColorLoop(bool on)
288 288 return true;
289 289 }
290 290  
291   - Json::Value reply = SendPutRequest(request);
  291 + Json::Value reply = light.SendPutRequest(request);
292 292  
293 293 //Check whether request was successful
294   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  294 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
295 295 bool success = true;
296 296 int i = 0;
297 297 if (success && request.isMember("on"))
... ... @@ -308,55 +308,55 @@ bool HueColorLight::setColorLoop(bool on)
308 308 return success;
309 309 }
310 310  
311   -bool HueColorLight::alertHueSaturation(uint16_t hue, uint8_t sat)
  311 +bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const
312 312 {
313   - refreshState();
314   - std::string cType = state["state"]["colormode"].asString();
315   - bool on = state["state"]["on"].asBool();
  313 + light.refreshState();
  314 + std::string cType = light.state["state"]["colormode"].asString();
  315 + bool on = light.state["state"]["on"].asBool();
316 316 if (cType == "hs")
317 317 {
318   - uint16_t oldHue = state["state"]["hue"].asUInt();
319   - uint8_t oldSat = state["state"]["sat"].asUInt();
320   - if (!setColorHueSaturation(hue, sat, 1))
  318 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  319 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  320 + if (!light.setColorHueSaturation(hue, sat, 1))
321 321 {
322 322 return false;
323 323 }
324 324 std::this_thread::sleep_for(std::chrono::milliseconds(110));
325   - if (!alert())
  325 + if (!light.alert())
326 326 {
327 327 return false;
328 328 }
329 329 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
330 330 if (!on)
331 331 {
332   - return OffNoRefresh(1);
  332 + return light.OffNoRefresh(1);
333 333 }
334 334 else
335 335 {
336   - return setColorHueSaturation(oldHue, oldSat, 1);
  336 + return light.setColorHueSaturation(oldHue, oldSat, 1);
337 337 }
338 338 }
339 339 else if (cType == "xy")
340 340 {
341   - float oldX = state["state"]["xy"][0].asFloat();
342   - float oldY = state["state"]["xy"][1].asFloat();
343   - if (!setColorHueSaturation(hue, sat, 1))
  341 + float oldX = light.state["state"]["xy"][0].asFloat();
  342 + float oldY = light.state["state"]["xy"][1].asFloat();
  343 + if (!light.setColorHueSaturation(hue, sat, 1))
344 344 {
345 345 return false;
346 346 }
347 347 std::this_thread::sleep_for(std::chrono::milliseconds(110));
348   - if (!alert())
  348 + if (!light.alert())
349 349 {
350 350 return false;
351 351 }
352 352 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
353 353 if (!on)
354 354 {
355   - return OffNoRefresh(1);
  355 + return light.OffNoRefresh(1);
356 356 }
357 357 else
358 358 {
359   - return setColorXY(oldX, oldY, 1);
  359 + return light.setColorXY(oldX, oldY, 1);
360 360 }
361 361 }
362 362 else
... ... @@ -365,55 +365,55 @@ bool HueColorLight::alertHueSaturation(uint16_t hue, uint8_t sat)
365 365 }
366 366 }
367 367  
368   -bool HueColorLight::alertXY(float x, float y)
  368 +bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const
369 369 {
370   - refreshState();
371   - std::string cType = state["state"]["colormode"].asString();
372   - bool on = state["state"]["on"].asBool();
  370 + light.refreshState();
  371 + std::string cType = light.state["state"]["colormode"].asString();
  372 + bool on = light.state["state"]["on"].asBool();
373 373 if (cType == "hs")
374 374 {
375   - uint16_t oldHue = state["state"]["hue"].asUInt();
376   - uint8_t oldSat = state["state"]["sat"].asUInt();
377   - if (!setColorXY(x, y, 1))
  375 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  376 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  377 + if (!light.setColorXY(x, y, 1))
378 378 {
379 379 return false;
380 380 }
381 381 std::this_thread::sleep_for(std::chrono::milliseconds(110));
382   - if (!alert())
  382 + if (!light.alert())
383 383 {
384 384 return false;
385 385 }
386 386 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
387 387 if (!on)
388 388 {
389   - return OffNoRefresh(1);
  389 + return light.OffNoRefresh(1);
390 390 }
391 391 else
392 392 {
393   - return setColorHueSaturation(oldHue, oldSat, 1);
  393 + return light.setColorHueSaturation(oldHue, oldSat, 1);
394 394 }
395 395 }
396 396 else if (cType == "xy")
397 397 {
398   - float oldX = state["state"]["xy"][0].asFloat();
399   - float oldY = state["state"]["xy"][1].asFloat();
400   - if (!setColorXY(x, y, 1))
  398 + float oldX = light.state["state"]["xy"][0].asFloat();
  399 + float oldY = light.state["state"]["xy"][1].asFloat();
  400 + if (!light.setColorXY(x, y, 1))
401 401 {
402 402 return false;
403 403 }
404 404 std::this_thread::sleep_for(std::chrono::milliseconds(110));
405   - if (!alert())
  405 + if (!light.alert())
406 406 {
407 407 return false;
408 408 }
409 409 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
410 410 if (!on)
411 411 {
412   - return OffNoRefresh(1);
  412 + return light.OffNoRefresh(1);
413 413 }
414 414 else
415 415 {
416   - return setColorXY(oldX, oldY, 1);
  416 + return light.setColorXY(oldX, oldY, 1);
417 417 }
418 418 }
419 419 else
... ... @@ -422,55 +422,55 @@ bool HueColorLight::alertXY(float x, float y)
422 422 }
423 423 }
424 424  
425   -bool HueColorLight::alertRGB(uint8_t r, uint8_t g, uint8_t b)
  425 +bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const
426 426 {
427   - refreshState();
428   - std::string cType = state["state"]["colormode"].asString();
429   - bool on = state["state"]["on"].asBool();
  427 + light.refreshState();
  428 + std::string cType = light.state["state"]["colormode"].asString();
  429 + bool on = light.state["state"]["on"].asBool();
430 430 if (cType == "hs")
431 431 {
432   - uint16_t oldHue = state["state"]["hue"].asUInt();
433   - uint8_t oldSat = state["state"]["sat"].asUInt();
434   - if (!setColorRGB(r, g, b, 1))
  432 + uint16_t oldHue = light.state["state"]["hue"].asUInt();
  433 + uint8_t oldSat = light.state["state"]["sat"].asUInt();
  434 + if (!light.setColorRGB(r, g, b, 1))
435 435 {
436 436 return false;
437 437 }
438 438 std::this_thread::sleep_for(std::chrono::milliseconds(110));
439   - if (!alert())
  439 + if (!light.alert())
440 440 {
441 441 return false;
442 442 }
443 443 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
444 444 if (!on)
445 445 {
446   - return OffNoRefresh(1);
  446 + return light.OffNoRefresh(1);
447 447 }
448 448 else
449 449 {
450   - return setColorHueSaturation(oldHue, oldSat, 1);
  450 + return light.setColorHueSaturation(oldHue, oldSat, 1);
451 451 }
452 452 }
453 453 else if (cType == "xy")
454 454 {
455   - float oldX = state["state"]["xy"][0].asFloat();
456   - float oldY = state["state"]["xy"][1].asFloat();
457   - if (!setColorRGB(r, g, b, 1))
  455 + float oldX = light.state["state"]["xy"][0].asFloat();
  456 + float oldY = light.state["state"]["xy"][1].asFloat();
  457 + if (!light.setColorRGB(r, g, b, 1))
458 458 {
459 459 return false;
460 460 }
461 461 std::this_thread::sleep_for(std::chrono::milliseconds(110));
462   - if (!alert())
  462 + if (!light.alert())
463 463 {
464 464 return false;
465 465 }
466 466 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
467 467 if (!on)
468 468 {
469   - return OffNoRefresh(1);
  469 + return light.OffNoRefresh(1);
470 470 }
471 471 else
472 472 {
473   - return setColorXY(oldX, oldY, 1);
  473 + return light.setColorXY(oldX, oldY, 1);
474 474 }
475 475 }
476 476 else
... ... @@ -479,7 +479,7 @@ bool HueColorLight::alertRGB(uint8_t r, uint8_t g, uint8_t b)
479 479 }
480 480 }
481 481  
482   -/*bool HueColorLight::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2)
  482 +/*bool SimpleColorHueStrategy::pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2)
483 483 {
484 484 float A = (-y1 * x2 + y0*(-x1 + x2) + x0*(y1 - y2) + x1 * y1);
485 485 int8_t sign = A < 0 ? -1 : 1;
... ...
hueplusplus/HueTemperatureLight.cpp renamed to hueplusplus/SimpleColorTemperatureStrategy.cpp 100644 โ†’ 100755
1 1 /**
2   - \file HueTemperatureLight.cpp
  2 + \file SimpleColorTemperatureStrategy.cpp
3 3 Copyright Notice\n
4 4 Copyright (C) 2017 Jan Rogall - developer\n
5 5 Copyright (C) 2017 Moritz Wirger - developer\n
... ... @@ -17,26 +17,26 @@
17 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 18 **/
19 19  
20   -#include "include/HueTemperatureLight.h"
  20 +#include "include/SimpleColorTemperatureStrategy.h"
21 21  
22 22 #include <cmath>
23 23 #include <iostream>
24 24 #include <thread>
25 25  
26 26  
27   -bool HueTemperatureLight::setColorTemperature(unsigned int mired, uint8_t transistion)
  27 +bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const
28 28 {
29   - refreshState();
  29 + light.refreshState();
30 30 Json::Value request(Json::objectValue);
31   - if (transistion != 4)
  31 + if (transition != 4)
32 32 {
33   - request["transistiontime"] = transistion;
  33 + request["transitiontime"] = transition;
34 34 }
35   - if (state["state"]["on"].asBool() != true)
  35 + if (light.state["state"]["on"].asBool() != true)
36 36 {
37 37 request["on"] = true;
38 38 }
39   - if (state["state"]["ct"].asUInt() != mired)
  39 + if (light.state["state"]["ct"].asUInt() != mired)
40 40 {
41 41 if (mired > 500)
42 42 {
... ... @@ -55,16 +55,16 @@ bool HueTemperatureLight::setColorTemperature(unsigned int mired, uint8_t transi
55 55 return true;
56 56 }
57 57  
58   - Json::Value reply = SendPutRequest(request);
  58 + Json::Value reply = light.SendPutRequest(request);
59 59  
60 60 //Check whether request was successful
61   - std::string path = "/lights/" + std::to_string(id) + "/state/";
  61 + std::string path = "/lights/" + std::to_string(light.id) + "/state/";
62 62 bool success = true;
63 63 int i = 0;
64   - if (success && request.isMember("transistiontime"))
  64 + if (success && request.isMember("transitiontime"))
65 65 {
66 66 //Check if success was sent and the value was changed
67   - success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transistiontime"].asUInt() == request["transistiontime"].asUInt();
  67 + success = !reply[i].isNull() && reply[i].isMember("success") && reply[i]["success"][path + "transitiontime"].asUInt() == request["transitiontime"].asUInt();
68 68 ++i;
69 69 }
70 70 if (success && request.isMember("on"))
... ... @@ -81,31 +81,31 @@ bool HueTemperatureLight::setColorTemperature(unsigned int mired, uint8_t transi
81 81 return success;
82 82 }
83 83  
84   -bool HueTemperatureLight::alertTemperature(unsigned int mired)
  84 +bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const
85 85 {
86   - refreshState();
87   - std::string cType = state["state"]["colormode"].asString();
88   - bool on = state["state"]["on"].asBool();
  86 + light.refreshState();
  87 + std::string cType = light.state["state"]["colormode"].asString();
  88 + bool on = light.state["state"]["on"].asBool();
89 89 if (cType == "ct")
90 90 {
91   - uint16_t oldCT = state["state"]["ct"].asUInt();
92   - if (!setColorTemperature(mired, 1))
  91 + uint16_t oldCT = light.state["state"]["ct"].asUInt();
  92 + if (!light.setColorTemperature(mired, 1))
93 93 {
94 94 return false;
95 95 }
96 96 std::this_thread::sleep_for(std::chrono::milliseconds(110));
97   - if (!alert())
  97 + if (!light.alert())
98 98 {
99 99 return false;
100 100 }
101 101 std::this_thread::sleep_for(std::chrono::milliseconds(1500));
102 102 if (!on)
103 103 {
104   - return OffNoRefresh(1);
  104 + return light.OffNoRefresh(1);
105 105 }
106 106 else
107 107 {
108   - return setColorTemperature(oldCT, 1);
  108 + return light.setColorTemperature(oldCT, 1);
109 109 }
110 110 }
111 111 else
... ...
hueplusplus/include/BrightnessStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file BrightnessStrategy.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 _BRIGHTNESS_STRATEGY_H
  21 +#define _BRIGHTNESS_STRATEGY_H
  22 +
  23 +#include <stdint.h>
  24 +
  25 +class HueLight;
  26 +
  27 +class BrightnessStrategy
  28 +{
  29 + public:
  30 + virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0;
  31 + virtual ~BrightnessStrategy() {}
  32 +};
  33 +
  34 +#endif
0 35 \ No newline at end of file
... ...
hueplusplus/include/ColorHueStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file ColorHueStrategy.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 _COLOR_HUE_STRATEGY_H
  21 +#define _COLOR_HUE_STRATEGY_H
  22 +
  23 +#include <stdint.h>
  24 +
  25 +class HueLight;
  26 +
  27 +class ColorHueStrategy
  28 +{
  29 + public:
  30 + virtual bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const = 0;
  31 + virtual bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const = 0;
  32 + virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const = 0;
  33 + virtual bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const = 0;
  34 + virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const = 0;
  35 + virtual bool setColorLoop(bool on, HueLight& light) const = 0;
  36 + virtual bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const = 0;
  37 + virtual bool alertXY(float x, float y, HueLight& light) const = 0;
  38 + virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0;
  39 + virtual ~ColorHueStrategy() {}
  40 +};
  41 +
  42 +#endif
0 43 \ No newline at end of file
... ...
hueplusplus/include/ColorTemperatureStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file ColorTemperatureStrategy.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 _COLOR_TEMPERATURE_STRATEGY_H
  21 +#define _COLOR_TEMPERATURE_STRATEGY_H
  22 +
  23 +#include <stdint.h>
  24 +
  25 +class HueLight;
  26 +
  27 +class ColorTemperatureStrategy
  28 +{
  29 + public:
  30 + virtual bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const = 0;
  31 + virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0;
  32 + virtual ~ColorTemperatureStrategy() {}
  33 +};
  34 +
  35 +#endif
0 36 \ No newline at end of file
... ...
hueplusplus/include/ExtendedColorHueStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file ExtendedColorHueStrategy.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 _EXTENDED_COLOR_HUE_STRATEGY_H
  21 +#define _EXTENDED_COLOR_HUE_STRATEGY_H
  22 +
  23 +#include "SimpleColorHueStrategy.h"
  24 +
  25 +class ExtendedColorHueStrategy : public SimpleColorHueStrategy
  26 +{
  27 + public:
  28 + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const;
  29 + bool alertXY(float x, float y, HueLight& light) const;
  30 + bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const;
  31 +};
  32 +
  33 +#endif
0 34 \ No newline at end of file
... ...
hueplusplus/include/ExtendedColorTemperatureStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file ExtendedColorTemperatureStrategy.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 _EXTENDED_COLOR_TEMPERATURE_STRATEGY_H
  21 +#define _EXTENDED_COLOR_TEMPERATURE_STRATEGY_H
  22 +
  23 +#include "ColorTemperatureStrategy.h"
  24 +#include "HueLight.h"
  25 +
  26 +class ExtendedColorTemperatureStrategy : public ColorTemperatureStrategy
  27 +{
  28 + public:
  29 + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const;
  30 + bool alertTemperature(unsigned int mired, HueLight& light) const;
  31 +};
  32 +
  33 +#endif
0 34 \ No newline at end of file
... ...
hueplusplus/include/Hue.h 100644 โ†’ 100755
... ... @@ -21,6 +21,9 @@
21 21 #define _HUE_H
22 22  
23 23 #include "HueLight.h"
  24 +#include "BrightnessStrategy.h"
  25 +#include "ColorHueStrategy.h"
  26 +#include "ColorTemperatureStrategy.h"
24 27  
25 28 #include "json/json.h"
26 29  
... ... @@ -104,7 +107,15 @@ public:
104 107 //! Function that returns a \HueLight of specified \ref id
105 108 //! \param id Integer that specifies the ID of a Hue light
106 109 //! \return \ref HueLight that can be controlled
107   - std::unique_ptr<HueLight> getLight(int id);
  110 + const HueLight& getLight(int id);
  111 +
  112 + //! Function that returns all light types that are associated with this bridge
  113 + //! \return A map mapping light id's to light types for every light
  114 + //const std::map<uint8_t, ColorType>& getAllLightTypes();
  115 +
  116 + //! Function that returns all lights that are associated with this bridge
  117 + //! \return A vector containing pointers pointing to every HueLight
  118 + std::vector<std::reference_wrapper<const HueLight>> getAllLights();
108 119  
109 120 private:
110 121 //! Function that refreshes the local \ref state of the Hue bridge
... ... @@ -114,6 +125,13 @@ private:
114 125 std::string ip;
115 126 std::string username;
116 127 Json::Value state;
  128 + std::map< uint8_t, HueLight > lights;
  129 +
  130 + std::shared_ptr<BrightnessStrategy> _simpleBrightnessStrategy;
  131 + std::shared_ptr<ColorHueStrategy> _simpleColorHueStrategy;
  132 + std::shared_ptr<ColorHueStrategy> _extendedColorHueStrategy;
  133 + std::shared_ptr<ColorTemperatureStrategy> _simpleColorTemperatureStrategy;
  134 + std::shared_ptr<ColorTemperatureStrategy> _extendedColorTemperatureStrategy;
117 135 };
118 136  
119 137 #endif
120 138 \ No newline at end of file
... ...
hueplusplus/include/HueColorLight.h deleted
1   -#ifndef _HUE_COLOR_LIGHT
2   -#define _HUE_COLOR_LIGHT
3   -
4   -#include "HueDimmableLight.h"
5   -
6   -// xy beats ct beats hue/sat.
7   -// supports groups, scenes, on / off, dimming and color control(hue / saturation, enhanced hue, color loop and XY)
8   -class HueColorLight : public HueDimmableLight
9   -{
10   - friend class Hue;
11   -
12   -public:
13   - //! Function to set the color of this light with specified hue. Ranging from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue.
14   - //! \param hue uint16_t that specifies the hue
15   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
16   - //! \return Bool that is true on success
17   - virtual bool setColorHue(uint16_t hue, uint8_t transistion = 4);
18   -
19   - //! Function to set the saturation of color of this light with specified saturation. Ranging from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated.
20   - //! \param sat uint8_t that specifies the saturation
21   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
22   - //! \return Bool that is true on success
23   - virtual bool setColorSaturation(uint8_t sat, uint8_t transistion = 4);
24   -
25   - //! Function to set the color of this light with specified hue and saturation.
26   - //! \param hue uint16_t that specifies the hue
27   - //! \param sat uint8_t that specifies the saturation
28   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms.
29   - //! \return Bool that is true on success
30   - virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition = 4);
31   -
32   - //! Function to set the color of this light in CIE with specified x y. Where x and y are ranging from 0 to 1.
33   - //! \param x float that specifies the x coordinate in CIE
34   - //! \param y float that specifies the y coordinate in CIE
35   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
36   - //! \return Bool that is true on success
37   - virtual bool setColorXY(float x, float y, uint8_t transistion = 4);
38   -
39   - //! Function to set the color of this light with red green and blue values. Where red, green and blue are ranging from 0 to 255.
40   - //! \param r uint8_t that specifies the red color percentage
41   - //! \param g uint8_t that specifies the green color percentage
42   - //! \param b uint8_t that specifies the blue color percentage
43   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
44   - //! \return Bool that is true on success
45   - virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transistion = 4);
46   -
47   - //! Function to enable colorloop effect. The colorloop effect will loop through all colors on current hue and saturation levels.
48   - //! Notice that none of the setter functions check for this and the colorloop can only be disabled via this function.
49   - //! or by simply calling Off()/OffNoRefresh() and then On()/OnNoRefresh(),
50   - //! so you could alternatively call Off() and then use any of the setter functions
51   - //! \param on bool that enables this feature when true and disables it when false
52   - //! \return Bool that is true on success
53   - virtual bool setColorLoop(bool on);
54   -
55   - //! Function that lets the light perform one breath cycle in specified color.
56   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
57   - //! \param hue uint16_t that specifies the hue
58   - //! \param sat uint8_t that specifies the saturation
59   - //! \return Bool that is true on success
60   - bool alertHueSaturation(uint16_t hue, uint8_t sat);
61   -
62   - //! Function that lets the light perform one breath cycle in specified color.
63   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
64   - //! \param x float that specifies the x coordinate in CIE
65   - //! \param y float that specifies the y coordinate in CIE
66   - //! \return Bool that is true on success
67   - bool alertXY(float x, float y);
68   -
69   - //! Function that lets the light perform one breath cycle in specified color.
70   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
71   - //! \param r uint8_t that specifies the red color percentage
72   - //! \param g uint8_t that specifies the green color percentage
73   - //! \param b uint8_t that specifies the blue color percentage
74   - //! \return Bool that is true on success
75   - bool alertRGB(uint8_t r, uint8_t g, uint8_t b);
76   -
77   -protected:
78   - //! protected ctor that is used by \ref Hue class.
79   - //! \param ip String that specifies the ip of the Hue bridge
80   - //! \param username String that specifies the username used to control the bridge
81   - //! \param id Integer that specifies the id of this light
82   - HueColorLight(const std::string& ip, const std::string& username, int id) : HueDimmableLight(ip, username, id) {};
83   -
84   - /*private:
85   - bool pointInTriangle(float pointx, float pointy, float x0, float y0, float x1, float y1, float x2, float y2); // currently unused because Hue bridge handles this*/
86   -};
87   -#endif
hueplusplus/include/HueDimmableLight.h deleted
1   -#ifndef _HUE_DIMMABLE_LIGHT_H
2   -#define _HUE_DIMMABLE_LIGHT_H
3   -#include "HueLight.h"
4   -
5   -// supports groups, scenes, on/off and dimming
6   -class HueDimmableLight : public HueLight
7   -{
8   - friend class Hue;
9   -
10   -public:
11   - //! virtual function that sets the brightness of this light. Ranging from 0=off to 255=fully on
12   - //! \param bri Unsigned int that specifies the brightness
13   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
14   - //! \return Bool that is true on success
15   - virtual bool setBrightness(unsigned int bri, uint8_t transistion = 4);
16   -
17   -protected:
18   - //! protected ctor that is used by \ref Hue class.
19   - //! \param ip String that specifies the ip of the Hue bridge
20   - //! \param username String that specifies the username used to control the bridge
21   - //! \param id Integer that specifies the id of this light
22   - HueDimmableLight(const std::string& ip, const std::string& username, int id) : HueLight(ip, username, id) {};
23   -};
24   -#endif
hueplusplus/include/HueExtendedColorLight.h deleted
1   -#ifndef _HUE_EXTENDED_COLOR_LIGHT
2   -#define _HUE_EXTENDED_COLOR_LIGHT
3   -
4   -#include "HueColorLight.h"
5   -// supports same as Color light, but which supports additional setting of color temperature
6   -class HueExtendedColorLight : public HueColorLight
7   -{
8   - friend class Hue;
9   -
10   -public:
11   - //! Fucntion that sets the color temperature of this light in mired. Ranging from 153 to 500.
12   - //! \param mired Unsigned int that specifies the color temperature in Mired
13   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
14   - //! \return Bool that is true on success
15   - virtual bool setColorTemperature(unsigned int mired, uint8_t transistion = 4);
16   -
17   - //! Function that lets the light perform one breath cycle in specified color temperature.
18   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
19   - //! \param mired Color temperature in mired
20   - //! \return Bool that is true on success
21   - bool alertTemperature(unsigned int mired);
22   -
23   - //! Function that lets the light perform one breath cycle in specified color.
24   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
25   - //! \param hue uint16_t that specifies the hue
26   - //! \param sat uint8_t that specifies the saturation
27   - //! \return Bool that is true on success
28   - bool alertHueSaturation(uint16_t hue, uint8_t sat);
29   -
30   - //! Function that lets the light perform one breath cycle in specified color.
31   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
32   - //! \param x float that specifies the x coordinate in CIE
33   - //! \param y float that specifies the y coordinate in CIE
34   - //! \return Bool that is true on success
35   - bool alertXY(float x, float y);
36   -
37   - //! Function that lets the light perform one breath cycle in specified color.
38   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
39   - //! \param r uint8_t that specifies the red color percentage
40   - //! \param g uint8_t that specifies the green color percentage
41   - //! \param b uint8_t that specifies the blue color percentage
42   - //! \return Bool that is true on success
43   - bool alertRGB(uint8_t r, uint8_t g, uint8_t b);
44   -
45   -protected:
46   - //! protected ctor that is used by \ref Hue class.
47   - //! \param ip String that specifies the ip of the Hue bridge
48   - //! \param username String that specifies the username used to control the bridge
49   - //! \param id Integer that specifies the id of this light
50   - HueExtendedColorLight(const std::string& ip, const std::string& username, int id) : HueColorLight(ip, username, id) {};
51   -};
52   -#endif
hueplusplus/include/HueLight.h 100644 โ†’ 100755
... ... @@ -20,7 +20,12 @@
20 20 #ifndef _HUE_LIGHT_H
21 21 #define _HUE_LIGHT_H
22 22  
  23 +#include <memory>
  24 +
23 25 #include "json/json.h"
  26 +#include "BrightnessStrategy.h"
  27 +#include "ColorHueStrategy.h"
  28 +#include "ColorTemperatureStrategy.h"
24 29  
25 30 /*enum ModelType
26 31 {
... ... @@ -78,32 +83,32 @@ enum ColorType
78 83 GAMUT_C_TEMPERATURE
79 84 };
80 85  
81   -// supports groups, scenes and on/off control
82 86 class HueLight
83 87 {
84 88 friend class Hue;
  89 + friend class SimpleBrightnessStrategy;
  90 + friend class SimpleColorHueStrategy;
  91 + friend class ExtendedColorHueStrategy;
  92 + friend class SimpleColorTemperatureStrategy;
  93 + friend class ExtendedColorTemperatureStrategy;
85 94  
86 95 public:
87   - //! virtual std dtor
88   - virtual ~HueLight() = default;
89   -
90   - //! virtual function that turns the light on.
91   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
92   - //! \return Bool that is true on success
93   - virtual bool On(uint8_t transistion = 4);
  96 + //! std dtor
  97 + ~HueLight() = default;
94 98  
95   - //! virtual function that turns the light off.
96   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
  99 + //! Function that turns the light on.
  100 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
97 101 //! \return Bool that is true on success
98   - virtual bool Off(uint8_t transistion = 4);
  102 + bool On(uint8_t transition = 4);
99 103  
100   - //! Function that lets the light perform one breath cycle.
  104 + //! Function that turns the light off.
  105 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
101 106 //! \return Bool that is true on success
102   - virtual bool alert();
  107 + bool Off(uint8_t transition = 4);
103 108  
104   - //! virtual function that returns the name of the light.
  109 + //! F\unction that returns the name of the light.
105 110 //! \return String containig the name of the light
106   - virtual std::string getName();
  111 + std::string getName();
107 112  
108 113 //! Function that converts Kelvin to Mired.
109 114 //! \param kelvin Unsigned integer value in Kelvin
... ... @@ -115,6 +120,186 @@ public:
115 120 //! \return Unsigned integer value in Kelvin
116 121 unsigned int MiredToKelvin(unsigned int mired);
117 122  
  123 + //! Function that sets the brightness of this light if the
  124 + //! light has a reference to a specific \ref BrightnessStrategy.
  125 + //! The brightness can range from 0=off to 255=fully on.
  126 + //! \param bri Unsigned int that specifies the brightness
  127 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  128 + //! \return Bool that is true on success
  129 + bool setBrightness(unsigned int bri, uint8_t transition = 4)
  130 + {
  131 + if (_brightnessStrategy)
  132 + {
  133 + return (*_brightnessStrategy).setBrightness(bri, transition, *this);
  134 + }
  135 + };
  136 +
  137 + //! Fucntion that sets the color temperature of this light in mired if the
  138 + //! light has a reference to a specific \ref ColorTemperatureStrategy.
  139 + //! The color temperature can range from 153 to 500.
  140 + //! \param mired Unsigned int that specifies the color temperature in Mired
  141 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  142 + //! \return Bool that is true on success
  143 + bool setColorTemperature(unsigned int mired, uint8_t transition = 4)
  144 + {
  145 + if (_colorTemperatureStrategy)
  146 + {
  147 + return (*_colorTemperatureStrategy).setColorTemperature(mired, transition, *this);
  148 + }
  149 + };
  150 +
  151 + //! Function to set the color of this light with specified hue if the
  152 + //! light has a reference to a specific \ref ColorHueStrategy.
  153 + //! The hue can range from 0 to 65535, whereas 65535 and 0 are red, 25500 is green and 46920 is blue.
  154 + //! \param hue uint16_t that specifies the hue
  155 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  156 + //! \return Bool that is true on success
  157 + bool setColorHue(uint16_t hue, uint8_t transition = 4)
  158 + {
  159 + if(_colorHueStategy)
  160 + {
  161 + return (*_colorHueStategy).setColorHue(hue, transition, *this);
  162 + }
  163 + };
  164 +
  165 + //! Function to set the saturation of color of this light with specified saturation if the
  166 + //! light has a reference to a specific \ref ColorHueStrategy.
  167 + //! The saturation can range from 0 to 254, whereas 0 is least saturated (white) and 254 is most saturated.
  168 + //! \param sat uint8_t that specifies the saturation
  169 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  170 + //! \return Bool that is true on success
  171 + bool setColorSaturation(uint8_t sat, uint8_t transition = 4)
  172 + {
  173 + if(_colorHueStategy)
  174 + {
  175 + return (*_colorHueStategy).setColorSaturation(sat, transition, *this);
  176 + }
  177 + };
  178 +
  179 + //! Function to set the color of this light with specified hue and saturation if the
  180 + //! light has a reference to a specific \ref ColorHueStrategy.
  181 + //! \param hue uint16_t that specifies the hue
  182 + //! \param sat uint8_t that specifies the saturation
  183 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms.
  184 + //! \return Bool that is true on success
  185 + bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition = 4)
  186 + {
  187 + if(_colorHueStategy)
  188 + {
  189 + return (*_colorHueStategy).setColorHueSaturation(hue, sat, transition, *this);
  190 + }
  191 + };
  192 +
  193 + //! Function to set the color of this light in CIE with specified x y if the
  194 + //! light has a reference to a specific \ref ColorHueStrategy.
  195 + //! The values of x and y are ranging from 0 to 1.
  196 + //! \param x float that specifies the x coordinate in CIE
  197 + //! \param y float that specifies the y coordinate in CIE
  198 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  199 + //! \return Bool that is true on success
  200 + bool setColorXY(float x, float y, uint8_t transition = 4)
  201 + {
  202 + if(_colorHueStategy)
  203 + {
  204 + return (*_colorHueStategy).setColorXY(x, y, transition, *this);
  205 + }
  206 + };
  207 +
  208 + //! Function to set the color of this light with red green and blue values if the
  209 + //! light has a reference to a specific \ref ColorHueStrategy.
  210 + //! The values of red, green and blue are ranging from 0 to 255.
  211 + //! \param r uint8_t that specifies the red color value
  212 + //! \param g uint8_t that specifies the green color value
  213 + //! \param b uint8_t that specifies the blue color value
  214 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  215 + //! \return Bool that is true on success
  216 + bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition = 4)
  217 + {
  218 + if(_colorHueStategy)
  219 + {
  220 + return (*_colorHueStategy).setColorRGB(r, g, b, transition, *this);
  221 + }
  222 + };
  223 +
  224 + //! Function that lets the light perform one breath cycle.
  225 + //! \return bool that is true on success
  226 + virtual bool alert();
  227 +
  228 + //! Function that lets the light perform one breath cycle in specified color temperature
  229 + //! if the light has a reference to a specific \ref ColorTemperatureStrategy.
  230 + //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs.
  231 + //! \param mired Color temperature in mired
  232 + //! \return Bool that is true on success
  233 + bool alertTemperature(unsigned int mired)
  234 + {
  235 + if(_colorTemperatureStrategy)
  236 + {
  237 + return (*_colorTemperatureStrategy).alertTemperature(mired, *this);
  238 + }
  239 + };
  240 +
  241 + //! Function that lets the light perform one breath cycle in specified color if the
  242 + //! light has a reference to a specific \ref ColorHueStrategy.
  243 + //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
  244 + //! \param hue uint16_t that specifies the hue
  245 + //! \param sat uint8_t that specifies the saturation
  246 + //! \return Bool that is true on success
  247 + bool alertHueSaturation(uint16_t hue, uint8_t sat)
  248 + {
  249 + if(_colorHueStategy)
  250 + {
  251 + return (*_colorHueStategy).alertHueSaturation(hue, sat, *this);
  252 + }
  253 + };
  254 +
  255 + //! Function that lets the light perform one breath cycle in specified color if the
  256 + //! light has a reference to a specific \ref ColorHueStrategy.
  257 + //! The values of x and y are ranging from 0 to 1.
  258 + //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
  259 + //! \param x float that specifies the x coordinate in CIE
  260 + //! \param y float that specifies the y coordinate in CIE
  261 + //! \return Bool that is true on success
  262 + bool alertXY(float x, float y)
  263 + {
  264 + if(_colorHueStategy)
  265 + {
  266 + return (*_colorHueStategy).alertXY(x, y, *this);
  267 + }
  268 + };
  269 +
  270 + //! Function that lets the light perform one breath cycle in specified color if the
  271 + //! light has a reference to a specific \ref ColorHueStrategy.
  272 + //! The values of red, green and blue are ranging from 0 to 255.
  273 + //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
  274 + //! \param r uint8_t that specifies the red color value
  275 + //! \param g uint8_t that specifies the green color value
  276 + //! \param b uint8_t that specifies the blue color value
  277 + //! \return Bool that is true on success
  278 + bool alertRGB(uint8_t r, uint8_t g, uint8_t b)
  279 + {
  280 + if(_colorHueStategy)
  281 + {
  282 + return (*_colorHueStategy).alertRGB(r, g, b, *this);
  283 + }
  284 + };
  285 +
  286 + //! Function to enable colorloop effect if the
  287 + //! light has a reference to a specific \ref ColorHueStrategy.
  288 + //! The colorloop effect will loop through all colors on current hue and saturation levels.
  289 + //! Notice that none of the setter functions check whether this feature is enabled and
  290 + //! the colorloop can only be disabled with this function or by simply calling Off()/OffNoRefresh()
  291 + //! and then On()/OnNoRefresh(), so you could alternatively call Off() and
  292 + //! then use any of the setter functions.
  293 + //! \param on bool that enables this feature when true and disables it when false
  294 + //! \return Bool that is true on success
  295 + bool setColorLoop(bool on)
  296 + {
  297 + if(_colorHueStategy)
  298 + {
  299 + return (*_colorHueStategy).setColorLoop(on, *this);
  300 + }
  301 + };
  302 +
118 303 protected:
119 304 //! protected ctor that is used by \ref Hue class.
120 305 //! \param ip String that specifies the ip of the Hue bridge
... ... @@ -122,15 +307,30 @@ protected:
122 307 //! \param id Integer that specifies the id of this light
123 308 HueLight(const std::string& ip, const std::string& username, int id);
124 309  
125   - //! virtual function that turns the light on without refreshing its state.
126   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
  310 + //! protected function that sets the brightness strategy which defines how
  311 + //! specific commands that deal with brightness control are executed
  312 + //! \param strat a strategy of type \ref BrightnessStrategy
  313 + void setBrightnessStrategy(std::shared_ptr<BrightnessStrategy> strat) { _brightnessStrategy = strat; };
  314 +
  315 + //! protected function that sets the colorTemperature strategy which defines how
  316 + //! specific commands that deal with colortemperature control are executed
  317 + //! \param strat a strategy of type \ref ColorTemperatureStrategy
  318 + void setColorTemperatureStrategy(std::shared_ptr<ColorTemperatureStrategy> strat) { _colorTemperatureStrategy = strat; };
  319 +
  320 + //! protected function that sets the colorHue strategy which defines how
  321 + //! specific commands that deal with color control are executed
  322 + //! \param strat a strategy of type \ref ColorHueStrategy
  323 + void setColorHueStrategy(std::shared_ptr<ColorHueStrategy> strat) { _colorHueStategy = strat; };
  324 +
  325 + //! Function that turns the light on without refreshing its state.
  326 + //! \param transition Optional parameter to set the transition from current state to new standard is 4 = 400ms
127 327 //! \return Bool that is true on success
128   - virtual bool OnNoRefresh(uint8_t transistion = 4);
  328 + bool OnNoRefresh(uint8_t transition = 4);
129 329  
130   - //! virtual function that turns the light off without refreshing its state.
131   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
  330 + //! Function that turns the light off without refreshing its state.
  331 + //! \param transition Optional parameter to set the transition from current state to new standard is 4 = 400ms
132 332 //! \return Bool that is true on success
133   - virtual bool OffNoRefresh(uint8_t transistion = 4);
  333 + bool OffNoRefresh(uint8_t transition = 4);
134 334  
135 335 //! utility function to send a put request to the light.
136 336 //! \throws std::runtime_error if the reply could not be parsed
... ... @@ -146,12 +346,10 @@ protected:
146 346 int id; //!< holds the id of the light
147 347 Json::Value state; //!< holds the current state of the light updated by \ref refreshState
148 348 ColorType colorType; //!< holds the \ref ColorType of the light
149   -};
150   -
151   -
152   -
153   -
154   -
155 349  
  350 + std::shared_ptr<BrightnessStrategy> _brightnessStrategy; //!< holds a reference to the strategy that handles brighntess commands
  351 + std::shared_ptr<ColorTemperatureStrategy> _colorTemperatureStrategy; //!< holds a reference to the strategy that handles colortemperature commands
  352 + std::shared_ptr<ColorHueStrategy> _colorHueStategy; //!< holds a reference to the strategy that handles all color commands
  353 +};
156 354  
157 355 -#endif
  356 +#endif
158 357 \ No newline at end of file
... ...
hueplusplus/include/HueTemperatureLight.h deleted
1   -#ifndef _HUE_TEMPAERATURE_LIGHT
2   -#define _HUE_TEMPAERATURE_LIGHT
3   -
4   -#include "HueDimmableLight.h"
5   -
6   -// supports groups, scenes, on/off, dimming, and setting of color temperature
7   -class HueTemperatureLight : public HueDimmableLight
8   -{
9   - friend class Hue;
10   -
11   -public:
12   - //! Fucntion that sets the color temperature of this light in mired. Ranging from 153 to 500
13   - //! \param mired Unsigned int that specifies the color temperature in Mired
14   - //! \param transistion Optional parameter to set the transition from current state to new standard is 4 = 400ms
15   - //! \return Bool that is true on success
16   - virtual bool setColorTemperature(unsigned int mired, uint8_t transistion = 4);
17   -
18   - //! Function that lets the light perform one breath cycle in specified color temperature.
19   - //! It uses this_thread::sleep_for to accomodate for the time an \ref alert() needs
20   - //! \param mired Color temperature in mired
21   - //! \return Bool that is true on success
22   - bool alertTemperature(unsigned int mired);
23   -
24   -protected:
25   - //! protected ctor that is used by \ref Hue class.
26   - //! \param ip String that specifies the ip of the Hue bridge
27   - //! \param username String that specifies the username used to control the bridge
28   - //! \param id Integer that specifies the id of this light
29   - HueTemperatureLight(const std::string& ip, const std::string& username, int id) : HueDimmableLight(ip, username, id) {};
30   -};
31   -#endif
hueplusplus/include/SimpleBrightnessStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file SimpleBrightnessStrategy.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 _SIMPLE_BRIGHTNESS_STRATEGY_H
  21 +#define _SIMPLE_BRIGHTNESS_STRATEGY_H
  22 +
  23 +#include "BrightnessStrategy.h"
  24 +#include "HueLight.h"
  25 +
  26 +class SimpleBrightnessStrategy : public BrightnessStrategy
  27 +{
  28 + public:
  29 + bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const;
  30 +};
  31 +
  32 +#endif
0 33 \ No newline at end of file
... ...
hueplusplus/include/SimpleColorHueStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file SimpleColorHueStrategy.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 _SIMPLE_COLOR_HUE_STRATEGY_H
  21 +#define _SIMPLE_COLOR_HUE_STRATEGY_H
  22 +
  23 +#include "HueLight.h"
  24 +
  25 +class SimpleColorHueStrategy : public ColorHueStrategy
  26 +{
  27 + public:
  28 + bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const;
  29 + bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const;
  30 + bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const;
  31 + bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const;
  32 + bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const;
  33 + bool setColorLoop(bool on, HueLight& light) const;
  34 + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const;
  35 + bool alertXY(float x, float y, HueLight& light) const;
  36 + bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const;
  37 +};
  38 +
  39 +#endif
0 40 \ No newline at end of file
... ...
hueplusplus/include/SimpleColorTemperatureStrategy.h 0 โ†’ 100755
  1 +/**
  2 + \file SimpleColorTemperatureStrategy.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 _SIMPLE_COLOR_TEMPERATURE_STRATEGY_H
  21 +#define _SIMPLE_COLOR_TEMPERATURE_STRATEGY_H
  22 +
  23 +#include "ColorTemperatureStrategy.h"
  24 +#include "HueLight.h"
  25 +
  26 +class SimpleColorTemperatureStrategy : public ColorTemperatureStrategy
  27 +{
  28 + public:
  29 + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const;
  30 + bool alertTemperature(unsigned int mired, HueLight& light) const;
  31 +};
  32 +
  33 +#endif
0 34 \ No newline at end of file
... ...