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

Commit 925b063

Browse files
committed
Implemented timeout for restoring original state.
1 parent 5887fdf commit 925b063

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

libsrc/leddevice/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ include_directories(
1414
# Group the headers that go through the MOC compiler
1515
SET(Leddevice_QT_HEADERS
1616
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
17+
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
1718
)
1819

1920
SET(Leddevice_HEADERS
@@ -29,7 +30,6 @@ SET(Leddevice_HEADERS
2930
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
3031
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
3132
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
32-
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
3333
)
3434

3535
SET(Leddevice_SOURCES

libsrc/leddevice/LedDevicePhilipsHue.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) :
1414
host(output.c_str()), username("newdeveloper") {
1515
http = new QHttp(host);
16+
timer.setInterval(1000);
17+
timer.setSingleShot(true);
18+
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()()));
1619
}
1720

1821
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
@@ -37,10 +40,12 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
3740
// Next light id.
3841
lightId++;
3942
}
43+
timer.start();
4044
return 0;
4145
}
4246

4347
int LedDevicePhilipsHue::switchOff() {
48+
timer.stop();
4449
// If light states have been saved before, ...
4550
if (statesSaved()) {
4651
// ... restore them.

libsrc/leddevice/LedDevicePhilipsHue.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include <string>
55

66
// Qt includes
7+
#include <QObject>
78
#include <QString>
89
#include <QHttp>
10+
#include <QTimer>
911

1012
// Leddevice includes
1113
#include <leddevice/LedDevice.h>
@@ -18,7 +20,8 @@
1820
* Framegrabber must be limited to 10 Hz / numer of lights to avoid rate limitation by the hue bridge.
1921
* Create a new API user name "newdeveloper" on the bridge (http://developers.meethue.com/gettingstarted.html)
2022
*/
21-
class LedDevicePhilipsHue: public LedDevice {
23+
class LedDevicePhilipsHue: public QObject, public LedDevice {
24+
Q_OBJECT
2225
public:
2326
///
2427
/// Constructs the device.
@@ -44,6 +47,10 @@ class LedDevicePhilipsHue: public LedDevice {
4447
/// Switch the leds off
4548
virtual int switchOff();
4649

50+
private slots:
51+
/// Restores the status of all lights.
52+
void restoreStates();
53+
4754
private:
4855
/// Array to save the light states.
4956
std::vector<QString> states;
@@ -53,6 +60,8 @@ class LedDevicePhilipsHue: public LedDevice {
5360
QString username;
5461
/// Qhttp object for sending requests.
5562
QHttp* http;
63+
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
64+
QTimer timer;
5665

5766
///
5867
/// Sends a HTTP GET request (blocking).
@@ -93,9 +102,6 @@ class LedDevicePhilipsHue: public LedDevice {
93102
///
94103
void saveStates(unsigned int nLights);
95104

96-
/// Restores the status of all lights.
97-
void restoreStates();
98-
99105
///
100106
/// @return true if light states have been saved.
101107
///

0 commit comments

Comments
 (0)