Compare commits

..

No commits in common. "dd198ef4c1da5ee76dea1ce6c340c05e6e9e033a" and "cde9138dcd4cdc554b68ab0a134392ffb8137eba" have entirely different histories.

5 changed files with 36 additions and 109 deletions

View File

@ -33,7 +33,7 @@
/**********************************************************************
* TIMER CONSTANTS
*/
#define ZCL_LEVEL_CHANGE_INTERVAL 20 // 50 steps a second, every 20ms
#define ZCL_LEVEL_CHANGE_INTERVAL 20 // Step 50 times a second, every 20ms
#define ZCL_COLOR_CHANGE_INTERVAL 20 // see above
#define ZCL_REMAINING_TIME_INTERVAL 100 // 1/10th of a second according to the zigbee spec

View File

@ -34,7 +34,7 @@
/**********************************************************************
* LOCAL CONSTANTS
*/
#define PWM_FREQUENCY 3000 // 3KHz
#define PWM_FREQUENCY 1000 // 1KHz
#define PWM_FULL_DUTYCYCLE 100
#define PMW_MAX_TICK (PWM_CLOCK_SOURCE / PWM_FREQUENCY)
@ -230,13 +230,13 @@ void hwLight_colorUpdate_colorTemperature(u16 colorTemperatureMireds, u8 level)
*
* @return None
*/
void hsvToRGB(u16 hue, u8 saturation, u8 level, u8 *R, u8 *G, u8 *B, bool enhanced)
void hsvToRGB(u8 hue, u8 saturation, u8 level, u8 *R, u8 *G, u8 *B)
{
u8 region;
u8 remainder;
u8 p, q, t;
u16 rHue = (u32)hue * 360 / (enhanced ? ZCL_COLOR_ATTR_ENHANCED_HUE_MAX : ZCL_COLOR_ATTR_HUE_MAX);
u16 rHue = (u16)hue * 360 / ZCL_COLOR_ATTR_HUE_MAX;
u8 rS = saturation;
u8 rV = level;
@ -309,20 +309,18 @@ void hsvToRGB(u16 hue, u8 saturation, u8 level, u8 *R, u8 *G, u8 *B, bool enhanc
* @param hue - hue attribute value
* saturation - saturation attribute value
* level - level attribute value
* bool - whether the enhanced calculation should be used or not
*
* @return None
*/
void hwLight_colorUpdate_HSV2RGB(u16 hue, u8 saturation, u8 level, bool enhanced)
void hwLight_colorUpdate_HSV2RGB(u8 hue, u8 saturation, u8 level)
{
u8 R = 0;
u8 G = 0;
u8 B = 0;
// No idea why this is here, lets see what happens with a more minimal value
level = (level < 0x01) ? 0x01 : level;
level = (level < 0x10) ? 0x10 : level;
hsvToRGB(hue, saturation, level, &R, &G, &B, enhanced);
hsvToRGB(hue, saturation, level, &R, &G, &B);
hwLight_colorUpdate_RGB(R, G, B);
}

View File

@ -35,7 +35,7 @@ void hwLight_init(void);
void hwLight_onOffUpdate(u8 onOff);
void hwLight_levelUpdate(u8 level);
void hwLight_colorUpdate_colorTemperature(u16 colorTemperatureMireds, u8 level);
void hwLight_colorUpdate_HSV2RGB(u16 hue, u8 saturation, u8 level, bool enhanced);
void hwLight_colorUpdate_HSV2RGB(u8 hue, u8 saturation, u8 level);
void hwLight_colorUpdate_RGB(u8 R, u8 G, u8 B);
void hwLight_colorUpdate_XY2RGB(u16 x, u16 y, u8 level);

View File

@ -266,7 +266,7 @@ zcl_lightColorCtrlAttr_t g_zcl_colorCtrlAttrs =
.options = 0,
.enhancedColorMode = ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS,
.numOfPrimaries = 0xFF, // 0xFF is used if the primaries are unknown
.colorCapabilities = ZCL_COLOR_CAPABILITIES_BIT_HUE_SATURATION | ZCL_COLOR_CAPABILITIES_BIT_COLOR_LOOP | ZCL_COLOR_CAPABILITIES_BIT_ENHANCED_HUE | ZCL_COLOR_CAPABILITIES_BIT_COLOR_TEMPERATURE | ZCL_COLOR_CAPABILITIES_BIT_X_Y_ATTRIBUTES,
.colorCapabilities = ZCL_COLOR_CAPABILITIES_BIT_COLOR_TEMPERATURE | ZCL_COLOR_CAPABILITIES_BIT_X_Y_ATTRIBUTES | ZCL_COLOR_CAPABILITIES_BIT_HUE_SATURATION,
.currentHue = 0x00,
.currentSaturation = 0x00,
.currentX = 0x616b,

View File

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