mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Implemented timeout for restoring original state.
Former-commit-id: 925b063aba1a859b592ead9b75ce67d90fb81e28
This commit is contained in:
parent
9220c346bb
commit
8cca280fdc
@ -14,6 +14,7 @@ include_directories(
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(Leddevice_QT_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||
)
|
||||
|
||||
SET(Leddevice_HEADERS
|
||||
@ -29,7 +30,6 @@ SET(Leddevice_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||
)
|
||||
|
||||
SET(Leddevice_SOURCES
|
||||
|
@ -13,6 +13,9 @@
|
||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) :
|
||||
host(output.c_str()), username("newdeveloper") {
|
||||
http = new QHttp(host);
|
||||
timer.setInterval(1000);
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()()));
|
||||
}
|
||||
|
||||
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
|
||||
@ -37,10 +40,12 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
||||
// Next light id.
|
||||
lightId++;
|
||||
}
|
||||
timer.start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedDevicePhilipsHue::switchOff() {
|
||||
timer.stop();
|
||||
// If light states have been saved before, ...
|
||||
if (statesSaved()) {
|
||||
// ... restore them.
|
||||
|
@ -4,8 +4,10 @@
|
||||
#include <string>
|
||||
|
||||
// Qt includes
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QHttp>
|
||||
#include <QTimer>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
@ -18,7 +20,8 @@
|
||||
* Framegrabber must be limited to 10 Hz / numer of lights to avoid rate limitation by the hue bridge.
|
||||
* Create a new API user name "newdeveloper" on the bridge (http://developers.meethue.com/gettingstarted.html)
|
||||
*/
|
||||
class LedDevicePhilipsHue: public LedDevice {
|
||||
class LedDevicePhilipsHue: public QObject, public LedDevice {
|
||||
Q_OBJECT
|
||||
public:
|
||||
///
|
||||
/// Constructs the device.
|
||||
@ -44,6 +47,10 @@ public:
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
||||
private slots:
|
||||
/// Restores the status of all lights.
|
||||
void restoreStates();
|
||||
|
||||
private:
|
||||
/// Array to save the light states.
|
||||
std::vector<QString> states;
|
||||
@ -53,6 +60,8 @@ private:
|
||||
QString username;
|
||||
/// Qhttp object for sending requests.
|
||||
QHttp* http;
|
||||
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
|
||||
QTimer timer;
|
||||
|
||||
///
|
||||
/// Sends a HTTP GET request (blocking).
|
||||
@ -93,9 +102,6 @@ private:
|
||||
///
|
||||
void saveStates(unsigned int nLights);
|
||||
|
||||
/// Restores the status of all lights.
|
||||
void restoreStates();
|
||||
|
||||
///
|
||||
/// @return true if light states have been saved.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user