@@ -20,7 +20,7 @@ bool operator !=(CiColor p1, CiColor p2) {
2020 return !(p1 == p2);
2121}
2222
23- PhilipsHueLamp::PhilipsHueLamp (unsigned int id, QString originalState, QString modelId) :
23+ PhilipsHueLight::PhilipsHueLight (unsigned int id, QString originalState, QString modelId) :
2424 id(id), originalState(originalState) {
2525 // Hue system model ids.
2626 const std::set<QString> HUE_BULBS_MODEL_IDS = { " LCT001" , " LCT002" , " LCT003" };
@@ -46,11 +46,11 @@ PhilipsHueLamp::PhilipsHueLamp(unsigned int id, QString originalState, QString m
4646 color = {black.x , black.y , black.bri };
4747}
4848
49- float PhilipsHueLamp ::crossProduct (CiColor p1, CiColor p2) {
49+ float PhilipsHueLight ::crossProduct (CiColor p1, CiColor p2) {
5050 return p1.x * p2.y - p1.y * p2.x ;
5151}
5252
53- bool PhilipsHueLamp ::isPointInLampsReach (CiColor p) {
53+ bool PhilipsHueLight ::isPointInLampsReach (CiColor p) {
5454 CiColor v1 = { colorSpace.green .x - colorSpace.red .x , colorSpace.green .y - colorSpace.red .y };
5555 CiColor v2 = { colorSpace.blue .x - colorSpace.red .x , colorSpace.blue .y - colorSpace.red .y };
5656 CiColor q = { p.x - colorSpace.red .x , p.y - colorSpace.red .y };
@@ -62,7 +62,7 @@ bool PhilipsHueLamp::isPointInLampsReach(CiColor p) {
6262 return false ;
6363}
6464
65- CiColor PhilipsHueLamp ::getClosestPointToPoint (CiColor a, CiColor b, CiColor p) {
65+ CiColor PhilipsHueLight ::getClosestPointToPoint (CiColor a, CiColor b, CiColor p) {
6666 CiColor AP = { p.x - a.x , p.y - a.y };
6767 CiColor AB = { b.x - a.x , b.y - a.y };
6868 float ab2 = AB.x * AB.x + AB.y * AB.y ;
@@ -76,7 +76,7 @@ CiColor PhilipsHueLamp::getClosestPointToPoint(CiColor a, CiColor b, CiColor p)
7676 return {a.x + AB.x * t, a.y + AB.y * t};
7777}
7878
79- float PhilipsHueLamp ::getDistanceBetweenTwoPoints (CiColor p1, CiColor p2) {
79+ float PhilipsHueLight ::getDistanceBetweenTwoPoints (CiColor p1, CiColor p2) {
8080 // Horizontal difference.
8181 float dx = p1.x - p2.x ;
8282 // Vertical difference.
@@ -85,7 +85,7 @@ float PhilipsHueLamp::getDistanceBetweenTwoPoints(CiColor p1, CiColor p2) {
8585 return sqrt (dx * dx + dy * dy);
8686}
8787
88- CiColor PhilipsHueLamp ::rgbToCiColor (float red, float green, float blue) {
88+ CiColor PhilipsHueLight ::rgbToCiColor (float red, float green, float blue) {
8989 // Apply gamma correction.
9090 float r = (red > 0 .04045f ) ? powf ((red + 0 .055f ) / (1 .0f + 0 .055f ), 2 .4f ) : (red / 12 .92f );
9191 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) {
153153 switchOn ((unsigned int ) ledValues.size ());
154154 }
155155 // 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 ()) {
157157 restoreStates ();
158158 return 0 ;
159159 }
160160 // Iterate through colors and set light states.
161161 unsigned int idx = 0 ;
162162 for (const ColorRgb& color : ledValues) {
163163 // Get lamp.
164- PhilipsHueLamp & lamp = lamps .at (idx);
164+ PhilipsHueLight & lamp = lights .at (idx);
165165 // Scale colors from [0, 255] to [0, 1] and convert to xy space.
166166 CiColor xy = lamp.rgbToCiColor (color.red / 255 .0f , color.green / 255 .0f , color.blue / 255 .0f );
167167 // Write color if color has been changed.
@@ -247,7 +247,7 @@ QString LedDevicePhilipsHue::getRoute(unsigned int lightId) {
247247
248248void LedDevicePhilipsHue::saveStates (unsigned int nLights) {
249249 // Clear saved lamps.
250- lamps .clear ();
250+ lights .clear ();
251251 // Use json parser to parse reponse.
252252 Json::Reader reader;
253253 Json::FastWriter writer;
@@ -279,24 +279,24 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
279279 QString modelId = QString (writer.write (json[" modelid" ]).c_str ()).trimmed ().replace (" \" " , " " );
280280 QString originalState = QString (writer.write (state).c_str ()).trimmed ();
281281 // Save state object.
282- lamps .push_back (PhilipsHueLamp (lightIds.at (i), originalState, modelId));
282+ lights .push_back (PhilipsHueLight (lightIds.at (i), originalState, modelId));
283283 }
284284}
285285
286286void 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}" );
289289 }
290290}
291291
292292void 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 );
295295 }
296296 // Clear saved light states.
297- lamps .clear ();
297+ lights .clear ();
298298}
299299
300300bool LedDevicePhilipsHue::areStatesSaved () {
301- return !lamps .empty ();
301+ return !lights .empty ();
302302}
0 commit comments