From 5925eb03207ea9a99cfbcde4def2452eb84a008c Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 19 Apr 2018 00:28:05 +0200 Subject: [PATCH] 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);