added optional QT5 support - LedDevicePhilipsHue needs proper fixes

Former-commit-id: 7f0971ccda221933da4be836628532e7cfc7c085
This commit is contained in:
frostworx
2016-01-06 17:31:23 +01:00
parent d5529e86df
commit defe217c89
24 changed files with 210 additions and 9 deletions

View File

@@ -102,8 +102,12 @@ if(ENABLE_TINKERFORGE)
)
endif(ENABLE_TINKERFORGE)
if(ENABLE_QT5)
QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
endif(ENABLE_QT5)
add_library(leddevice
${Leddevice_HEADERS}
@@ -112,6 +116,10 @@ add_library(leddevice
${Leddevice_SOURCES}
)
if(ENABLE_QT5)
qt5_use_modules(leddevice Widgets Network)
endif(ENABLE_QT5)
target_link_libraries(leddevice
hyperion-utils
serialport

View File

@@ -7,7 +7,12 @@
// qt includes
#include <QtCore/qmath.h>
#include <QUrl>
#ifdef ENABLE_QT5
#else
#include <QHttpRequestHeader>
#endif
#include <QEventLoop>
#include <set>
@@ -144,14 +149,22 @@ LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::s
int transitiontime, std::vector<unsigned int> lightIds) :
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
transitiontime), lightIds(lightIds) {
#ifdef ENABLE_QT5
#else
http = new QHttp(host);
timer.setInterval(3000);
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
#endif
}
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
#ifdef ENABLE_QT5
#else
delete http;
#endif
}
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
@@ -201,21 +214,32 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
// Next light id.
idx++;
}
#ifdef ENABLE_QT5
#else
timer.start();
#endif
return 0;
}
int LedDevicePhilipsHue::switchOff() {
#ifdef ENABLE_QT5
#else
timer.stop();
// If light states have been saved before, ...
if (areStatesSaved()) {
// ... restore them.
restoreStates();
}
#endif
return 0;
}
void LedDevicePhilipsHue::put(QString route, QString content) {
#ifdef ENABLE_QT5
#else
QString url = QString("/api/%1/%2").arg(username).arg(route);
QHttpRequestHeader header("PUT", url);
header.setValue("Host", host);
@@ -229,9 +253,13 @@ void LedDevicePhilipsHue::put(QString route, QString content) {
http->request(header, content.toAscii());
// Go into the loop until the request is finished.
loop.exec();
#endif
}
QByteArray LedDevicePhilipsHue::get(QString route) {
#ifdef ENABLE_QT5
return 0;
#else
QString url = QString("/api/%1/%2").arg(username).arg(route);
// Event loop to block until request finished.
QEventLoop loop;
@@ -243,6 +271,7 @@ QByteArray LedDevicePhilipsHue::get(QString route) {
loop.exec();
// Read all data of the response.
return http->readAll();
#endif
}
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {

View File

@@ -4,11 +4,14 @@
#include <string>
// Qt includes
#ifdef ENABLE_QT5
#include <QNetworkAccessManager>
#else
#include <QObject>
#include <QString>
#include <QHttp>
#include <QTimer>
#endif
// Leddevice includes
#include <leddevice/LedDevice.h>
@@ -165,9 +168,14 @@ private:
/// User name for the API ("newdeveloper")
QString username;
/// Qhttp object for sending requests.
#ifdef ENABLE_QT5
// TODO QNetworkAcessManager stuff
#else
QHttp* http;
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
QTimer timer;
#endif
///
bool switchOffOnBlack;
/// Transition time in multiples of 100 ms.