Merge pull request #250 from ntim/support_for_philips_hue

Support for philips hue

Former-commit-id: 650ce3b158058fe5de43d5370023d423cb0ea44d
This commit is contained in:
tvdzwan 2015-02-01 20:47:44 +01:00
commit a1d489f62f
3 changed files with 21 additions and 7 deletions

View File

@ -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")
{

View File

@ -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<ColorRgb> & 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.

View File

@ -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).