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

Commit 2ae179c

Browse files
author
Tim Niggemann
committed
Added config options for username and transitiontime
1 parent 899f1ed commit 2ae179c

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

libsrc/leddevice/LedDeviceFactory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
192192
else if (type == "philipshue")
193193
{
194194
const std::string output = deviceConfig["output"].asString();
195+
const std::string username = deviceConfig.get("username", "newdeveloper").asString();
195196
const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool();
196-
device = new LedDevicePhilipsHue(output, switchOffOnBlack);
197+
const int transitiontime = deviceConfig.get("transitiontime", 4).asInt();
198+
device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime);
197199
}
198200
else if (type == "test")
199201
{

libsrc/leddevice/LedDevicePhilipsHue.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ CiColor PhilipsHueLamp::rgbToCiColor(float red, float green, float blue) {
132132
return xy;
133133
}
134134

135-
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, bool switchOffOnBlack) :
136-
host(output.c_str()), username("newdeveloper"), switchOffOnBlack(switchOffOnBlack) {
135+
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack,
136+
int transitiontime) :
137+
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
138+
transitiontime) {
137139
http = new QHttp(host);
138140
timer.setInterval(3000);
139141
timer.setSingleShot(true);
@@ -166,11 +168,13 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
166168
if (xy != lamp.color) {
167169
// Switch on if the lamp has been previously switched off.
168170
if (switchOffOnBlack && lamp.color == lamp.black) {
169-
171+
put(getStateRoute(lamp.id), QString("{\"on\": true}"));
170172
}
171173
// Send adjust color and brightness command in JSON format.
174+
// We have to set the transition time each time.
172175
put(getStateRoute(lamp.id),
173-
QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(xy.x).arg(xy.y).arg(qRound(xy.bri * 255.0f)));
176+
QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg(
177+
qRound(xy.bri * 255.0f)).arg(transitiontime));
174178

175179
}
176180
// Switch lamp off if switchOffOnBlack is enabled and the lamp is currently on.

libsrc/leddevice/LedDevicePhilipsHue.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,14 @@ Q_OBJECT
125125
///
126126
/// @param output the ip address of the bridge
127127
///
128-
/// @param switchOffOnBlack kill lights for black
128+
/// @param username username of the hue bridge (default: newdeveloper)
129129
///
130-
LedDevicePhilipsHue(const std::string& output, bool switchOffOnBlack);
130+
/// @param switchOffOnBlack kill lights for black (default: false)
131+
///
132+
/// @param transitiontime the time duration a light change takes in multiples of 100 ms (default: 400 ms).
133+
///
134+
LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack =
135+
false, int transitiontime = 4);
131136

132137
///
133138
/// Destructor of this device
@@ -163,6 +168,9 @@ private slots:
163168
QTimer timer;
164169
///
165170
bool switchOffOnBlack;
171+
/// Transition time in multiples of 100 ms.
172+
/// The default of the Hue lights will be 400 ms, but we want to have it snapier
173+
int transitiontime;
166174

167175
///
168176
/// Sends a HTTP GET request (blocking).

0 commit comments

Comments
 (0)