Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit b1a175a

Browse files
committed
Remove unnecessary code
- reenable timer
1 parent 5a0328f commit b1a175a

File tree

2 files changed

+37
-47
lines changed

2 files changed

+37
-47
lines changed

libsrc/leddevice/LedDevicePhilipsHue.cpp

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string &output) :
1515
host(output.c_str()), username("newdeveloper") {
1616
http = new QHttp(host);
17-
/* timer.setInterval(3000);
17+
timer.setInterval(3000);
1818
timer.setSingleShot(true);
19-
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));*/
19+
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
2020
}
2121

2222
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
2323
delete http;
2424
}
2525

26-
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> &ledValues) {
26+
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
2727
// Save light states if not done before.
2828
if (!statesSaved())
2929
saveStates(ledValues.size());
@@ -65,15 +65,15 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> &ledValues) {
6565
switchLampOn(lightId);
6666

6767
float bri;
68-
CGPoint p = CGPointMake(0, 0);
68+
CGPoint p = {0.0f, 0.0f};
6969
// Scale colors from [0, 255] to [0, 1] and convert to xy space.
70-
rgbToXYBrightness(r, g, b, &p, bri);
70+
rgbToXYBrightness(r, g, b, p, bri);
7171
// Send adjust color and brightness command in JSON format.
7272
put(getStateRoute(lightId),
7373
QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(p.x).arg(p.y).arg(qRound(b * 255.0f)));
7474
}
7575
oldLedValues = ledValues;
76-
//timer.start();
76+
timer.start();
7777
return 0;
7878
}
7979

@@ -95,7 +95,7 @@ bool LedDevicePhilipsHue::hasColorChanged(unsigned int lightId, const ColorRgb *
9595
}
9696

9797
int LedDevicePhilipsHue::switchOff() {
98-
//timer.stop();
98+
timer.stop();
9999
// If light states have been saved before, ...
100100
if (statesSaved()) {
101101
// ... restore them.
@@ -122,7 +122,6 @@ void LedDevicePhilipsHue::put(QString route, QString content) {
122122
http->request(header, content.toAscii());
123123
// Go into the loop until the request is finished.
124124
loop.exec();
125-
//std::cout << http->readAll().data() << std::endl;
126125
}
127126

128127
QByteArray LedDevicePhilipsHue::get(QString route) {
@@ -203,23 +202,15 @@ bool LedDevicePhilipsHue::statesSaved() {
203202
return !states.empty();
204203
}
205204

206-
CGPoint LedDevicePhilipsHue::CGPointMake(float x, float y) {
207-
CGPoint p;
208-
p.x = x;
209-
p.y = y;
210-
211-
return p;
212-
}
213-
214-
float LedDevicePhilipsHue::CrossProduct(CGPoint p1, CGPoint p2) {
205+
float LedDevicePhilipsHue::CrossProduct(CGPoint& p1, CGPoint& p2) {
215206
return (p1.x * p2.y - p1.y * p2.x);
216207
}
217208

218-
bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint p) {
219-
CGPoint v1 = CGPointMake(Green.x - Red.x, Green.y - Red.y);
220-
CGPoint v2 = CGPointMake(Blue.x - Red.x, Blue.y - Red.y);
209+
bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint& p) {
210+
CGPoint v1 = {Green.x - Red.x, Green.y - Red.y};
211+
CGPoint v2 = {Blue.x - Red.x, Blue.y - Red.y};
221212

222-
CGPoint q = CGPointMake(p.x - Red.x, p.y - Red.y);
213+
CGPoint q = {p.x - Red.x, p.y - Red.y};
223214

224215
float s = CrossProduct(q, v2) / CrossProduct(v1, v2);
225216
float t = CrossProduct(v1, q) / CrossProduct(v1, v2);
@@ -229,9 +220,9 @@ bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint p) {
229220
return false;
230221
}
231222

232-
CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoint P) {
233-
CGPoint AP = CGPointMake(P.x - A.x, P.y - A.y);
234-
CGPoint AB = CGPointMake(B.x - A.x, B.y - A.y);
223+
CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint& A, CGPoint& B, CGPoint& P) {
224+
CGPoint AP = {P.x - A.x, P.y - A.y};
225+
CGPoint AB = {B.x - A.x, B.y - A.y};
235226
float ab2 = AB.x * AB.x + AB.y * AB.y;
236227
float ap_ab = AP.x * AB.x + AP.y * AB.y;
237228

@@ -242,18 +233,18 @@ CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoin
242233
else if (t > 1.0f)
243234
t = 1.0f;
244235

245-
return CGPointMake(A.x + AB.x * t, A.y + AB.y * t);
236+
return {A.x + AB.x * t, A.y + AB.y * t};
246237
}
247238

248-
float LedDevicePhilipsHue::GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two) {
239+
float LedDevicePhilipsHue::GetDistanceBetweenTwoPoints(CGPoint& one, CGPoint& two) {
249240
float dx = one.x - two.x; // horizontal difference
250241
float dy = one.y - two.y; // vertical difference
251242
float dist = sqrt(dx * dx + dy * dy);
252243

253244
return dist;
254245
}
255246

256-
void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, CGPoint *xyPoint, float &brightness) {
247+
void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, CGPoint& xyPoint, float& brightness) {
257248
//Apply gamma correction.
258249
float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f);
259250
float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f);
@@ -271,25 +262,25 @@ void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue,
271262
if (isnan(cy))
272263
cy = 0.0f;
273264

274-
(*xyPoint).x = cx;
275-
(*xyPoint).y = cy;
265+
xyPoint.x = cx;
266+
xyPoint.y = cy;
276267

277268
//Check if the given XY value is within the colourreach of our lamps.
278-
bool inReachOfLamps = CheckPointInLampsReach(*xyPoint);
269+
bool inReachOfLamps = CheckPointInLampsReach(xyPoint);
279270

280271
if (!inReachOfLamps) {
281272
//It seems the colour is out of reach
282273
//let's find the closes colour we can produce with our lamp and send this XY value out.
283274

284275
//Find the closest point on each line in the triangle.
285-
CGPoint pAB = GetClosestPointToPoint(Red, Green, *xyPoint);
286-
CGPoint pAC = GetClosestPointToPoint(Blue, Red, *xyPoint);
287-
CGPoint pBC = GetClosestPointToPoint(Green, Blue, *xyPoint);
276+
CGPoint pAB = GetClosestPointToPoint(Red, Green, xyPoint);
277+
CGPoint pAC = GetClosestPointToPoint(Blue, Red, xyPoint);
278+
CGPoint pBC = GetClosestPointToPoint(Green, Blue, xyPoint);
288279

289280
//Get the distances per point and see which point is closer to our Point.
290-
float dAB = GetDistanceBetweenTwoPoints(*xyPoint, pAB);
291-
float dAC = GetDistanceBetweenTwoPoints(*xyPoint, pAC);
292-
float dBC = GetDistanceBetweenTwoPoints(*xyPoint, pBC);
281+
float dAB = GetDistanceBetweenTwoPoints(xyPoint, pAB);
282+
float dAC = GetDistanceBetweenTwoPoints(xyPoint, pAC);
283+
float dBC = GetDistanceBetweenTwoPoints(xyPoint, pBC);
293284

294285
float lowest = dAB;
295286
CGPoint closestPoint = pAB;
@@ -304,8 +295,8 @@ void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue,
304295
}
305296

306297
//Change the xy value to a value which is within the reach of the lamp.
307-
(*xyPoint).x = closestPoint.x;
308-
(*xyPoint).y = closestPoint.y;
298+
xyPoint.x = closestPoint.x;
299+
xyPoint.y = closestPoint.y;
309300
}
310301

311302
// Brightness is simply Y in the XYZ space.

libsrc/leddevice/LedDevicePhilipsHue.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Q_OBJECT
4949
///
5050
/// @return Zero on success else negative
5151
///
52-
virtual int write(const std::vector<ColorRgb> &ledValues);
52+
virtual int write(const std::vector<ColorRgb> & ledValues);
5353

5454
/// Restores the original state of the leds.
5555
virtual int switchOff();
@@ -59,18 +59,17 @@ private slots:
5959
void restoreStates();
6060

6161
private:
62-
// ModelIds
62+
/// Available modelIds
6363
const std::vector<QString> hueBulbs = {"LCT001", "LCT002", "LCT003"};
6464
const std::vector<QString> livingColors = {"LLC001", "LLC005", "LLC006", "LLC007",
6565
"LLC011", "LLC012", "LLC013", "LST001"};
66-
/// LivingColors color gamut triangle
66+
/// Color gamut triangle
6767
CGPoint Red , Green, Blue;
6868

69-
CGPoint CGPointMake(float x, float y);
70-
float CrossProduct(CGPoint p1, CGPoint p2);
71-
bool CheckPointInLampsReach(CGPoint p);
72-
CGPoint GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoint P);
73-
float GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two);
69+
float CrossProduct(CGPoint& p1, CGPoint& p2);
70+
bool CheckPointInLampsReach(CGPoint& p);
71+
CGPoint GetClosestPointToPoint(CGPoint& A, CGPoint& B, CGPoint& P);
72+
float GetDistanceBetweenTwoPoints(CGPoint& one, CGPoint& two);
7473

7574
/// Array to save the light states.
7675
std::vector<QString> states;
@@ -159,6 +158,6 @@ private slots:
159158
///
160159
/// @param brightness converted brightness component
161160
///
162-
void rgbToXYBrightness(float red, float green, float blue, CGPoint *xyPoint, float &brightness);
161+
void rgbToXYBrightness(float red, float green, float blue, CGPoint& xyPoint, float& brightness);
163162

164163
};

0 commit comments

Comments
 (0)