diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 9e547920..a7f78319 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -192,8 +192,10 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) else if (type == "philipshue") { const std::string output = deviceConfig["output"].asString(); + const std::string username = deviceConfig.get("username", "newdeveloper").asString(); const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool(); - device = new LedDevicePhilipsHue(output, switchOffOnBlack); + const int transitiontime = deviceConfig.get("transitiontime", 1).asInt(); + device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime); } else if (type == "test") { diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index 35607871..c8cfa339 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -132,8 +132,10 @@ CiColor PhilipsHueLamp::rgbToCiColor(float red, float green, float blue) { return xy; } -LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, bool switchOffOnBlack) : - host(output.c_str()), username("newdeveloper"), switchOffOnBlack(switchOffOnBlack) { +LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack, + int transitiontime) : + host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime( + transitiontime) { http = new QHttp(host); timer.setInterval(3000); timer.setSingleShot(true); @@ -166,11 +168,13 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) { if (xy != lamp.color) { // Switch on if the lamp has been previously switched off. if (switchOffOnBlack && lamp.color == lamp.black) { - + put(getStateRoute(lamp.id), QString("{\"on\": true}")); } // Send adjust color and brightness command in JSON format. + // We have to set the transition time each time. put(getStateRoute(lamp.id), - QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(xy.x).arg(xy.y).arg(qRound(xy.bri * 255.0f))); + QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg( + qRound(xy.bri * 255.0f)).arg(transitiontime)); } // Switch lamp off if switchOffOnBlack is enabled and the lamp is currently on. diff --git a/libsrc/leddevice/LedDevicePhilipsHue.h b/libsrc/leddevice/LedDevicePhilipsHue.h index 085defb0..8a678505 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/LedDevicePhilipsHue.h @@ -125,9 +125,14 @@ public: /// /// @param output the ip address of the bridge /// - /// @param switchOffOnBlack kill lights for black + /// @param username username of the hue bridge (default: newdeveloper) /// - LedDevicePhilipsHue(const std::string& output, bool switchOffOnBlack); + /// @param switchOffOnBlack kill lights for black (default: false) + /// + /// @param transitiontime the time duration a light change takes in multiples of 100 ms (default: 400 ms). + /// + LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack = + false, int transitiontime = 1); /// /// Destructor of this device @@ -163,6 +168,9 @@ private: QTimer timer; /// bool switchOffOnBlack; + /// Transition time in multiples of 100 ms. + /// The default of the Hue lights will be 400 ms, but we want to have it snapier + int transitiontime; /// /// Sends a HTTP GET request (blocking).