Fix time stepping in interpolation, change broke time accuracy

Add back enhanced hue, causes read errors otherwise
main
MartB 2022-04-04 16:56:02 +02:00
parent 6c3e794bec
commit 358dc29ff7
4 changed files with 17 additions and 10 deletions

View File

@ -35,6 +35,11 @@
*/
#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
// Map the required time to our internal steps
#define INTERP_STEPS_FROM_REM_TIME(remTime, base) ((remTime * ZCL_REMAINING_TIME_INTERVAL)/base)
/**********************************************************************
* TYPEDEFS

View File

@ -271,6 +271,7 @@ zcl_lightColorCtrlAttr_t g_zcl_colorCtrlAttrs =
.currentSaturation = 0x00,
.currentX = 0x616b,
.currentY = 0x607d,
.enhancedCurrentHue = 0x0000,
.colorLoopActive = 0x00,
.colorLoopDirection = 0x00,
.colorLoopTime = 0x0019,
@ -292,6 +293,7 @@ const zclAttrInfo_t lightColorCtrl_attrTbl[] =
{ZCL_ATTRID_CURRENT_X, ZCL_DATA_TYPE_UINT16, ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, (u8 *)&g_zcl_colorCtrlAttrs.currentX},
{ZCL_ATTRID_CURRENT_Y, ZCL_DATA_TYPE_UINT16, ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, (u8 *)&g_zcl_colorCtrlAttrs.currentY},
{ZCL_ATTRID_CURRENT_HUE, ZCL_DATA_TYPE_UINT8, ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, (u8 *)&g_zcl_colorCtrlAttrs.currentHue},
{ZCL_ATTRID_ENHANCED_CURRENT_HUE, ZCL_DATA_TYPE_UINT16, ACCESS_CONTROL_READ, (u8 *)&g_zcl_colorCtrlAttrs.enhancedCurrentHue},
{ZCL_ATTRID_CURRENT_SATURATION, ZCL_DATA_TYPE_UINT8, ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, (u8 *)&g_zcl_colorCtrlAttrs.currentSaturation},
{ZCL_ATTRID_COLOR_LOOP_ACTIVE, ZCL_DATA_TYPE_UINT8, ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, (u8 *)&g_zcl_colorCtrlAttrs.colorLoopActive},
{ZCL_ATTRID_COLOR_LOOP_DIRECTION, ZCL_DATA_TYPE_UINT8, ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, (u8 *)&g_zcl_colorCtrlAttrs.colorLoopDirection},
@ -385,7 +387,7 @@ nv_sts_t zcl_onOffAttr_restore(void)
{
return st;
}
g_zcl_onOffAttrs.startUpOnOff = zcl_nv_onOff.startUp;
g_zcl_onOffAttrs.onOff = zcl_nv_onOff.lastState;
#else

View File

@ -358,7 +358,7 @@ static void sampleLight_moveToHueProcess(zcl_colorCtrlMoveToHueCmd_t *cmd)
break;
}
colorInfo.hueRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.hueRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.stepHue256 = ((s32)hueDiff) << 8;
colorInfo.stepHue256 /= (s32)colorInfo.hueRemainingTime;
@ -440,7 +440,7 @@ static void sampleLight_stepHueProcess(zcl_colorCtrlStepHueCmd_t *cmd)
colorInfo.currentHue256 = (u16)(pColor->currentHue) << 8;
colorInfo.hueRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.hueRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.stepHue256 = (((s32)cmd->stepSize) << 8) / colorInfo.hueRemainingTime;
@ -485,7 +485,7 @@ static void sampleLight_moveToSaturationProcess(zcl_colorCtrlMoveToSaturationCmd
colorInfo.currentSaturation256 = (u16)(pColor->currentSaturation) << 8;
colorInfo.saturationRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.saturationRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.stepSaturation256 = ((s32)(cmd->saturation - pColor->currentSaturation)) << 8;
colorInfo.stepSaturation256 /= (s32)colorInfo.saturationRemainingTime;
@ -568,7 +568,7 @@ static void sampleLight_stepSaturationProcess(zcl_colorCtrlStepSaturationCmd_t *
colorInfo.currentSaturation256 = (u16)(pColor->currentSaturation) << 8;
colorInfo.saturationRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.saturationRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.stepSaturation256 = (((s32)cmd->stepSize) << 8) / colorInfo.saturationRemainingTime;
@ -645,7 +645,7 @@ static void sampleLight_moveToColorProcess(zcl_colorCtrlMoveToColorCmd_t *cmd)
colorInfo.currentX256 = (u16)(pColor->currentX) << 8;
colorInfo.currentY256 = (u16)(pColor->currentY) << 8;
u16 remTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
u16 remTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.xyRemainingTime = remTime;
colorInfo.stepX256 = ((s32)(cmd->colorX - pColor->currentX)) << 8;
@ -892,7 +892,7 @@ static void sampleLight_moveToColorTemperatureProcess(zcl_colorCtrlMoveToColorTe
colorInfo.currentColorTemp256 = (u32)(pColor->colorTemperatureMireds) << 8;
colorInfo.colorTempRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.colorTempRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.stepColorTemp256 = ((s32)(cmd->colorTemperature - pColor->colorTemperatureMireds)) << 8;
colorInfo.stepColorTemp256 /= (s32)colorInfo.colorTempRemainingTime;
@ -1015,7 +1015,7 @@ static void sampleLight_stepColorTemperatureProcess(zcl_colorCtrlStepColorTemper
colorInfo.currentColorTemp256 = (u32)(pColor->colorTemperatureMireds) << 8;
colorInfo.colorTempRemainingTime = (cmd->transitionTime == 0) ? 1 : cmd->transitionTime;
colorInfo.colorTempRemainingTime = (cmd->transitionTime == 0) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_COLOR_CHANGE_INTERVAL);
colorInfo.stepColorTemp256 = (((s32)cmd->stepSize) << 8) / colorInfo.colorTempRemainingTime;

View File

@ -164,7 +164,7 @@ static void sampleLight_moveToLevelProcess(u8 cmdId, moveToLvl_t *cmd)
{
zcl_levelAttr_t *pLevel = zcl_levelAttrGet();
pLevel->remainingTime = ((cmd->transitionTime == 0) || (cmd->transitionTime == 0xFFFF)) ? 1 : cmd->transitionTime;
pLevel->remainingTime = ((cmd->transitionTime == 0) || (cmd->transitionTime == 0xFFFF)) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_LEVEL_CHANGE_INTERVAL);
levelInfo.withOnOff = (cmdId == ZCL_CMD_LEVEL_MOVE_TO_LEVEL_WITH_ON_OFF) ? TRUE : FALSE;
levelInfo.currentLevel256 = (u16)(pLevel->curLevel) << 8;
@ -280,7 +280,7 @@ static void sampleLight_stepProcess(u8 cmdId, step_t *cmd)
{
zcl_levelAttr_t *pLevel = zcl_levelAttrGet();
pLevel->remainingTime = ((cmd->transitionTime == 0) || (cmd->transitionTime == 0xFFFF)) ? 1 : cmd->transitionTime;
pLevel->remainingTime = ((cmd->transitionTime == 0) || (cmd->transitionTime == 0xFFFF)) ? 1 : INTERP_STEPS_FROM_REM_TIME(cmd->transitionTime, ZCL_LEVEL_CHANGE_INTERVAL);
levelInfo.withOnOff = (cmdId == ZCL_CMD_LEVEL_STEP_WITH_ON_OFF) ? TRUE : FALSE;
levelInfo.currentLevel256 = (u16)(pLevel->curLevel) << 8;