@@ -20,7 +20,7 @@ bool operator !=(CiColor p1, CiColor p2) {
20
20
return !(p1 == p2);
21
21
}
22
22
23
- PhilipsHueLamp::PhilipsHueLamp (unsigned int id, QString originalState, QString modelId) :
23
+ PhilipsHueLight::PhilipsHueLight (unsigned int id, QString originalState, QString modelId) :
24
24
id(id), originalState(originalState) {
25
25
// Hue system model ids.
26
26
const std::set<QString> HUE_BULBS_MODEL_IDS = { " LCT001" , " LCT002" , " LCT003" };
@@ -46,11 +46,11 @@ PhilipsHueLamp::PhilipsHueLamp(unsigned int id, QString originalState, QString m
46
46
color = {black.x , black.y , black.bri };
47
47
}
48
48
49
- float PhilipsHueLamp ::crossProduct (CiColor p1, CiColor p2) {
49
+ float PhilipsHueLight ::crossProduct (CiColor p1, CiColor p2) {
50
50
return p1.x * p2.y - p1.y * p2.x ;
51
51
}
52
52
53
- bool PhilipsHueLamp ::isPointInLampsReach (CiColor p) {
53
+ bool PhilipsHueLight ::isPointInLampsReach (CiColor p) {
54
54
CiColor v1 = { colorSpace.green .x - colorSpace.red .x , colorSpace.green .y - colorSpace.red .y };
55
55
CiColor v2 = { colorSpace.blue .x - colorSpace.red .x , colorSpace.blue .y - colorSpace.red .y };
56
56
CiColor q = { p.x - colorSpace.red .x , p.y - colorSpace.red .y };
@@ -62,7 +62,7 @@ bool PhilipsHueLamp::isPointInLampsReach(CiColor p) {
62
62
return false ;
63
63
}
64
64
65
- CiColor PhilipsHueLamp ::getClosestPointToPoint (CiColor a, CiColor b, CiColor p) {
65
+ CiColor PhilipsHueLight ::getClosestPointToPoint (CiColor a, CiColor b, CiColor p) {
66
66
CiColor AP = { p.x - a.x , p.y - a.y };
67
67
CiColor AB = { b.x - a.x , b.y - a.y };
68
68
float ab2 = AB.x * AB.x + AB.y * AB.y ;
@@ -76,7 +76,7 @@ CiColor PhilipsHueLamp::getClosestPointToPoint(CiColor a, CiColor b, CiColor p)
76
76
return {a.x + AB.x * t, a.y + AB.y * t};
77
77
}
78
78
79
- float PhilipsHueLamp ::getDistanceBetweenTwoPoints (CiColor p1, CiColor p2) {
79
+ float PhilipsHueLight ::getDistanceBetweenTwoPoints (CiColor p1, CiColor p2) {
80
80
// Horizontal difference.
81
81
float dx = p1.x - p2.x ;
82
82
// Vertical difference.
@@ -85,7 +85,7 @@ float PhilipsHueLamp::getDistanceBetweenTwoPoints(CiColor p1, CiColor p2) {
85
85
return sqrt (dx * dx + dy * dy);
86
86
}
87
87
88
- CiColor PhilipsHueLamp ::rgbToCiColor (float red, float green, float blue) {
88
+ CiColor PhilipsHueLight ::rgbToCiColor (float red, float green, float blue) {
89
89
// Apply gamma correction.
90
90
float r = (red > 0 .04045f ) ? powf ((red + 0 .055f ) / (1 .0f + 0 .055f ), 2 .4f ) : (red / 12 .92f );
91
91
float g = (green > 0 .04045f ) ? powf ((green + 0 .055f ) / (1 .0f + 0 .055f ), 2 .4f ) : (green / 12 .92f );
@@ -153,15 +153,15 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
153
153
switchOn ((unsigned int ) ledValues.size ());
154
154
}
155
155
// If there are less states saved than colors given, then maybe something went wrong before.
156
- if (lamps .size () != ledValues.size ()) {
156
+ if (lights .size () != ledValues.size ()) {
157
157
restoreStates ();
158
158
return 0 ;
159
159
}
160
160
// Iterate through colors and set light states.
161
161
unsigned int idx = 0 ;
162
162
for (const ColorRgb& color : ledValues) {
163
163
// Get lamp.
164
- PhilipsHueLamp & lamp = lamps .at (idx);
164
+ PhilipsHueLight & lamp = lights .at (idx);
165
165
// Scale colors from [0, 255] to [0, 1] and convert to xy space.
166
166
CiColor xy = lamp.rgbToCiColor (color.red / 255 .0f , color.green / 255 .0f , color.blue / 255 .0f );
167
167
// Write color if color has been changed.
@@ -247,7 +247,7 @@ QString LedDevicePhilipsHue::getRoute(unsigned int lightId) {
247
247
248
248
void LedDevicePhilipsHue::saveStates (unsigned int nLights) {
249
249
// Clear saved lamps.
250
- lamps .clear ();
250
+ lights .clear ();
251
251
// Use json parser to parse reponse.
252
252
Json::Reader reader;
253
253
Json::FastWriter writer;
@@ -279,24 +279,24 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
279
279
QString modelId = QString (writer.write (json[" modelid" ]).c_str ()).trimmed ().replace (" \" " , " " );
280
280
QString originalState = QString (writer.write (state).c_str ()).trimmed ();
281
281
// Save state object.
282
- lamps .push_back (PhilipsHueLamp (lightIds.at (i), originalState, modelId));
282
+ lights .push_back (PhilipsHueLight (lightIds.at (i), originalState, modelId));
283
283
}
284
284
}
285
285
286
286
void LedDevicePhilipsHue::switchOn (unsigned int nLights) {
287
- for (PhilipsHueLamp lamp : lamps ) {
288
- put (getStateRoute (lamp .id ), " {\" on\" : true}" );
287
+ for (PhilipsHueLight light : lights ) {
288
+ put (getStateRoute (light .id ), " {\" on\" : true}" );
289
289
}
290
290
}
291
291
292
292
void LedDevicePhilipsHue::restoreStates () {
293
- for (PhilipsHueLamp lamp : lamps ) {
294
- put (getStateRoute (lamp .id ), lamp .originalState );
293
+ for (PhilipsHueLight light : lights ) {
294
+ put (getStateRoute (light .id ), light .originalState );
295
295
}
296
296
// Clear saved light states.
297
- lamps .clear ();
297
+ lights .clear ();
298
298
}
299
299
300
300
bool LedDevicePhilipsHue::areStatesSaved () {
301
- return !lamps .empty ();
301
+ return !lights .empty ();
302
302
}
0 commit comments