Redo XY Color remaining time logic.

main
MartB 2022-04-04 16:51:41 +02:00
parent 48c02b36af
commit 6c3e794bec
4 changed files with 74 additions and 48 deletions

View File

@ -501,17 +501,8 @@ void light_applyUpdate(u8 *curLevel, u16 *curLevel256, s32 *stepLevel256, u16 *r
light_fresh();
}
/*********************************************************************
* @fn light_applyUpdate_16
*
* @brief
*
* @param
*
* @return None
*/
void light_applyUpdate_16(u16 *curLevel, u32 *curLevel256, s32 *stepLevel256, u16 *remainingTime, u16 minLevel, u16 maxLevel, bool wrap)
{
void light_computeUpdate_16(u16 *curLevel, u32 *curLevel256, s32 *stepLevel256, u16 minLevel, u16 maxLevel, bool wrap) {
if ((*stepLevel256 > 0) && ((((s32)*curLevel256 + *stepLevel256) / 256) > maxLevel))
{
*curLevel256 = (wrap) ? ((u32)minLevel * 256 + ((*curLevel256 + *stepLevel256) - (u32)maxLevel * 256) - 256)
@ -535,6 +526,20 @@ void light_applyUpdate_16(u16 *curLevel, u32 *curLevel256, s32 *stepLevel256, u1
{
*curLevel = *curLevel256 / 256;
}
}
/*********************************************************************
* @fn light_applyUpdate_16
*
* @brief
*
* @param
*
* @return None
*/
void light_applyUpdate_16(u16 *curLevel, u32 *curLevel256, s32 *stepLevel256, u16 *remainingTime, u16 minLevel, u16 maxLevel, bool wrap)
{
light_computeUpdate_16(curLevel, curLevel256, stepLevel256, minLevel, maxLevel, wrap);
if (*remainingTime == 0)
{
@ -549,6 +554,38 @@ void light_applyUpdate_16(u16 *curLevel, u32 *curLevel256, s32 *stepLevel256, u1
light_fresh();
}
/*********************************************************************
* @fn light_applyXYUpdate_16
*
* @brief Updates the X and Y value (or two independent values at once)
*
* @param
*
* @return None
*/
void light_applyXYUpdate_16(u16 *curX, u32 *curX256, s32 *stepX256, u16 *curY, u32 *curY256, s32 *stepY256, u16 *remainingTime, u16 minLevel, u16 maxLevel, bool wrap)
{
// First update both components at once
light_computeUpdate_16(curX, curX256, stepX256, minLevel, maxLevel, wrap);
light_computeUpdate_16(curY, curY256, stepY256, minLevel, maxLevel, wrap);
// Then count down the single time
if (*remainingTime == 0)
{
*curX256 = ((u32)*curX) * 256;
*stepX256 = 0;
*curY256 = ((u32)*curY) * 256;
*stepY256 = 0;
}
else if (*remainingTime != 0xFFFF)
{
*remainingTime = *remainingTime - 1;
}
light_fresh();
}
/*********************************************************************
* @fn light_blink_TimerEvtCb
*

View File

@ -43,6 +43,7 @@ void light_adjust(void);
void light_fresh(void);
void light_applyUpdate(u8 *curLevel, u16 *curLevel256, s32 *stepLevel256, u16 *remainingTime, u8 minLevel, u8 maxLevel, bool wrap);
void light_applyUpdate_16(u16 *curLevel, u32 *curLevel256, s32 *stepLevel256, u16 *remainingTime, u16 minLevel, u16 maxLevel, bool wrap);
void light_applyXYUpdate_16(u16 *curX, u32 *curX256, s32 *stepX256, u16 *curY, u32 *curY256, s32 *stepY256, u16 *remainingTime, u16 minLevel, u16 maxLevel, bool wrap);
void light_blink_start(u8 times, u16 ledOnTime, u16 ledOffTime);
void light_blink_stop(void);

View File

@ -265,8 +265,8 @@ zcl_lightColorCtrlAttr_t g_zcl_colorCtrlAttrs =
.colorMode = ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS,
.options = 0,
.enhancedColorMode = ZCL_COLOR_MODE_COLOR_TEMPERATURE_MIREDS,
.colorCapabilities = ZCL_COLOR_CAPABILITIES_BIT_COLOR_TEMPERATURE | ZCL_COLOR_CAPABILITIES_BIT_X_Y_ATTRIBUTES | ZCL_COLOR_CAPABILITIES_BIT_HUE_SATURATION,
.numOfPrimaries = 0,
.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,
@ -347,9 +347,10 @@ nv_sts_t zcl_onOffAttr_save(void)
st = nv_flashReadNew(1, NV_MODULE_ZCL, NV_ITEM_ZCL_ON_OFF, sizeof(zcl_nv_onOff_t), (u8 *)&zcl_nv_onOff);
bool onOffAttrsDiffer = st == NV_ITEM_NOT_FOUND ||
(st == NV_SUCC && (zcl_nv_onOff.startUp != g_zcl_onOffAttrs.startUpOnOff || zcl_nv_onOff.lastState != g_zcl_onOffAttrs.onOff));
(st == NV_SUCC && (zcl_nv_onOff.startUp != g_zcl_onOffAttrs.startUpOnOff || zcl_nv_onOff.lastState != g_zcl_onOffAttrs.onOff));
if (onOffAttrsDiffer) {
if (onOffAttrsDiffer)
{
zcl_nv_onOff.startUp = g_zcl_onOffAttrs.startUpOnOff;
zcl_nv_onOff.lastState = g_zcl_onOffAttrs.onOff;
st = nv_flashWriteNew(1, NV_MODULE_ZCL, NV_ITEM_ZCL_ON_OFF, sizeof(zcl_nv_onOff_t), (u8 *)&zcl_nv_onOff);
@ -412,10 +413,10 @@ nv_sts_t zcl_levelAttr_save(void)
st = nv_flashReadNew(1, NV_MODULE_ZCL, NV_ITEM_ZCL_LEVEL, sizeof(zcl_nv_level_t), (u8 *)&zcl_nv_level);
bool levelAttrsNeedsUpdate = st == NV_ITEM_NOT_FOUND
|| (st == NV_SUCC && (zcl_nv_level.startUp != g_zcl_levelAttrs.startUpCurrentLevel || zcl_nv_level.lastLevel != g_zcl_levelAttrs.curLevel));
bool levelAttrsNeedsUpdate = st == NV_ITEM_NOT_FOUND || (st == NV_SUCC && (zcl_nv_level.startUp != g_zcl_levelAttrs.startUpCurrentLevel || zcl_nv_level.lastLevel != g_zcl_levelAttrs.curLevel));
if (levelAttrsNeedsUpdate) {
if (levelAttrsNeedsUpdate)
{
zcl_nv_level.startUp = g_zcl_levelAttrs.startUpCurrentLevel;
zcl_nv_level.lastLevel = g_zcl_levelAttrs.curLevel;
@ -479,10 +480,10 @@ nv_sts_t zcl_colorCtrlAttr_save(void)
zcl_lightColorCtrlAttr_t c = g_zcl_colorCtrlAttrs;
// Check if the item does not exist in nvram, or the values differ
bool colorAttrsDiffer = st == NV_ITEM_NOT_FOUND
|| (st == NV_SUCC && (nv.startUpMireds != c.startUpColorTemperatureMireds || nv.lastMireds != c.colorTemperatureMireds));
bool colorAttrsDiffer = st == NV_ITEM_NOT_FOUND || (st == NV_SUCC && (nv.startUpMireds != c.startUpColorTemperatureMireds || nv.lastMireds != c.colorTemperatureMireds));
if (colorAttrsDiffer) {
if (colorAttrsDiffer)
{
nv.startUpMireds = c.startUpColorTemperatureMireds;
nv.lastMireds = c.colorTemperatureMireds;
st = nv_flashWriteNew(1, NV_MODULE_ZCL, NV_ITEM_ZCL_COLOR_CTRL, sizeof(zcl_nv_colorCtrl_t), (u8 *)&nv);

View File

@ -224,12 +224,8 @@ static s32 sampleLight_colorTimerEvtCb(void *arg)
{
if (colorInfo.xyRemainingTime)
{
light_applyUpdate_16(&pColor->currentX, &colorInfo.currentX256, &colorInfo.stepX256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
light_applyUpdate_16(&pColor->currentY, &colorInfo.currentY256, &colorInfo.stepY256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
light_applyXYUpdate_16(&pColor->currentX, &colorInfo.currentX256, &colorInfo.stepX256, &pColor->currentY, &colorInfo.currentY256, &colorInfo.stepY256,
&colorInfo.xyRemainingTime, ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
}
}
if (colorInfo.saturationRemainingTime || colorInfo.hueRemainingTime || colorInfo.colorTempRemainingTime || colorInfo.xyRemainingTime)
@ -649,19 +645,18 @@ static void sampleLight_moveToColorProcess(zcl_colorCtrlMoveToColorCmd_t *cmd)
colorInfo.currentX256 = (u16)(pColor->currentX) << 8;
colorInfo.currentY256 = (u16)(pColor->currentY) << 8;
colorInfo.xyRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
u16 remTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.xyRemainingTime = remTime;
colorInfo.stepX256 = ((s32)(cmd->colorX - pColor->currentX)) << 8;
colorInfo.stepX256 /= (s32)colorInfo.xyRemainingTime;
colorInfo.stepX256 /= (s32)remTime;
colorInfo.stepY256 = ((s32)(cmd->colorY - pColor->currentY)) << 8;
colorInfo.stepY256 /= (s32)colorInfo.xyRemainingTime;
colorInfo.stepY256 /= (s32)remTime;
light_applyUpdate_16(&pColor->currentX, &colorInfo.currentX256, &colorInfo.stepX256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
light_applyUpdate_16(&pColor->currentY, &colorInfo.currentY256, &colorInfo.stepY256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
light_applyXYUpdate_16(&pColor->currentX, &colorInfo.currentX256, &colorInfo.stepX256,
&pColor->currentY, &colorInfo.currentY256, &colorInfo.stepY256,
&colorInfo.xyRemainingTime, ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
sampleLight_colorTimerStop();
if (colorInfo.xyRemainingTime)
@ -681,18 +676,14 @@ static void sampleLight_moveToColorProcess(zcl_colorCtrlMoveToColorCmd_t *cmd)
*/
static void sampleLight_moveColorProcess(zcl_colorCtrlMoveColorCmd_t *cmd)
{
/*
zcl_lightColorCtrlAttr_t *pColor = zcl_colorAttrGet();
sampleLight_updateColorMode(ZCL_COLOR_MODE_CURRENT_X_Y);
pColor->colorMode = ZCL_COLOR_MODE_CURRENT_X_Y;
pColor->enhancedColorMode = ZCL_COLOR_MODE_CURRENT_X_Y;
light_applyUpdate_16(&pColor->currentX, &colorInfo.currentX256, &colorInfo.stepX256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
light_applyUpdate_16(&pColor->currentY, &colorInfo.currentY256, &colorInfo.stepY256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
*/
}
/*********************************************************************
@ -706,18 +697,14 @@ static void sampleLight_moveColorProcess(zcl_colorCtrlMoveColorCmd_t *cmd)
*/
static void sampleLight_stepColorProcess(zcl_colorCtrlStepColorCmd_t *cmd)
{
/*
zcl_lightColorCtrlAttr_t *pColor = zcl_colorAttrGet();
sampleLight_updateColorMode(ZCL_COLOR_MODE_CURRENT_X_Y);
pColor->colorMode = ZCL_COLOR_MODE_CURRENT_X_Y;
pColor->enhancedColorMode = ZCL_COLOR_MODE_CURRENT_X_Y;
light_applyUpdate_16(&pColor->currentX, &colorInfo.currentX256, &colorInfo.stepX256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
light_applyUpdate_16(&pColor->currentY, &colorInfo.currentY256, &colorInfo.stepY256, &colorInfo.xyRemainingTime,
ZCL_COLOR_ATTR_XY_MIN, ZCL_COLOR_ATTR_XY_MAX, FALSE);
*/
}
/*********************************************************************