From 2b3a3be0d3b7d3a8c9a734bb61535309c01afd8a Mon Sep 17 00:00:00 2001 From: Fabian Hertwig Date: Sat, 24 May 2014 13:03:46 +0200 Subject: [PATCH 01/11] Added the possibility to change the base color of the mood blobs over time. The base Color is moved 1 degree in baseColorChangeRate seconds if activated. It is moved between baseColorRangeLeft and baseColorRangeRight. These Values are in degrees. When these borders are set to the full circle (eg. 0 and 360), the base color moves around the colorwheel, otherwise it moves from left to right and back again. Furthermore there are three effects script for this feature: "Full color mood blobs" which moves around the full circle, "Warm mood blobs" and "Cold mood blobs" which only shows the warm, cold colors. This update wont change the functionality of the old scripts. Former-commit-id: 0c7a2ad280e49cd1ac0d6a9fbc9d1a9ff0eea236 --- effects/mood-blobs-cold.json | 16 +++++++ effects/mood-blobs-full.json | 16 +++++++ effects/mood-blobs-warm.json | 16 +++++++ effects/mood-blobs.py | 93 ++++++++++++++++++++++++++++-------- 4 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 effects/mood-blobs-cold.json create mode 100644 effects/mood-blobs-full.json create mode 100644 effects/mood-blobs-warm.json diff --git a/effects/mood-blobs-cold.json b/effects/mood-blobs-cold.json new file mode 100644 index 00000000..d259b9f1 --- /dev/null +++ b/effects/mood-blobs-cold.json @@ -0,0 +1,16 @@ +{ + "name" : "Cold mood blobs", + "script" : "mood-blobs.py", + "args" : + { + "rotationTime" : 60.0, + "color" : [0,0,255], + "hueChange" : 30.0, + "blobs" : 5, + "reverse" : false, + "baseChange" : true, + "baseColorRangeLeft" : 160, + "baseColorRangeRight" : 320, + "baseColorChangeRate" : 2.0 + } +} diff --git a/effects/mood-blobs-full.json b/effects/mood-blobs-full.json new file mode 100644 index 00000000..8b230010 --- /dev/null +++ b/effects/mood-blobs-full.json @@ -0,0 +1,16 @@ +{ + "name" : "Full color mood blobs", + "script" : "mood-blobs.py", + "args" : + { + "rotationTime" : 60.0, + "color" : [0,0,255], + "hueChange" : 30.0, + "blobs" : 5, + "reverse" : false, + "baseChange" : true, + "baseColorRangeLeft" : 0, + "baseColorRangeRight" : 360, + "baseColorChangeRate" : 0.2 + } +} diff --git a/effects/mood-blobs-warm.json b/effects/mood-blobs-warm.json new file mode 100644 index 00000000..39443092 --- /dev/null +++ b/effects/mood-blobs-warm.json @@ -0,0 +1,16 @@ +{ + "name" : "Warm mood blobs", + "script" : "mood-blobs.py", + "args" : + { + "rotationTime" : 60.0, + "color" : [255,0,0], + "hueChange" : 30.0, + "blobs" : 5, + "reverse" : false, + "baseChange" : true, + "baseColorRangeLeft" : 333, + "baseColorRangeRight" : 151, + "baseColorChangeRate" : 2.0 + } +} diff --git a/effects/mood-blobs.py b/effects/mood-blobs.py index c0ce3d15..b638f3d3 100644 --- a/effects/mood-blobs.py +++ b/effects/mood-blobs.py @@ -6,14 +6,31 @@ import math # Get the parameters rotationTime = float(hyperion.args.get('rotationTime', 20.0)) color = hyperion.args.get('color', (0,0,255)) -hueChange = float(hyperion.args.get('hueChange', 60.0)) / 360.0 +hueChange = float(hyperion.args.get('hueChange', 60.0)) blobs = int(hyperion.args.get('blobs', 5)) reverse = bool(hyperion.args.get('reverse', False)) +baseColorChange = bool(hyperion.args.get('baseChange', False)) +baseColorRangeLeft = float(hyperion.args.get('baseColorRangeLeft',0.0)) # Degree +baseColorRangeRight = float(hyperion.args.get('baseColorRangeRight',360.0)) # Degree +baseColorChangeRate = float(hyperion.args.get('baseColorChangeRate',10.0)) # Seconds for one Degree + +# switch baseColor change off if left and right are too close together to see a difference in color +if (baseColorRangeRight > baseColorRangeLeft and (baseColorRangeRight - baseColorRangeLeft) < 10) or \ + (baseColorRangeLeft > baseColorRangeRight and ((baseColorRangeRight + 360) - baseColorRangeLeft) < 10): + baseColorChange = False + +# 360 -> 1 +fullColorWheelAvailable = (baseColorRangeRight % 360) == (baseColorRangeLeft % 360) +baseColorChangeIncreaseValue = 1.0 / 360.0 # 1 degree +hueChange /= 360.0 +baseColorRangeLeft = (baseColorRangeLeft / 360.0) +baseColorRangeRight = (baseColorRangeRight / 360.0) # Check parameters rotationTime = max(0.1, rotationTime) hueChange = max(0.0, min(abs(hueChange), .5)) blobs = max(1, blobs) +baseColorChangeRate = max(0, baseColorChangeRate) # > 0 # Calculate the color data baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0) @@ -27,6 +44,7 @@ for i in range(hyperion.ledCount): sleepTime = 0.1 amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime colorDataIncrement = 3 +baseColorChangeRate /= sleepTime # Switch direction if needed if reverse: @@ -39,23 +57,58 @@ colors = bytearray(hyperion.ledCount * (0,0,0)) # Start the write data loop amplitudePhase = 0.0 rotateColors = False -while not hyperion.abort(): - # Calculate new colors - for i in range(hyperion.ledCount): - amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount)) - colors[3*i+0] = int(colorData[3*i+0] * amplitude) - colors[3*i+1] = int(colorData[3*i+1] * amplitude) - colors[3*i+2] = int(colorData[3*i+2] * amplitude) +baseColorChangeStepCount = 0 +baseHSVValue = baseHsv[0] +numberOfRotates = 0 - # set colors - hyperion.setColor(colors) - - # increment the phase - amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi) - - if rotateColors: - colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement] - rotateColors = not rotateColors - - # sleep for a while - time.sleep(sleepTime) +while not hyperion.abort(): + + # move the basecolor + if baseColorChange: + # every baseColorChangeRate seconds + if baseColorChangeStepCount >= baseColorChangeRate: + baseColorChangeStepCount = 0 + # cyclic increment when the full colorwheel is available, move up and down otherwise + if fullColorWheelAvailable: + baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % baseColorRangeRight + else: + # switch increment direction if baseHSV <= left or baseHSV >= right + if baseColorChangeIncreaseValue < 0 and baseHSVValue > baseColorRangeLeft and (baseHSVValue + baseColorChangeIncreaseValue) <= baseColorRangeLeft: + baseColorChangeIncreaseValue = abs(baseColorChangeIncreaseValue) + elif baseColorChangeIncreaseValue > 0 and baseHSVValue < baseColorRangeRight and (baseHSVValue + baseColorChangeIncreaseValue) >= baseColorRangeRight : + baseColorChangeIncreaseValue = -abs(baseColorChangeIncreaseValue) + + baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % 1.0 + + # update color values + colorData = bytearray() + for i in range(hyperion.ledCount): + hue = (baseHSVValue + hueChange * math.sin(2*math.pi * i / hyperion.ledCount)) % 1.0 + rgb = colorsys.hsv_to_rgb(hue, baseHsv[1], baseHsv[2]) + colorData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2]))) + + # set correct rotation after reinitialisation of the array + colorData = colorData[-colorDataIncrement*numberOfRotates:] + colorData[:-colorDataIncrement*numberOfRotates] + + baseColorChangeStepCount += 1 + + # Calculate new colors + for i in range(hyperion.ledCount): + amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount)) + colors[3*i+0] = int(colorData[3*i+0] * amplitude) + colors[3*i+1] = int(colorData[3*i+1] * amplitude) + colors[3*i+2] = int(colorData[3*i+2] * amplitude) + + # set colors + hyperion.setColor(colors) + + # increment the phase + amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi) + + if rotateColors: + colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement] + numberOfRotates = (numberOfRotates + 1) % hyperion.ledCount + rotateColors = not rotateColors + + # sleep for a while + time.sleep(sleepTime) From 8f1bb8e9db1b43ab5cb9710cbd805b1e04ee2d98 Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Sat, 24 May 2014 21:05:59 +0200 Subject: [PATCH 02/11] Updated hyperion release to include philips hue Former-commit-id: d46ccf12d1f2a8059d45f946fe0f4c43e8b5bc9e --- deploy/hyperion.tar.gz.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index 7f4560e3..b04b8f6e 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -e3e4ea5204c555e64aa909d5bbbd6ac95ebec0dc \ No newline at end of file +bfe399d8f3299c6110179fddb9f2b06b475d6a53 \ No newline at end of file From 98dfe7997f9eefa86da2164edd8e659372ec1005 Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Mon, 2 Jun 2014 21:38:41 +0200 Subject: [PATCH 03/11] Updated release with updated blob effect Former-commit-id: 3d859fb7283961152ff67eb8101db89bdcd21847 --- deploy/hyperion.tar.gz.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index dde0b4dd..35028a43 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -e6c826638971667596af0fb18e819514d8390286 \ No newline at end of file +d9eb8f0ef98c76bc54a43cc572183f7c54fc4dc9 \ No newline at end of file From 1d046ab35a8021c7bf5719ed508e50e1c07850f0 Mon Sep 17 00:00:00 2001 From: Gamadril Date: Sun, 15 Jun 2014 02:19:09 +0200 Subject: [PATCH 04/11] Added support for tpm2 protocol. One frame used for all LEDs Former-commit-id: 5b2ed33a50d90999c6f9508ba3782ad73838fb56 --- libsrc/leddevice/CMakeLists.txt | 2 ++ libsrc/leddevice/LedDeviceFactory.cpp | 10 +++++++ libsrc/leddevice/LedDeviceTpm2.cpp | 42 +++++++++++++++++++++++++++ libsrc/leddevice/LedDeviceTpm2.h | 38 ++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 libsrc/leddevice/LedDeviceTpm2.cpp create mode 100644 libsrc/leddevice/LedDeviceTpm2.h diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 093975db..441618d2 100755 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -29,6 +29,7 @@ SET(Leddevice_HEADERS ${CURRENT_SOURCE_DIR}/LedDeviceSedu.h ${CURRENT_SOURCE_DIR}/LedDeviceTest.h ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h + ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h ) SET(Leddevice_SOURCES @@ -45,6 +46,7 @@ SET(Leddevice_SOURCES ${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp ${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp + ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp ) if(ENABLE_SPIDEV) diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 76eb0137..9c42384a 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -29,6 +29,7 @@ #include "LedDeviceTest.h" #include "LedDeviceHyperionUsbasp.h" #include "LedDevicePhilipsHue.h" +#include "LedDeviceTpm2.h" LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) { @@ -171,6 +172,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) const std::string output = deviceConfig["output"].asString(); device = new LedDeviceTest(output); } + else if (type == "tpm2") + { + const std::string output = deviceConfig["output"].asString(); + const unsigned rate = deviceConfig["rate"].asInt(); + + LedDeviceTpm2* deviceTpm2 = new LedDeviceTpm2(output, rate); + deviceTpm2->open(); + device = deviceTpm2; + } else { std::cout << "Unable to create device " << type << std::endl; diff --git a/libsrc/leddevice/LedDeviceTpm2.cpp b/libsrc/leddevice/LedDeviceTpm2.cpp new file mode 100644 index 00000000..49bb6121 --- /dev/null +++ b/libsrc/leddevice/LedDeviceTpm2.cpp @@ -0,0 +1,42 @@ + +// STL includes +#include +#include +#include + +// Linux includes +#include +#include + +// hyperion local includes +#include "LedDeviceTpm2.h" + +LedDeviceTpm2::LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate) : + LedRs232Device(outputDevice, baudrate), + _ledBuffer(0) +{ + // empty +} + +int LedDeviceTpm2::write(const std::vector &ledValues) +{ + if (_ledBuffer.size() == 0) + { + _ledBuffer.resize(5 + 3*ledValues.size()); + _ledBuffer[0] = 0xC9; // block-start byte + _ledBuffer[1] = 0xDA; // DATA frame + _ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // LED count high byte + _ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // LED count low byte + _ledBuffer.back() = 0x36; // block-end byte + } + + // write data + memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} + +int LedDeviceTpm2::switchOff() +{ + memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 5); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/leddevice/LedDeviceTpm2.h b/libsrc/leddevice/LedDeviceTpm2.h new file mode 100644 index 00000000..f7ca8680 --- /dev/null +++ b/libsrc/leddevice/LedDeviceTpm2.h @@ -0,0 +1,38 @@ +#pragma once + +// STL includes +#include + +// hyperion incluse +#include "LedRs232Device.h" + +/// +/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol. +/// +class LedDeviceTpm2 : public LedRs232Device +{ +public: + /// + /// Constructs the LedDevice for attached serial device using supporting tpm2 protocol + /// All LEDs in the stripe are handled as one frame + /// + /// @param outputDevice The name of the output device (eg '/dev/ttyAMA0') + /// @param baudrate The used baudrate for writing to the output device + /// + LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate); + + /// + /// Writes the led color values to the led-device + /// + /// @param ledValues The color-value per led + /// @return Zero on succes else negative + /// + virtual int write(const std::vector &ledValues); + + /// Switch the leds off + virtual int switchOff(); + +private: + /// The buffer containing the packed RGB values + std::vector _ledBuffer; +}; From 3135b89255f529737da02ce4bde073328a5ee509 Mon Sep 17 00:00:00 2001 From: Gamadril Date: Wed, 18 Jun 2014 13:49:27 +0200 Subject: [PATCH 05/11] Update LedDeviceTpm2.cpp Former-commit-id: 8d51eb00044460002e29687468786e3056afd0bb --- libsrc/leddevice/LedDeviceTpm2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/leddevice/LedDeviceTpm2.cpp b/libsrc/leddevice/LedDeviceTpm2.cpp index 49bb6121..a0fcf869 100644 --- a/libsrc/leddevice/LedDeviceTpm2.cpp +++ b/libsrc/leddevice/LedDeviceTpm2.cpp @@ -22,11 +22,11 @@ int LedDeviceTpm2::write(const std::vector &ledValues) { if (_ledBuffer.size() == 0) { - _ledBuffer.resize(5 + 3*ledValues.size()); + _ledBuffer.resize(5 + 3*ledValues.size()); _ledBuffer[0] = 0xC9; // block-start byte _ledBuffer[1] = 0xDA; // DATA frame - _ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // LED count high byte - _ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // LED count low byte + _ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // frame size high byte + _ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // frame size low byte _ledBuffer.back() = 0x36; // block-end byte } From ba4d2b45d5ae3a6b90c0c5ef2e5216328293b1db Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Thu, 19 Jun 2014 22:16:03 +0200 Subject: [PATCH 06/11] Updated release package to include new device (tpm2) Former-commit-id: 24decda30a774b4d3702ec8fa375bc1ac4b849d7 --- deploy/hyperion.tar.gz.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index 35028a43..7729eb84 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -d9eb8f0ef98c76bc54a43cc572183f7c54fc4dc9 \ No newline at end of file +5e8d795d2aa82337e42924c1a5292203d7d4271a \ No newline at end of file From c4c7ed03319220e50ad78e37502d14dcc896cdd3 Mon Sep 17 00:00:00 2001 From: bimsarck Date: Fri, 4 Jul 2014 12:11:37 +0200 Subject: [PATCH 07/11] Improved philip hue device: add lamp types autodetection add full xy-Colorspace implementations reduce http requests to the hue bridge. This prevents DDOS -> 503 add color black -> lamps off save state is temporary disabled Former-commit-id: 5a0328fe80a06a9f670c5190190e239857cbd15c --- libsrc/leddevice/LedDevicePhilipsHue.cpp | 231 +++++++++++++++++++---- libsrc/leddevice/LedDevicePhilipsHue.h | 33 +++- 2 files changed, 220 insertions(+), 44 deletions(-) diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index f8a9698a..ed549b35 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -1,3 +1,4 @@ +#include // Local-Hyperion includes #include "LedDevicePhilipsHue.h" @@ -10,43 +11,91 @@ #include #include -LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) : - host(output.c_str()), username("newdeveloper") { +LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string &output) : + host(output.c_str()), username("newdeveloper") { http = new QHttp(host); - timer.setInterval(3000); +/* timer.setInterval(3000); timer.setSingleShot(true); - connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates())); + connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));*/ } LedDevicePhilipsHue::~LedDevicePhilipsHue() { delete http; } -int LedDevicePhilipsHue::write(const std::vector & ledValues) { +int LedDevicePhilipsHue::write(const std::vector &ledValues) { // Save light states if not done before. - if (!statesSaved()) { + if (!statesSaved()) saveStates(ledValues.size()); - switchOn(ledValues.size()); - } // Iterate through colors and set light states. - unsigned int lightId = 1; - for (const ColorRgb& color : ledValues) { - float x, y, b; - // Scale colors from [0, 255] to [0, 1] and convert to xy space. - rgbToXYBrightness(color.red / 255.0f, color.green / 255.0f, color.blue / 255.0f, x, y, b); - // Send adjust color command in JSON format. - put(getStateRoute(lightId), QString("{\"xy\": [%1, %2]}").arg(x).arg(y)); - // Send brightness color command in JSON format. - put(getStateRoute(lightId), QString("{\"bri\": %1}").arg(qRound(b * 255.0f))); - // Next light id. + unsigned int lightId = 0; + for (const ColorRgb &color : ledValues) { lightId++; + // Send only request to the brigde if color changed (prevents DDOS --> 503) + if (!oldLedValues.empty()) + if(!hasColorChanged(lightId, &color)) + continue; + + float r = color.red / 255.0f; + float g = color.green / 255.0f; + float b = color.blue / 255.0f; + + //set color gamut triangle + if(std::find(hueBulbs.begin(), hueBulbs.end(), modelIds[(lightId - 1)]) != hueBulbs.end()) { + Red = {0.675f, 0.322f}; + Green = {0.4091f, 0.518f}; + Blue = {0.167f, 0.04f}; + } else if (std::find(livingColors.begin(), + livingColors.end(), modelIds[(lightId - 1)]) != livingColors.end()) { + Red = {0.703f, 0.296f}; + Green = {0.214f, 0.709f}; + Blue = {0.139f, 0.081f}; + } else { + Red = {1.0f, 0.0f}; + Green = {0.0f, 1.0f}; + Blue = {0.0f, 0.0f}; + } + // if color equal black, switch off lamp ... + if (r == 0.0f && g == 0.0f && b == 0.0f) { + switchLampOff(lightId); + continue; + } + // ... and if lamp off, switch on + if (!checkOnStatus(states[(lightId - 1)])) + switchLampOn(lightId); + + float bri; + CGPoint p = CGPointMake(0, 0); + // Scale colors from [0, 255] to [0, 1] and convert to xy space. + rgbToXYBrightness(r, g, b, &p, bri); + // Send adjust color and brightness command in JSON format. + put(getStateRoute(lightId), + QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(p.x).arg(p.y).arg(qRound(b * 255.0f))); } - timer.start(); + oldLedValues = ledValues; + //timer.start(); return 0; } +bool LedDevicePhilipsHue::hasColorChanged(unsigned int lightId, const ColorRgb *color) { + bool matchFound = true; + const ColorRgb &tmpOldColor = oldLedValues[(lightId - 1)]; + if ((*color).red == tmpOldColor.red) + matchFound = false; + if (!matchFound && (*color).green == tmpOldColor.green) + matchFound = false; + else + matchFound = true; + if (!matchFound && (*color).blue == tmpOldColor.blue) + matchFound = false; + else + matchFound = true; + + return matchFound; +} + int LedDevicePhilipsHue::switchOff() { - timer.stop(); + //timer.stop(); // If light states have been saved before, ... if (statesSaved()) { // ... restore them. @@ -55,6 +104,10 @@ int LedDevicePhilipsHue::switchOff() { return 0; } +bool LedDevicePhilipsHue::checkOnStatus(QString status) { + return status.contains("\"on\":true"); +} + void LedDevicePhilipsHue::put(QString route, QString content) { QString url = QString("/api/%1/%2").arg(username).arg(route); QHttpRequestHeader header("PUT", url); @@ -69,6 +122,7 @@ void LedDevicePhilipsHue::put(QString route, QString content) { http->request(header, content.toAscii()); // Go into the loop until the request is finished. loop.exec(); + //std::cout << http->readAll().data() << std::endl; } QByteArray LedDevicePhilipsHue::get(QString route) { @@ -96,6 +150,7 @@ QString LedDevicePhilipsHue::getRoute(unsigned int lightId) { void LedDevicePhilipsHue::saveStates(unsigned int nLights) { // Clear saved light states. states.clear(); + modelIds.clear(); // Use json parser to parse reponse. Json::Reader reader; Json::FastWriter writer; @@ -117,14 +172,19 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) { state["bri"] = json["state"]["bri"]; } // Save state object. + modelIds.push_back(QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", "")); states.push_back(QString(writer.write(state).c_str()).trimmed()); } } -void LedDevicePhilipsHue::switchOn(unsigned int nLights) { - for (unsigned int i = 0; i < nLights; i++) { - put(getStateRoute(i + 1), "{\"on\": true}"); - } +void LedDevicePhilipsHue::switchLampOn(unsigned int lightId) { + put(getStateRoute(lightId), "{\"on\": true}"); + states[(lightId - 1)].replace("\"on\":false", "\"on\":true"); +} + +void LedDevicePhilipsHue::switchLampOff(unsigned int lightId) { + put(getStateRoute(lightId), "{\"on\": false}"); + states[(lightId - 1)].replace("\"on\":true", "\"on\":false"); } void LedDevicePhilipsHue::restoreStates() { @@ -135,30 +195,119 @@ void LedDevicePhilipsHue::restoreStates() { } // Clear saved light states. states.clear(); + modelIds.clear(); + oldLedValues.clear(); } bool LedDevicePhilipsHue::statesSaved() { return !states.empty(); } -void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, float& x, float& y, float& brightness) { - // Apply gamma correction. - red = (red > 0.04045f) ? qPow((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); - green = (green > 0.04045f) ? qPow((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); - blue = (blue > 0.04045f) ? qPow((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f); - // Convert to XYZ space. - float X = red * 0.649926f + green * 0.103455f + blue * 0.197109f; - float Y = red * 0.234327f + green * 0.743075f + blue * 0.022598f; - float Z = red * 0.0000000f + green * 0.053077f + blue * 1.035763f; - // Convert to x,y space. - x = X / (X + Y + Z); - y = Y / (X + Y + Z); - if (isnan(x)) { - x = 0.0f; - } - if (isnan(y)) { - y = 0.0f; +CGPoint LedDevicePhilipsHue::CGPointMake(float x, float y) { + CGPoint p; + p.x = x; + p.y = y; + + return p; +} + +float LedDevicePhilipsHue::CrossProduct(CGPoint p1, CGPoint p2) { + return (p1.x * p2.y - p1.y * p2.x); +} + +bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint p) { + CGPoint v1 = CGPointMake(Green.x - Red.x, Green.y - Red.y); + CGPoint v2 = CGPointMake(Blue.x - Red.x, Blue.y - Red.y); + + CGPoint q = CGPointMake(p.x - Red.x, p.y - Red.y); + + float s = CrossProduct(q, v2) / CrossProduct(v1, v2); + float t = CrossProduct(v1, q) / CrossProduct(v1, v2); + if ((s >= 0.0f) && (t >= 0.0f) && (s + t <= 1.0f)) + return true; + else + return false; +} + +CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoint P) { + CGPoint AP = CGPointMake(P.x - A.x, P.y - A.y); + CGPoint AB = CGPointMake(B.x - A.x, B.y - A.y); + float ab2 = AB.x * AB.x + AB.y * AB.y; + float ap_ab = AP.x * AB.x + AP.y * AB.y; + + float t = ap_ab / ab2; + + if (t < 0.0f) + t = 0.0f; + else if (t > 1.0f) + t = 1.0f; + + return CGPointMake(A.x + AB.x * t, A.y + AB.y * t); +} + +float LedDevicePhilipsHue::GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two) { + float dx = one.x - two.x; // horizontal difference + float dy = one.y - two.y; // vertical difference + float dist = sqrt(dx * dx + dy * dy); + + return dist; +} + +void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, CGPoint *xyPoint, float &brightness) { + //Apply gamma correction. + float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); + float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); + float b = (blue > 0.04045f) ? powf((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f); + //Convert to XYZ space. + float X = r * 0.649926f + g * 0.103455f + b * 0.197109f; + float Y = r * 0.234327f + g * 0.743075f + b * 0.022598f; + float Z = r * 0.0000000f + g * 0.053077f + b * 1.035763f; + //Convert to x,y space. + float cx = X / (X + Y + Z + 0.0000001f); + float cy = Y / (X + Y + Z + 0.0000001f); + + if (isnan(cx)) + cx = 0.0f; + if (isnan(cy)) + cy = 0.0f; + + (*xyPoint).x = cx; + (*xyPoint).y = cy; + + //Check if the given XY value is within the colourreach of our lamps. + bool inReachOfLamps = CheckPointInLampsReach(*xyPoint); + + if (!inReachOfLamps) { + //It seems the colour is out of reach + //let's find the closes colour we can produce with our lamp and send this XY value out. + + //Find the closest point on each line in the triangle. + CGPoint pAB = GetClosestPointToPoint(Red, Green, *xyPoint); + CGPoint pAC = GetClosestPointToPoint(Blue, Red, *xyPoint); + CGPoint pBC = GetClosestPointToPoint(Green, Blue, *xyPoint); + + //Get the distances per point and see which point is closer to our Point. + float dAB = GetDistanceBetweenTwoPoints(*xyPoint, pAB); + float dAC = GetDistanceBetweenTwoPoints(*xyPoint, pAC); + float dBC = GetDistanceBetweenTwoPoints(*xyPoint, pBC); + + float lowest = dAB; + CGPoint closestPoint = pAB; + + if (dAC < lowest) { + lowest = dAC; + closestPoint = pAC; + } + if (dBC < lowest) { + lowest = dBC; + closestPoint = pBC; + } + + //Change the xy value to a value which is within the reach of the lamp. + (*xyPoint).x = closestPoint.x; + (*xyPoint).y = closestPoint.y; } + // Brightness is simply Y in the XYZ space. brightness = Y; } diff --git a/libsrc/leddevice/LedDevicePhilipsHue.h b/libsrc/leddevice/LedDevicePhilipsHue.h index 84e7bd35..9760b7ad 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/LedDevicePhilipsHue.h @@ -22,6 +22,11 @@ * * @author ntim (github) */ +struct CGPoint; +struct CGPoint { + float x; + float y; +}; class LedDevicePhilipsHue: public QObject, public LedDevice { Q_OBJECT public: @@ -44,7 +49,7 @@ public: /// /// @return Zero on success else negative /// - virtual int write(const std::vector & ledValues); + virtual int write(const std::vector &ledValues); /// Restores the original state of the leds. virtual int switchOff(); @@ -54,6 +59,19 @@ private slots: void restoreStates(); private: + // ModelIds + const std::vector hueBulbs = {"LCT001", "LCT002", "LCT003"}; + const std::vector livingColors = {"LLC001", "LLC005", "LLC006", "LLC007", + "LLC011", "LLC012", "LLC013", "LST001"}; + /// LivingColors color gamut triangle + CGPoint Red , Green, Blue; + + CGPoint CGPointMake(float x, float y); + float CrossProduct(CGPoint p1, CGPoint p2); + bool CheckPointInLampsReach(CGPoint p); + CGPoint GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoint P); + float GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two); + /// Array to save the light states. std::vector states; /// Ip address of the bridge @@ -65,6 +83,13 @@ private: /// Use timer to reset lights when we got into "GRABBINGMODE_OFF". QTimer timer; + std::vector oldLedValues; + std::vector modelIds; + + bool hasColorChanged(unsigned int lightId, const ColorRgb *color); + + bool checkOnStatus(QString status); + /// /// Sends a HTTP GET request (blocking). /// @@ -109,7 +134,9 @@ private: /// /// @param nLights the number of lights /// - void switchOn(unsigned int nLights); + void switchLampOn(unsigned int lightId); + + void switchLampOff(unsigned int lightId); /// /// @return true if light states have been saved. @@ -132,6 +159,6 @@ private: /// /// @param brightness converted brightness component /// - void rgbToXYBrightness(float red, float green, float blue, float& x, float& y, float& brightness); + void rgbToXYBrightness(float red, float green, float blue, CGPoint *xyPoint, float &brightness); }; From e6d39b047cc6bff6c3b526f3ae48a935f1c58f6a Mon Sep 17 00:00:00 2001 From: bimsarck Date: Sat, 12 Jul 2014 14:56:39 +0200 Subject: [PATCH 08/11] Remove unnecessary code - reenable timer Former-commit-id: b1a175a1f1e5c3a7da753240030815252b1b22bb --- libsrc/leddevice/LedDevicePhilipsHue.cpp | 67 ++++++++++-------------- libsrc/leddevice/LedDevicePhilipsHue.h | 17 +++--- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index ed549b35..1fb89e6e 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -14,16 +14,16 @@ LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string &output) : host(output.c_str()), username("newdeveloper") { http = new QHttp(host); -/* timer.setInterval(3000); + timer.setInterval(3000); timer.setSingleShot(true); - connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));*/ + connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates())); } LedDevicePhilipsHue::~LedDevicePhilipsHue() { delete http; } -int LedDevicePhilipsHue::write(const std::vector &ledValues) { +int LedDevicePhilipsHue::write(const std::vector & ledValues) { // Save light states if not done before. if (!statesSaved()) saveStates(ledValues.size()); @@ -65,15 +65,15 @@ int LedDevicePhilipsHue::write(const std::vector &ledValues) { switchLampOn(lightId); float bri; - CGPoint p = CGPointMake(0, 0); + CGPoint p = {0.0f, 0.0f}; // Scale colors from [0, 255] to [0, 1] and convert to xy space. - rgbToXYBrightness(r, g, b, &p, bri); + rgbToXYBrightness(r, g, b, p, bri); // Send adjust color and brightness command in JSON format. put(getStateRoute(lightId), QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(p.x).arg(p.y).arg(qRound(b * 255.0f))); } oldLedValues = ledValues; - //timer.start(); + timer.start(); return 0; } @@ -95,7 +95,7 @@ bool LedDevicePhilipsHue::hasColorChanged(unsigned int lightId, const ColorRgb * } int LedDevicePhilipsHue::switchOff() { - //timer.stop(); + timer.stop(); // If light states have been saved before, ... if (statesSaved()) { // ... restore them. @@ -122,7 +122,6 @@ void LedDevicePhilipsHue::put(QString route, QString content) { http->request(header, content.toAscii()); // Go into the loop until the request is finished. loop.exec(); - //std::cout << http->readAll().data() << std::endl; } QByteArray LedDevicePhilipsHue::get(QString route) { @@ -203,23 +202,15 @@ bool LedDevicePhilipsHue::statesSaved() { return !states.empty(); } -CGPoint LedDevicePhilipsHue::CGPointMake(float x, float y) { - CGPoint p; - p.x = x; - p.y = y; - - return p; -} - -float LedDevicePhilipsHue::CrossProduct(CGPoint p1, CGPoint p2) { +float LedDevicePhilipsHue::CrossProduct(CGPoint& p1, CGPoint& p2) { return (p1.x * p2.y - p1.y * p2.x); } -bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint p) { - CGPoint v1 = CGPointMake(Green.x - Red.x, Green.y - Red.y); - CGPoint v2 = CGPointMake(Blue.x - Red.x, Blue.y - Red.y); +bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint& p) { + CGPoint v1 = {Green.x - Red.x, Green.y - Red.y}; + CGPoint v2 = {Blue.x - Red.x, Blue.y - Red.y}; - CGPoint q = CGPointMake(p.x - Red.x, p.y - Red.y); + CGPoint q = {p.x - Red.x, p.y - Red.y}; float s = CrossProduct(q, v2) / CrossProduct(v1, v2); float t = CrossProduct(v1, q) / CrossProduct(v1, v2); @@ -229,9 +220,9 @@ bool LedDevicePhilipsHue::CheckPointInLampsReach(CGPoint p) { return false; } -CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoint P) { - CGPoint AP = CGPointMake(P.x - A.x, P.y - A.y); - CGPoint AB = CGPointMake(B.x - A.x, B.y - A.y); +CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint& A, CGPoint& B, CGPoint& P) { + CGPoint AP = {P.x - A.x, P.y - A.y}; + CGPoint AB = {B.x - A.x, B.y - A.y}; float ab2 = AB.x * AB.x + AB.y * AB.y; float ap_ab = AP.x * AB.x + AP.y * AB.y; @@ -242,10 +233,10 @@ CGPoint LedDevicePhilipsHue::GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoin else if (t > 1.0f) t = 1.0f; - return CGPointMake(A.x + AB.x * t, A.y + AB.y * t); + return {A.x + AB.x * t, A.y + AB.y * t}; } -float LedDevicePhilipsHue::GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two) { +float LedDevicePhilipsHue::GetDistanceBetweenTwoPoints(CGPoint& one, CGPoint& two) { float dx = one.x - two.x; // horizontal difference float dy = one.y - two.y; // vertical difference float dist = sqrt(dx * dx + dy * dy); @@ -253,7 +244,7 @@ float LedDevicePhilipsHue::GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two) return dist; } -void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, CGPoint *xyPoint, float &brightness) { +void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, CGPoint& xyPoint, float& brightness) { //Apply gamma correction. float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f); float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f); @@ -271,25 +262,25 @@ void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, if (isnan(cy)) cy = 0.0f; - (*xyPoint).x = cx; - (*xyPoint).y = cy; + xyPoint.x = cx; + xyPoint.y = cy; //Check if the given XY value is within the colourreach of our lamps. - bool inReachOfLamps = CheckPointInLampsReach(*xyPoint); + bool inReachOfLamps = CheckPointInLampsReach(xyPoint); if (!inReachOfLamps) { //It seems the colour is out of reach //let's find the closes colour we can produce with our lamp and send this XY value out. //Find the closest point on each line in the triangle. - CGPoint pAB = GetClosestPointToPoint(Red, Green, *xyPoint); - CGPoint pAC = GetClosestPointToPoint(Blue, Red, *xyPoint); - CGPoint pBC = GetClosestPointToPoint(Green, Blue, *xyPoint); + CGPoint pAB = GetClosestPointToPoint(Red, Green, xyPoint); + CGPoint pAC = GetClosestPointToPoint(Blue, Red, xyPoint); + CGPoint pBC = GetClosestPointToPoint(Green, Blue, xyPoint); //Get the distances per point and see which point is closer to our Point. - float dAB = GetDistanceBetweenTwoPoints(*xyPoint, pAB); - float dAC = GetDistanceBetweenTwoPoints(*xyPoint, pAC); - float dBC = GetDistanceBetweenTwoPoints(*xyPoint, pBC); + float dAB = GetDistanceBetweenTwoPoints(xyPoint, pAB); + float dAC = GetDistanceBetweenTwoPoints(xyPoint, pAC); + float dBC = GetDistanceBetweenTwoPoints(xyPoint, pBC); float lowest = dAB; CGPoint closestPoint = pAB; @@ -304,8 +295,8 @@ void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue, } //Change the xy value to a value which is within the reach of the lamp. - (*xyPoint).x = closestPoint.x; - (*xyPoint).y = closestPoint.y; + xyPoint.x = closestPoint.x; + xyPoint.y = closestPoint.y; } // Brightness is simply Y in the XYZ space. diff --git a/libsrc/leddevice/LedDevicePhilipsHue.h b/libsrc/leddevice/LedDevicePhilipsHue.h index 9760b7ad..11ec4abd 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/LedDevicePhilipsHue.h @@ -49,7 +49,7 @@ public: /// /// @return Zero on success else negative /// - virtual int write(const std::vector &ledValues); + virtual int write(const std::vector & ledValues); /// Restores the original state of the leds. virtual int switchOff(); @@ -59,18 +59,17 @@ private slots: void restoreStates(); private: - // ModelIds + /// Available modelIds const std::vector hueBulbs = {"LCT001", "LCT002", "LCT003"}; const std::vector livingColors = {"LLC001", "LLC005", "LLC006", "LLC007", "LLC011", "LLC012", "LLC013", "LST001"}; - /// LivingColors color gamut triangle + /// Color gamut triangle CGPoint Red , Green, Blue; - CGPoint CGPointMake(float x, float y); - float CrossProduct(CGPoint p1, CGPoint p2); - bool CheckPointInLampsReach(CGPoint p); - CGPoint GetClosestPointToPoint(CGPoint A, CGPoint B, CGPoint P); - float GetDistanceBetweenTwoPoints(CGPoint one, CGPoint two); + float CrossProduct(CGPoint& p1, CGPoint& p2); + bool CheckPointInLampsReach(CGPoint& p); + CGPoint GetClosestPointToPoint(CGPoint& A, CGPoint& B, CGPoint& P); + float GetDistanceBetweenTwoPoints(CGPoint& one, CGPoint& two); /// Array to save the light states. std::vector states; @@ -159,6 +158,6 @@ private: /// /// @param brightness converted brightness component /// - void rgbToXYBrightness(float red, float green, float blue, CGPoint *xyPoint, float &brightness); + void rgbToXYBrightness(float red, float green, float blue, CGPoint& xyPoint, float& brightness); }; From c1998da2ec91515c328d024649751c0e97083dee Mon Sep 17 00:00:00 2001 From: bimsarck Date: Sun, 13 Jul 2014 13:48:49 +0200 Subject: [PATCH 09/11] Fixes saveState feature Former-commit-id: 8158c77521727bf74875a5998c803212aece0645 --- libsrc/leddevice/LedDevicePhilipsHue.cpp | 29 ++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index 1fb89e6e..6b837eb0 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -11,7 +11,7 @@ #include #include -LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string &output) : +LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) : host(output.c_str()), username("newdeveloper") { http = new QHttp(host); timer.setInterval(3000); @@ -30,23 +30,24 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) { // Iterate through colors and set light states. unsigned int lightId = 0; for (const ColorRgb &color : ledValues) { - lightId++; // Send only request to the brigde if color changed (prevents DDOS --> 503) if (!oldLedValues.empty()) - if(!hasColorChanged(lightId, &color)) + if(!hasColorChanged(lightId, &color)) { + lightId++; continue; + } float r = color.red / 255.0f; float g = color.green / 255.0f; float b = color.blue / 255.0f; //set color gamut triangle - if(std::find(hueBulbs.begin(), hueBulbs.end(), modelIds[(lightId - 1)]) != hueBulbs.end()) { + if(std::find(hueBulbs.begin(), hueBulbs.end(), modelIds[lightId]) != hueBulbs.end()) { Red = {0.675f, 0.322f}; Green = {0.4091f, 0.518f}; Blue = {0.167f, 0.04f}; } else if (std::find(livingColors.begin(), - livingColors.end(), modelIds[(lightId - 1)]) != livingColors.end()) { + livingColors.end(), modelIds[lightId]) != livingColors.end()) { Red = {0.703f, 0.296f}; Green = {0.214f, 0.709f}; Blue = {0.139f, 0.081f}; @@ -58,10 +59,11 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) { // if color equal black, switch off lamp ... if (r == 0.0f && g == 0.0f && b == 0.0f) { switchLampOff(lightId); + lightId++; continue; } // ... and if lamp off, switch on - if (!checkOnStatus(states[(lightId - 1)])) + if (!checkOnStatus(states[lightId])) switchLampOn(lightId); float bri; @@ -71,6 +73,7 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) { // Send adjust color and brightness command in JSON format. put(getStateRoute(lightId), QString("{\"xy\": [%1, %2], \"bri\": %3}").arg(p.x).arg(p.y).arg(qRound(b * 255.0f))); + lightId++; } oldLedValues = ledValues; timer.start(); @@ -79,7 +82,7 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) { bool LedDevicePhilipsHue::hasColorChanged(unsigned int lightId, const ColorRgb *color) { bool matchFound = true; - const ColorRgb &tmpOldColor = oldLedValues[(lightId - 1)]; + const ColorRgb &tmpOldColor = oldLedValues[lightId]; if ((*color).red == tmpOldColor.red) matchFound = false; if (!matchFound && (*color).green == tmpOldColor.green) @@ -139,7 +142,7 @@ QByteArray LedDevicePhilipsHue::get(QString route) { } QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) { - return QString("lights/%1/state").arg(lightId); + return QString("lights/%1/state").arg(lightId + 1); } QString LedDevicePhilipsHue::getRoute(unsigned int lightId) { @@ -178,18 +181,20 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) { void LedDevicePhilipsHue::switchLampOn(unsigned int lightId) { put(getStateRoute(lightId), "{\"on\": true}"); - states[(lightId - 1)].replace("\"on\":false", "\"on\":true"); + states[lightId].replace("\"on\":false", "\"on\":true"); } void LedDevicePhilipsHue::switchLampOff(unsigned int lightId) { put(getStateRoute(lightId), "{\"on\": false}"); - states[(lightId - 1)].replace("\"on\":true", "\"on\":false"); + states[lightId].replace("\"on\":true", "\"on\":false"); } void LedDevicePhilipsHue::restoreStates() { - unsigned int lightId = 1; + unsigned int lightId = 0; for (QString state : states) { - put(getStateRoute(lightId), state); + if (!checkOnStatus(states[lightId])) + switchLampOn(lightId); + put(getStateRoute(lightId), states[lightId]); lightId++; } // Clear saved light states. From b6fa306df71da127323b7f9f6dc08cd78248355a Mon Sep 17 00:00:00 2001 From: Johan Date: Fri, 1 Aug 2014 10:13:40 +0200 Subject: [PATCH 10/11] Fix schema requirement for json transforms (use numbers instead of doubles to allow integer values for zero and one) Former-commit-id: f65ea81c217bbf621184152fd913d58247d9b4db --- libsrc/jsonserver/schema/schema-transform.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/jsonserver/schema/schema-transform.json b/libsrc/jsonserver/schema/schema-transform.json index a135e12f..7b939839 100644 --- a/libsrc/jsonserver/schema/schema-transform.json +++ b/libsrc/jsonserver/schema/schema-transform.json @@ -16,12 +16,12 @@ "required" : false }, "saturationGain" : { - "type" : "double", + "type" : "number", "required" : false, "minimum" : 0.0 }, "valueGain" : { - "type" : "double", + "type" : "number", "required" : false, "minimum" : 0.0 }, @@ -29,7 +29,7 @@ "type": "array", "required": false, "items" : { - "type": "double", + "type": "number", "minimum": 0.0, "maximum": 1.0 }, @@ -40,7 +40,7 @@ "type": "array", "required": false, "items" : { - "type": "double", + "type": "number", "minimum": 0.0 }, "minItems": 3, @@ -50,7 +50,7 @@ "type": "array", "required": false, "items" : { - "type": "double" + "type": "number" }, "minItems": 3, "maxItems": 3 @@ -59,7 +59,7 @@ "type": "array", "required": false, "items" : { - "type": "double" + "type": "number" }, "minItems": 3, "maxItems": 3 From 04c54ee7eb375e8d94a62bfb0b9cea0d75a799c5 Mon Sep 17 00:00:00 2001 From: poljvd Date: Mon, 18 Aug 2014 13:50:19 +0200 Subject: [PATCH 11/11] Fix typo error Former-commit-id: 664fc81f7bcfab58ac543f08725992044e51d8db --- include/utils/VideoMode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/utils/VideoMode.h b/include/utils/VideoMode.h index f5cae94f..ae727657 100644 --- a/include/utils/VideoMode.h +++ b/include/utils/VideoMode.h @@ -18,7 +18,7 @@ inline VideoMode parse3DMode(std::string videoMode) // convert to lower case std::transform(videoMode.begin(), videoMode.end(), videoMode.begin(), ::tolower); - if (videoMode == "23DTAB") + if (videoMode == "3DTAB") { return VIDEO_3DTAB; }