12
12
13
13
#include < set>
14
14
15
- const ColorPoint LedDevicePhilipsHue::BLACK = {0 .0f , 0 .0f , 0 .0f };
15
+ const ColorPoint LedDevicePhilipsHue::BLACK = { 0 .0f , 0 .0f , 0 .0f };
16
16
17
17
LedDevicePhilipsHue::LedDevicePhilipsHue (const std::string& output, bool switchOffOnBlack) :
18
18
host(output.c_str()), username(" newdeveloper" ), switchOffOnBlack(switchOffOnBlack) {
@@ -42,16 +42,16 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
42
42
// Switch lamp off if switchOffOnBlack is enabled and the lamp is currently on.
43
43
if (switchOffOnBlack && xy == BLACK && lamp.color != BLACK) {
44
44
put (getStateRoute (lamp.id ), QString (" {\" on\" : false}" ));
45
- }
45
+ }
46
46
// Write color if color has been changed.
47
47
else if (xy != lamp.color ) {
48
48
// Switch on if the lamp has been previously switched off.
49
49
if (switchOffOnBlack && lamp.color == BLACK) {
50
50
put (getStateRoute (lamp.id ), QString (" {\" on\" : true}" ));
51
51
}
52
52
// Send adjust color and brightness command in JSON format.
53
- put (getStateRoute (lamp.id ), QString ( " { \" xy \" : [%1, %2], \" bri \" : %1} " ). arg (xy. x ). arg (xy. y )
54
- .arg (qRound (xy.bri * 255 .0f )));
53
+ put (getStateRoute (lamp.id ),
54
+ QString ( " { \" xy \" : [%1, %2], \" bri \" : %1} " ). arg (xy. x ). arg (xy. y ) .arg (qRound (xy.bri * 255 .0f )));
55
55
// Remember written color.
56
56
lamp.color = xy;
57
57
}
@@ -218,10 +218,11 @@ ColorPoint LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float
218
218
if (isnan (cy)) {
219
219
cy = 0 .0f ;
220
220
}
221
- ColorPoint xy = {cx, cy};
221
+ // Brightness is simply Y in the XYZ space.
222
+ ColorPoint xy = { cx, cy, Y };
222
223
// Check if the given XY value is within the color reach of our lamps.
223
224
if (!isPointInLampsReach (lamp, xy)) {
224
- // It seems the color is out of reach let's find the closes colour we can produce with our lamp and send this XY value out.
225
+ // It seems the color is out of reach let's find the closes color we can produce with our lamp and send this XY value out.
225
226
ColorPoint pAB = getClosestPointToPoint (lamp.colorSpace .red , lamp.colorSpace .green , xy);
226
227
ColorPoint pAC = getClosestPointToPoint (lamp.colorSpace .blue , lamp.colorSpace .red , xy);
227
228
ColorPoint pBC = getClosestPointToPoint (lamp.colorSpace .green , lamp.colorSpace .blue , xy);
@@ -243,8 +244,7 @@ ColorPoint LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float
243
244
xy.x = closestPoint.x ;
244
245
xy.y = closestPoint.y ;
245
246
}
246
- // Brightness is simply Y in the XYZ space.
247
- xy.bri = Y;
247
+ return xy;
248
248
}
249
249
250
250
HueLamp::HueLamp (unsigned int id, QString originalState, QString modelId) :
0 commit comments