|
|
|
@ -31,7 +31,6 @@
|
|
|
|
|
#include "sampleLight.h"
|
|
|
|
|
#include "sampleLightCtrl.h"
|
|
|
|
|
|
|
|
|
|
#include "app_ui.h"
|
|
|
|
|
#ifdef ZCL_LIGHT_COLOR_CONTROL
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
@ -58,10 +57,6 @@ typedef struct
|
|
|
|
|
u32 currentX256;
|
|
|
|
|
u32 currentY256;
|
|
|
|
|
u16 xyRemainingTime;
|
|
|
|
|
|
|
|
|
|
u32 currentEnhancedHue256;
|
|
|
|
|
s32 stepEnhancedHue256;
|
|
|
|
|
u16 enhancedHueRemainingTime;
|
|
|
|
|
} zcl_colorInfo_t;
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
@ -87,10 +82,6 @@ static zcl_colorInfo_t colorInfo = {
|
|
|
|
|
.currentX256 = 0,
|
|
|
|
|
.currentY256 = 0,
|
|
|
|
|
.xyRemainingTime = 0,
|
|
|
|
|
|
|
|
|
|
.currentEnhancedHue256 = 0,
|
|
|
|
|
.stepEnhancedHue256 = 0,
|
|
|
|
|
.enhancedHueRemainingTime = 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static ev_timer_event_t *colorTimerEvt = NULL;
|
|
|
|
@ -114,18 +105,18 @@ void sampleLight_colorInit(void)
|
|
|
|
|
{
|
|
|
|
|
zcl_lightColorCtrlAttr_t *pColor = zcl_colorAttrGet();
|
|
|
|
|
|
|
|
|
|
pColor->colorCapabilities = ZCL_COLOR_CAPABILITIES_BIT_HUE_SATURATION | ZCL_COLOR_CAPABILITIES_BIT_COLOR_TEMPERATURE | ZCL_COLOR_CAPABILITIES_BIT_X_Y_ATTRIBUTES;
|
|
|
|
|
|
|
|
|
|
colorInfo.currentHue256 = (u16)(pColor->currentHue) << 8;
|
|
|
|
|
colorInfo.currentSaturation256 = (u16)(pColor->currentSaturation) << 8;
|
|
|
|
|
colorInfo.currentColorTemp256 = (u32)(pColor->colorTemperatureMireds) << 8;
|
|
|
|
|
colorInfo.currentX256 = (u32)(pColor->currentX) << 8;
|
|
|
|
|
colorInfo.currentY256 = (u32)(pColor->currentY) << 8;
|
|
|
|
|
colorInfo.currentEnhancedHue256 = (u32)(pColor->enhancedCurrentHue) << 8;
|
|
|
|
|
|
|
|
|
|
colorInfo.hueRemainingTime = 0;
|
|
|
|
|
colorInfo.saturationRemainingTime = 0;
|
|
|
|
|
colorInfo.colorTempRemainingTime = 0;
|
|
|
|
|
colorInfo.colorTempRemainingTime = 1; // Start-up with a 1 second transition
|
|
|
|
|
colorInfo.xyRemainingTime = 0;
|
|
|
|
|
colorInfo.enhancedHueRemainingTime = 0;
|
|
|
|
|
|
|
|
|
|
// Startup is only defined for color temperature, so why would we load any colors here ...
|
|
|
|
|
pColor->colorMode = ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS;
|
|
|
|
@ -151,29 +142,18 @@ void sampleLight_updateColorMode(u8 colorMode)
|
|
|
|
|
{
|
|
|
|
|
zcl_lightColorCtrlAttr_t *pColor = zcl_colorAttrGet();
|
|
|
|
|
|
|
|
|
|
if (colorMode != pColor->colorMode)
|
|
|
|
|
{
|
|
|
|
|
if (colorMode == ZCL_COLOR_MODE_CURRENT_X_Y)
|
|
|
|
|
{
|
|
|
|
|
led_off(LED_STATUS_R);
|
|
|
|
|
led_on(LED_STATUS_G);
|
|
|
|
|
led_off(LED_STATUS_B);
|
|
|
|
|
}
|
|
|
|
|
else if (colorMode == ZCL_COLOR_MODE_CURRENT_HUE_SATURATION)
|
|
|
|
|
{
|
|
|
|
|
if (pColor->enhancedColorMode == ZCL_ENHANCED_COLOR_MODE_CURRENT_HUE_SATURATION) {
|
|
|
|
|
led_on(LED_STATUS_G);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
led_off(LED_STATUS_R);
|
|
|
|
|
led_off(LED_STATUS_G);
|
|
|
|
|
led_on(LED_STATUS_B);
|
|
|
|
|
}
|
|
|
|
|
else if (colorMode == ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS)
|
|
|
|
|
{
|
|
|
|
|
led_on(LED_STATUS_R);
|
|
|
|
|
led_off(LED_STATUS_G);
|
|
|
|
|
led_off(LED_STATUS_B);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
@ -194,11 +174,9 @@ void sampleLight_updateColor(void)
|
|
|
|
|
{
|
|
|
|
|
hwLight_colorUpdate_XY2RGB(pColor->currentX, pColor->currentY, pLevel->curLevel);
|
|
|
|
|
}
|
|
|
|
|
else if (pColor->colorMode == ZCL_COLOR_MODE_CURRENT_HUE_SATURATION)
|
|
|
|
|
else if (pColor->colorMode == ZCL_COLOR_MODE_CURRENT_HUE_SATURATION || pColor->enhancedColorMode == ZCL_ENHANCED_COLOR_MODE_CURRENT_HUE_SATURATION)
|
|
|
|
|
{
|
|
|
|
|
// If we are in the enhanced mode, we have to make use of the enhanced hue values!
|
|
|
|
|
bool enhanced = pColor->enhancedColorMode == ZCL_ENHANCED_COLOR_MODE_CURRENT_HUE_SATURATION;
|
|
|
|
|
hwLight_colorUpdate_HSV2RGB(enhanced ? pColor->enhancedCurrentHue : pColor->currentHue, pColor->currentSaturation, pLevel->curLevel, enhanced);
|
|
|
|
|
hwLight_colorUpdate_HSV2RGB(pColor->currentHue, pColor->currentSaturation, pLevel->curLevel);
|
|
|
|
|
}
|
|
|
|
|
else if (pColor->colorMode == ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS)
|
|
|
|
|
{
|
|
|
|
@ -219,8 +197,8 @@ static s32 sampleLight_colorTimerEvtCb(void *arg)
|
|
|
|
|
{
|
|
|
|
|
zcl_lightColorCtrlAttr_t *pColor = zcl_colorAttrGet();
|
|
|
|
|
|
|
|
|
|
if ((pColor->enhancedColorMode == ZCL_COLOR_MODE_CURRENT_HUE_SATURATION) ||
|
|
|
|
|
(pColor->enhancedColorMode == ZCL_ENHANCED_COLOR_MODE_CURRENT_HUE_SATURATION))
|
|
|
|
|
if ((pColor->colorMode == ZCL_COLOR_MODE_CURRENT_HUE_SATURATION) ||
|
|
|
|
|
(pColor->colorMode == ZCL_ENHANCED_COLOR_MODE_CURRENT_HUE_SATURATION))
|
|
|
|
|
{
|
|
|
|
|
if (colorInfo.saturationRemainingTime)
|
|
|
|
|
{
|
|
|
|
@ -233,14 +211,8 @@ static s32 sampleLight_colorTimerEvtCb(void *arg)
|
|
|
|
|
light_applyUpdate(&pColor->currentHue, &colorInfo.currentHue256, &colorInfo.stepHue256, &colorInfo.hueRemainingTime,
|
|
|
|
|
ZCL_COLOR_ATTR_HUE_MIN, ZCL_COLOR_ATTR_HUE_MAX, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (colorInfo.enhancedHueRemainingTime)
|
|
|
|
|
{
|
|
|
|
|
light_applyUpdate_16(&pColor->enhancedCurrentHue, &colorInfo.currentEnhancedHue256, &colorInfo.stepEnhancedHue256, &colorInfo.enhancedHueRemainingTime,
|
|
|
|
|
ZCL_COLOR_ATTR_ENHANCED_HUE_MIN, ZCL_COLOR_ATTR_ENHANCED_HUE_MAX, TRUE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (pColor->enhancedColorMode == ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS)
|
|
|
|
|
else if (pColor->colorMode == ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS)
|
|
|
|
|
{
|
|
|
|
|
if (colorInfo.colorTempRemainingTime)
|
|
|
|
|
{
|
|
|
|
@ -248,7 +220,7 @@ static s32 sampleLight_colorTimerEvtCb(void *arg)
|
|
|
|
|
colorInfo.colorTempMinMireds, colorInfo.colorTempMaxMireds, FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (pColor->enhancedColorMode == ZCL_COLOR_MODE_CURRENT_X_Y)
|
|
|
|
|
else if (pColor->colorMode == ZCL_COLOR_MODE_CURRENT_X_Y)
|
|
|
|
|
{
|
|
|
|
|
if (colorInfo.xyRemainingTime)
|
|
|
|
|
{
|
|
|
|
@ -256,8 +228,7 @@ static s32 sampleLight_colorTimerEvtCb(void *arg)
|
|
|
|
|
&colorInfo.xyRemainingTime, ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (colorInfo.saturationRemainingTime || colorInfo.hueRemainingTime || colorInfo.enhancedHueRemainingTime || colorInfo.colorTempRemainingTime || colorInfo.xyRemainingTime)
|
|
|
|
|
if (colorInfo.saturationRemainingTime || colorInfo.hueRemainingTime || colorInfo.colorTempRemainingTime || colorInfo.xyRemainingTime)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -503,16 +474,14 @@ static void sampleLight_stepHueProcess(zcl_colorCtrlStepHueCmd_t *cmd)
|
|
|
|
|
*
|
|
|
|
|
* @return None
|
|
|
|
|
*/
|
|
|
|
|
static void sampleLight_moveToSaturationProcess(zcl_colorCtrlMoveToSaturationCmd_t *cmd, bool preserveMode)
|
|
|
|
|
static void sampleLight_moveToSaturationProcess(zcl_colorCtrlMoveToSaturationCmd_t *cmd)
|
|
|
|
|
{
|
|
|
|
|
zcl_lightColorCtrlAttr_t *pColor = zcl_colorAttrGet();
|
|
|
|
|
|
|
|
|
|
if (!preserveMode)
|
|
|
|
|
{
|
|
|
|
|
sampleLight_updateColorMode(ZCL_COLOR_MODE_CURRENT_HUE_SATURATION);
|
|
|
|
|
|
|
|
|
|
pColor->colorMode = ZCL_COLOR_MODE_CURRENT_HUE_SATURATION;
|
|
|
|
|
pColor->enhancedColorMode = ZCL_COLOR_MODE_CURRENT_HUE_SATURATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
colorInfo.currentSaturation256 = (u16)(pColor->currentSaturation) << 8;
|
|
|
|
|
|
|
|
|
@ -646,7 +615,7 @@ static void sampleLight_moveToHueAndSaturationProcess(zcl_colorCtrlMoveToHueAndS
|
|
|
|
|
moveToSaturationCmd.transitionTime = cmd->transitionTime;
|
|
|
|
|
|
|
|
|
|
sampleLight_moveToHueProcess(&moveToHueCmd);
|
|
|
|
|
sampleLight_moveToSaturationProcess(&moveToSaturationCmd, false);
|
|
|
|
|
sampleLight_moveToSaturationProcess(&moveToSaturationCmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -756,59 +725,19 @@ static void sampleLight_enhancedMoveToHueProcess(zcl_colorCtrlEnhancedMoveToHueC
|
|
|
|
|
pColor->colorMode = ZCL_COLOR_MODE_CURRENT_HUE_SATURATION;
|
|
|
|
|
pColor->enhancedColorMode = ZCL_ENHANCED_COLOR_MODE_CURRENT_HUE_SATURATION;
|
|
|
|
|
|
|
|
|
|
colorInfo.currentEnhancedHue256 = (u32)(pColor->enhancedCurrentHue) << 8;
|
|
|
|
|
s32 hueDiff = (s32)cmd->enhancedHue - pColor->enhancedCurrentHue;
|
|
|
|
|
|
|
|
|
|
switch (cmd->direction)
|
|
|
|
|
{
|
|
|
|
|
case COLOR_CTRL_DIRECTION_SHORTEST_DISTANCE:
|
|
|
|
|
if (hueDiff > (ZCL_COLOR_ATTR_ENHANCED_HUE_MAX / 2))
|
|
|
|
|
{
|
|
|
|
|
hueDiff -= (ZCL_COLOR_ATTR_ENHANCED_HUE_MAX + 1);
|
|
|
|
|
}
|
|
|
|
|
else if (hueDiff < -ZCL_COLOR_ATTR_ENHANCED_HUE_MAX / 2)
|
|
|
|
|
{
|
|
|
|
|
hueDiff += (ZCL_COLOR_ATTR_ENHANCED_HUE_MAX + 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case COLOR_CTRL_DIRECTION_LONGEST_DISTANCE:
|
|
|
|
|
if ((hueDiff > 0) && (hueDiff < (ZCL_COLOR_ATTR_ENHANCED_HUE_MAX / 2)))
|
|
|
|
|
{
|
|
|
|
|
hueDiff -= (ZCL_COLOR_ATTR_ENHANCED_HUE_MAX + 1);
|
|
|
|
|
}
|
|
|
|
|
else if ((hueDiff < 0) && (hueDiff > -ZCL_COLOR_ATTR_ENHANCED_HUE_MAX / 2))
|
|
|
|
|
{
|
|
|
|
|
hueDiff += (ZCL_COLOR_ATTR_ENHANCED_HUE_MAX + 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case COLOR_CTRL_DIRECTION_UP:
|
|
|
|
|
if (hueDiff < 0)
|
|
|
|
|
{
|
|
|
|
|
hueDiff += ZCL_COLOR_ATTR_ENHANCED_HUE_MAX;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case COLOR_CTRL_DIRECTION_DOWN:
|
|
|
|
|
if (hueDiff > 0)
|
|
|
|
|
{
|
|
|
|
|
hueDiff -= ZCL_COLOR_ATTR_ENHANCED_HUE_MAX;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
colorInfo.enhancedHueRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
|
|
|
|
|
colorInfo.stepEnhancedHue256 = ((s32)hueDiff) << 8;
|
|
|
|
|
colorInfo.stepEnhancedHue256 /= (s32)colorInfo.enhancedHueRemainingTime;
|
|
|
|
|
|
|
|
|
|
light_applyUpdate_16(&pColor->enhancedCurrentHue, &colorInfo.currentEnhancedHue256, &colorInfo.stepEnhancedHue256, &colorInfo.enhancedHueRemainingTime,
|
|
|
|
|
ZCL_COLOR_ATTR_ENHANCED_HUE_MIN, ZCL_COLOR_ATTR_ENHANCED_HUE_MAX, TRUE);
|
|
|
|
|
|
|
|
|
|
sampleLight_colorTimerStop();
|
|
|
|
|
if (colorInfo.enhancedHueRemainingTime)
|
|
|
|
|
{
|
|
|
|
|
colorTimerEvt = TL_ZB_TIMER_SCHEDULE(sampleLight_colorTimerEvtCb, NULL, ZCL_COLOR_CHANGE_INTERVAL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
@ -892,8 +821,8 @@ static void sampleLight_enhancedMoveToHueAndSaturationProcess(zcl_colorCtrlEnhan
|
|
|
|
|
moveToSaturationCmd.saturation = cmd->saturation;
|
|
|
|
|
moveToSaturationCmd.transitionTime = cmd->transitionTime;
|
|
|
|
|
|
|
|
|
|
sampleLight_moveToSaturationProcess(&moveToSaturationCmd, true);
|
|
|
|
|
sampleLight_enhancedMoveToHueProcess(&enhancedMoveToHueCmd);
|
|
|
|
|
sampleLight_moveToSaturationProcess(&moveToSaturationCmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
@ -1158,7 +1087,7 @@ status_t sampleLight_colorCtrlCb(zclIncomingAddrInfo_t *pAddrInfo, u8 cmdId, voi
|
|
|
|
|
sampleLight_stepHueProcess((zcl_colorCtrlStepHueCmd_t *)cmdPayload);
|
|
|
|
|
break;
|
|
|
|
|
case ZCL_CMD_LIGHT_COLOR_CONTROL_MOVE_TO_SATURATION:
|
|
|
|
|
sampleLight_moveToSaturationProcess((zcl_colorCtrlMoveToSaturationCmd_t *)cmdPayload, false);
|
|
|
|
|
sampleLight_moveToSaturationProcess((zcl_colorCtrlMoveToSaturationCmd_t *)cmdPayload);
|
|
|
|
|
break;
|
|
|
|
|
case ZCL_CMD_LIGHT_COLOR_CONTROL_MOVE_SATURATION:
|
|
|
|
|
sampleLight_moveSaturationProcess((zcl_colorCtrlMoveSaturationCmd_t *)cmdPayload);
|
|
|
|
|