From 72d0b2bf6eb007893a533c81e75c9b1cac9a5c3b Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 18 Apr 2018 18:21:36 +0200 Subject: [PATCH 1/2] avea-colorlight interface testing --- elgato/aveabulb.cpp | 2 +- elgato/devicepluginelgato.cpp | 16 +++++++++++++++- elgato/devicepluginelgato.json | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/elgato/aveabulb.cpp b/elgato/aveabulb.cpp index cfd72330..1ab4bd16 100644 --- a/elgato/aveabulb.cpp +++ b/elgato/aveabulb.cpp @@ -205,7 +205,7 @@ bool AveaBulb::syncColor() return false; } - m_device->setStateValue(aveaBlueStateTypeId, m_white); + m_device->setStateValue(aveaWhiteStateTypeId, m_white); m_device->setStateValue(aveaRedStateTypeId, m_red); m_device->setStateValue(aveaGreenStateTypeId, m_green); m_device->setStateValue(aveaBlueStateTypeId, m_blue); diff --git a/elgato/devicepluginelgato.cpp b/elgato/devicepluginelgato.cpp index c9ba8226..f83ce11a 100644 --- a/elgato/devicepluginelgato.cpp +++ b/elgato/devicepluginelgato.cpp @@ -498,12 +498,26 @@ DeviceManager::DeviceError DevicePluginElgato::executeAction(Device *device, con device->setStateValue(aveaColorStateTypeId, color); return DeviceManager::DeviceErrorNoError; + } else if (action.actionTypeId() == aveaColorTemperatureActionTypeId) { + // (ct-153) : x = (500-153) : 255 + int ctValue = action.param(aveaColorTemperatureActionParamTypeId).value().toInt(); + int blue = (ctValue - 153) * 255 / (500-153); + int red = 255 - blue; + QColor color; + color.setRed(red); + color.setGreen(0); + color.setBlue(blue); + if (!bulb->setWhite(4095) || !bulb->setColor(color)) { + return DeviceManager::DeviceErrorHardwareNotAvailable; + } + device->setStateValue(aveaColorStateTypeId, color); + device->setStateValue(aveaColorTemperatureStateTypeId, ctValue); + return DeviceManager::DeviceErrorNoError; } else if (action.actionTypeId() == aveaWhiteActionTypeId) { int whiteValue = action.param(aveaWhiteActionParamTypeId).value().toInt(); if (!bulb->setWhite(whiteValue)) return DeviceManager::DeviceErrorHardwareNotAvailable; - device->setStateValue(aveaWhiteStateTypeId, whiteValue); return DeviceManager::DeviceErrorNoError; } else if (action.actionTypeId() == aveaGreenActionTypeId) { int greenValue = action.param(aveaGreenActionParamTypeId).value().toInt(); diff --git a/elgato/devicepluginelgato.json b/elgato/devicepluginelgato.json index 8626a936..b531d48d 100644 --- a/elgato/devicepluginelgato.json +++ b/elgato/devicepluginelgato.json @@ -14,7 +14,7 @@ "displayName": "Avea", "deviceIcon": "LightBulb", "basicTags": ["Device", "Actuator", "Lighting"], - "interfaces": ["connectable"], + "interfaces": ["connectable", "light", "colorlight"], "createMethods": ["discovery"], "paramTypes": [ { @@ -78,6 +78,19 @@ "defaultValue": "#000000", "writable": true }, + { + "id": "8932ddac-d718-4345-94aa-f4c9611f132f", + "name": "colorTemperature", + "displayName": "color temperature", + "displayNameEvent": "color temperature changed", + "displayNameAction": "Set color temperature", + "type": "int", + "unit": "Mired", + "defaultValue": 170, + "minValue": 153, + "maxValue": 500, + "writable": true + }, { "id": "50f6a224-fb8d-487d-8774-1a0536e5b1aa", "name": "white", From a73a977c7b60c36f73efedae3338e1f346499af8 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 19 Apr 2018 00:28:05 +0200 Subject: [PATCH 2/2] fade red and blue separately instead of cross-fading --- elgato/devicepluginelgato.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/elgato/devicepluginelgato.cpp b/elgato/devicepluginelgato.cpp index f83ce11a..6db65743 100644 --- a/elgato/devicepluginelgato.cpp +++ b/elgato/devicepluginelgato.cpp @@ -499,10 +499,16 @@ DeviceManager::DeviceError DevicePluginElgato::executeAction(Device *device, con device->setStateValue(aveaColorStateTypeId, color); return DeviceManager::DeviceErrorNoError; } else if (action.actionTypeId() == aveaColorTemperatureActionTypeId) { - // (ct-153) : x = (500-153) : 255 int ctValue = action.param(aveaColorTemperatureActionParamTypeId).value().toInt(); - int blue = (ctValue - 153) * 255 / (500-153); - int red = 255 - blue; + // normalize from 0 to 347 instead of 153 to 500 + int ct = ctValue - 153; + // for blue: lower half fades blue from 255 to 0 + // ct : (255-blue) = (347 / 2) : 255 + int blue = qMax(0, 255 - (ct * 255 / (347 / 2))); + // for red: upper half fades red from 0 255 + // ct - (347/2) : red = (347 / 2) : 255 + int red = qMax(0, (ct - (347/2)) * 255 / ((500-153)/2)); + QColor color; color.setRed(red); color.setGreen(0);