@@ -313,8 +313,8 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
313313 break ;
314314 case EnhancedColorMode::kCurrentXAndCurrentY :
315315#ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_XY
316- ColorControlServer::Instance ().moveToColor (colorXTransitionState-> finalValue , colorYTransitionState ->finalValue ,
317- transitionTime10th, endpoint );
316+ ColorControlServer::Instance ().moveToColor (endpoint, colorXTransitionState ->finalValue ,
317+ colorYTransitionState-> finalValue , transitionTime10th );
318318#endif // MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_XY
319319 break ;
320320 case EnhancedColorMode::kColorTemperatureMireds :
@@ -470,11 +470,9 @@ Status ColorControlServer::stopAllColorTransitions(EndpointId endpoint)
470470 return Status::Success;
471471}
472472
473- bool ColorControlServer::stopMoveStepCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
474- BitMask<OptionsBitmap> optionsMask, BitMask<OptionsBitmap> optionsOverride)
473+ Status ColorControlServer::stopMoveStepCommand (EndpointId endpoint, const Commands::StopMoveStep::DecodableType & commandData)
475474{
476- EndpointId endpoint = commandPath.mEndpointId ;
477- Status status = Status::Success;
475+ Status status = Status::Success;
478476
479477 // StopMoveStep command has no effect on an active color loop.
480478 // Fetch if it is supported and active.
@@ -488,7 +486,7 @@ bool ColorControlServer::stopMoveStepCommand(app::CommandHandler * commandObj, c
488486 }
489487 }
490488
491- if (shouldExecuteIfOff (endpoint, optionsMask, optionsOverride) && !isColorLoopActive)
489+ if (shouldExecuteIfOff (endpoint, commandData. optionsMask , commandData. optionsOverride ) && !isColorLoopActive)
492490 {
493491 status = stopAllColorTransitions (endpoint);
494492
@@ -507,8 +505,7 @@ bool ColorControlServer::stopMoveStepCommand(app::CommandHandler * commandObj, c
507505#endif // MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_HSV
508506 }
509507
510- commandObj->AddStatus (commandPath, status);
511- return true ;
508+ return status;
512509}
513510
514511bool ColorControlServer::shouldExecuteIfOff (EndpointId endpoint, BitMask<OptionsBitmap> optionMask,
@@ -2251,13 +2248,13 @@ EmberEventControl * ColorControlServer::configureXYEventControl(EndpointId endpo
22512248/* *
22522249 * @brief executes move to saturation command
22532250 *
2251+ * @param endpoint target endpoint where to execute move
22542252 * @param colorX target X
22552253 * @param colorY target Y
22562254 * @param transitionTime transition time in 10th of seconds
2257- * @param endpoint target endpoint where to execute move
22582255 * @return Status::Success if successful,Status::UnsupportedEndpoint XY is not supported on the endpoint
22592256 */
2260- Status ColorControlServer::moveToColor (uint16_t colorX, uint16_t colorY, uint16_t transitionTime, EndpointId endpoint )
2257+ Status ColorControlServer::moveToColor (EndpointId endpoint, uint16_t colorX, uint16_t colorY, uint16_t transitionTime)
22612258{
22622259 uint16_t epIndex = getEndpointIndex (endpoint);
22632260 Color16uTransitionState * colorXTransitionState = getXTransitionStateByIndex (epIndex);
@@ -2303,57 +2300,53 @@ Status ColorControlServer::moveToColor(uint16_t colorX, uint16_t colorY, uint16_
23032300 return Status::Success;
23042301}
23052302
2306- bool ColorControlServer::moveToColorCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2307- const Commands::MoveToColor::DecodableType & commandData)
2303+ /* *
2304+ * @brief executes move to color command
2305+ * @param endpoint endpointId of the recipient Color control cluster
2306+ * @param commandData Struct containing the parameters of the command
2307+ * @return Status::Success when successful,
2308+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a Color XY transition state (verified in
2309+ * moveToColor function),
2310+ */
2311+ Status ColorControlServer::moveToColorCommand (EndpointId endpoint, const Commands::MoveToColor::DecodableType & commandData)
23082312{
2309- if (!shouldExecuteIfOff (commandPath.mEndpointId , commandData.optionsMask , commandData.optionsOverride ))
2310- {
2311- commandObj->AddStatus (commandPath, Status::Success);
2312- return true ;
2313- }
2313+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
23142314
2315- Status status = moveToColor (commandData.colorX , commandData.colorY , commandData.transitionTime , commandPath. mEndpointId );
2315+ Status status = moveToColor (endpoint, commandData.colorX , commandData.colorY , commandData.transitionTime );
23162316#ifdef MATTER_DM_PLUGIN_SCENES_MANAGEMENT
2317- ScenesManagement::ScenesServer::Instance ().MakeSceneInvalidForAllFabrics (commandPath. mEndpointId );
2317+ ScenesManagement::ScenesServer::Instance ().MakeSceneInvalidForAllFabrics (endpoint );
23182318#endif // MATTER_DM_PLUGIN_SCENES_MANAGEMENT
2319- commandObj->AddStatus (commandPath, status);
2320- return true ;
2319+ return status;
23212320}
23222321
2323- bool ColorControlServer::moveColorCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2324- const Commands::MoveColor::DecodableType & commandData)
2322+ /* *
2323+ * @brief executes move color command
2324+ * @param endpoint endpointId of the recipient Color control cluster
2325+ * @param commandData Struct containing the parameters of the command
2326+ * @return Status::Success when successful,
2327+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a Color XY transition state (verified in
2328+ * moveToColor).
2329+ */
2330+ Status ColorControlServer::moveColorCommand (EndpointId endpoint, const Commands::MoveColor::DecodableType & commandData)
23252331{
2326- int16_t rateX = commandData.rateX ;
2327- int16_t rateY = commandData.rateY ;
2328- BitMask<OptionsBitmap> optionsMask = commandData.optionsMask ;
2329- BitMask<OptionsBitmap> optionsOverride = commandData.optionsOverride ;
2330- EndpointId endpoint = commandPath.mEndpointId ;
2331- Status status = Status::Success;
2332-
23332332 uint16_t epIndex = getEndpointIndex (endpoint);
23342333 Color16uTransitionState * colorXTransitionState = getXTransitionStateByIndex (epIndex);
23352334 Color16uTransitionState * colorYTransitionState = getYTransitionStateByIndex (epIndex);
2335+ VerifyOrReturnValue (colorXTransitionState != nullptr , Status::UnsupportedEndpoint);
2336+ VerifyOrReturnValue (colorYTransitionState != nullptr , Status::UnsupportedEndpoint);
23362337
2337- VerifyOrExit (colorXTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2338- VerifyOrExit (colorYTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2339-
2340- if (!shouldExecuteIfOff (endpoint, optionsMask, optionsOverride))
2341- {
2342- commandObj->AddStatus (commandPath, Status::Success);
2343- return true ;
2344- }
2338+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
23452339
23462340 uint16_t transitionTimeX, transitionTimeY;
23472341 uint16_t unsignedRate;
23482342
23492343 // New command. Need to stop any active transitions.
23502344 stopAllColorTransitions (endpoint);
23512345
2352- if (rateX == 0 && rateY == 0 )
2346+ if (commandData. rateX == 0 && commandData. rateY == 0 )
23532347 {
23542348 // any current transition has been stopped. We are done.
2355- commandObj->AddStatus (commandPath, Status::Success);
2356- return true ;
2349+ return Status::Success;
23572350 }
23582351
23592352 // Handle color mode transition, if necessary.
@@ -2362,15 +2355,15 @@ bool ColorControlServer::moveColorCommand(app::CommandHandler * commandObj, cons
23622355 // now, kick off the state machine.
23632356 Attributes::CurrentX::Get (endpoint, &(colorXTransitionState->initialValue ));
23642357 colorXTransitionState->currentValue = colorXTransitionState->initialValue ;
2365- if (rateX > 0 )
2358+ if (commandData. rateX > 0 )
23662359 {
23672360 colorXTransitionState->finalValue = MAX_CIE_XY_VALUE;
2368- unsignedRate = static_cast <uint16_t >(rateX);
2361+ unsignedRate = static_cast <uint16_t >(commandData. rateX );
23692362 }
23702363 else
23712364 {
23722365 colorXTransitionState->finalValue = MIN_CIE_XY_VALUE;
2373- unsignedRate = static_cast <uint16_t >(rateX * -1 );
2366+ unsignedRate = static_cast <uint16_t >(commandData. rateX * -1 );
23742367 }
23752368 transitionTimeX = computeTransitionTimeFromStateAndRate (colorXTransitionState, unsignedRate);
23762369 colorXTransitionState->stepsRemaining = transitionTimeX;
@@ -2383,15 +2376,15 @@ bool ColorControlServer::moveColorCommand(app::CommandHandler * commandObj, cons
23832376
23842377 Attributes::CurrentY::Get (endpoint, &(colorYTransitionState->initialValue ));
23852378 colorYTransitionState->currentValue = colorYTransitionState->initialValue ;
2386- if (rateY > 0 )
2379+ if (commandData. rateY > 0 )
23872380 {
23882381 colorYTransitionState->finalValue = MAX_CIE_XY_VALUE;
2389- unsignedRate = static_cast <uint16_t >(rateY);
2382+ unsignedRate = static_cast <uint16_t >(commandData. rateY );
23902383 }
23912384 else
23922385 {
23932386 colorYTransitionState->finalValue = MIN_CIE_XY_VALUE;
2394- unsignedRate = static_cast <uint16_t >(rateY * -1 );
2387+ unsignedRate = static_cast <uint16_t >(commandData. rateY * -1 );
23952388 }
23962389 transitionTimeY = computeTransitionTimeFromStateAndRate (colorYTransitionState, unsignedRate);
23972390 colorYTransitionState->stepsRemaining = transitionTimeY;
@@ -2406,52 +2399,36 @@ bool ColorControlServer::moveColorCommand(app::CommandHandler * commandObj, cons
24062399
24072400 // kick off the state machine:
24082401 scheduleTimerCallbackMs (configureXYEventControl (endpoint), TRANSITION_UPDATE_TIME_MS.count ());
2409-
2410- exit:
2411- commandObj->AddStatus (commandPath, status);
2412- return true ;
2402+ return Status::Success;
24132403}
24142404
2415- bool ColorControlServer::stepColorCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2416- const Commands::StepColor::DecodableType & commandData)
2405+ /* *
2406+ * @brief executes step color command
2407+ * @param endpoint endpointId of the recipient Color control cluster
2408+ * @param commandData Struct containing the parameters of the command
2409+ * @return Status::Success when successful,
2410+ * Status::InvalidCommand when a step X and Y of 0 is provided
2411+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a Color XY transition state.
2412+ */
2413+ Status ColorControlServer::stepColorCommand (EndpointId endpoint, const Commands::StepColor::DecodableType & commandData)
24172414{
2418- int16_t stepX = commandData.stepX ;
2419- int16_t stepY = commandData.stepY ;
2420- uint16_t transitionTime = commandData.transitionTime ;
2421- BitMask<OptionsBitmap> optionsMask = commandData.optionsMask ;
2422- BitMask<OptionsBitmap> optionsOverride = commandData.optionsOverride ;
2423- EndpointId endpoint = commandPath.mEndpointId ;
2424- uint16_t currentColorX = 0 ;
2425- uint16_t currentColorY = 0 ;
2426- uint16_t colorX = 0 ;
2427- uint16_t colorY = 0 ;
2428-
2429- Status status = Status::Success;
2415+ VerifyOrReturnValue (commandData.stepX != 0 || commandData.stepY != 0 , Status::InvalidCommand);
24302416
24312417 uint16_t epIndex = getEndpointIndex (endpoint);
24322418 Color16uTransitionState * colorXTransitionState = getXTransitionStateByIndex (epIndex);
24332419 Color16uTransitionState * colorYTransitionState = getYTransitionStateByIndex (epIndex);
24342420
2435- VerifyOrExit (colorXTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2436- VerifyOrExit (colorYTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2437-
2438- if (stepX == 0 && stepY == 0 )
2439- {
2440- commandObj->AddStatus (commandPath, Status::InvalidCommand);
2441- return true ;
2442- }
2443-
2444- if (!shouldExecuteIfOff (endpoint, optionsMask, optionsOverride))
2445- {
2446- commandObj->AddStatus (commandPath, Status::Success);
2447- return true ;
2448- }
2421+ VerifyOrReturnValue (colorXTransitionState != nullptr , Status::UnsupportedEndpoint);
2422+ VerifyOrReturnValue (colorYTransitionState != nullptr , Status::UnsupportedEndpoint);
2423+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
24492424
2425+ uint16_t currentColorX = 0 ;
2426+ uint16_t currentColorY = 0 ;
24502427 Attributes::CurrentX::Get (endpoint, ¤tColorX);
24512428 Attributes::CurrentY::Get (endpoint, ¤tColorY);
24522429
2453- colorX = findNewColorValueFromStep (currentColorX, stepX);
2454- colorY = findNewColorValueFromStep (currentColorY, stepY);
2430+ uint16_t colorX = findNewColorValueFromStep (currentColorX, commandData. stepX );
2431+ uint16_t colorY = findNewColorValueFromStep (currentColorY, commandData. stepY );
24552432
24562433 // New command. Need to stop any active transitions.
24572434 stopAllColorTransitions (endpoint);
@@ -2463,10 +2440,10 @@ bool ColorControlServer::stepColorCommand(app::CommandHandler * commandObj, cons
24632440 colorXTransitionState->initialValue = currentColorX;
24642441 colorXTransitionState->currentValue = currentColorX;
24652442 colorXTransitionState->finalValue = colorX;
2466- colorXTransitionState->stepsRemaining = std::max<uint16_t >(transitionTime, 1 );
2443+ colorXTransitionState->stepsRemaining = std::max<uint16_t >(commandData. transitionTime , 1 );
24672444 colorXTransitionState->stepsTotal = colorXTransitionState->stepsRemaining ;
2468- colorXTransitionState->timeRemaining = transitionTime;
2469- colorXTransitionState->transitionTime = transitionTime;
2445+ colorXTransitionState->timeRemaining = commandData. transitionTime ;
2446+ colorXTransitionState->transitionTime = commandData. transitionTime ;
24702447 colorXTransitionState->endpoint = endpoint;
24712448 colorXTransitionState->lowLimit = MIN_CIE_XY_VALUE;
24722449 colorXTransitionState->highLimit = MAX_CIE_XY_VALUE;
@@ -2476,20 +2453,17 @@ bool ColorControlServer::stepColorCommand(app::CommandHandler * commandObj, cons
24762453 colorYTransitionState->finalValue = colorY;
24772454 colorYTransitionState->stepsRemaining = colorXTransitionState->stepsRemaining ;
24782455 colorYTransitionState->stepsTotal = colorXTransitionState->stepsRemaining ;
2479- colorYTransitionState->timeRemaining = transitionTime;
2480- colorYTransitionState->transitionTime = transitionTime;
2456+ colorYTransitionState->timeRemaining = commandData. transitionTime ;
2457+ colorYTransitionState->transitionTime = commandData. transitionTime ;
24812458 colorYTransitionState->endpoint = endpoint;
24822459 colorYTransitionState->lowLimit = MIN_CIE_XY_VALUE;
24832460 colorYTransitionState->highLimit = MAX_CIE_XY_VALUE;
24842461
2485- SetQuietReportRemainingTime (endpoint, transitionTime, true /* isNewTransition */ );
2462+ SetQuietReportRemainingTime (endpoint, commandData. transitionTime , true /* isNewTransition */ );
24862463
24872464 // kick off the state machine:
2488- scheduleTimerCallbackMs (configureXYEventControl (endpoint), transitionTime ? TRANSITION_UPDATE_TIME_MS.count () : 0 );
2489-
2490- exit:
2491- commandObj->AddStatus (commandPath, status);
2492- return true ;
2465+ scheduleTimerCallbackMs (configureXYEventControl (endpoint), commandData.transitionTime ? TRANSITION_UPDATE_TIME_MS.count () : 0 );
2466+ return Status::Success;
24932467}
24942468
24952469/* *
@@ -3300,19 +3274,25 @@ bool emberAfColorControlClusterColorLoopSetCallback(app::CommandHandler * comman
33003274bool emberAfColorControlClusterMoveToColorCallback (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
33013275 const Commands::MoveToColor::DecodableType & commandData)
33023276{
3303- return ColorControlServer::Instance ().moveToColorCommand (commandObj, commandPath, commandData);
3277+ Status status = ColorControlServer::Instance ().moveToColorCommand (commandPath.mEndpointId , commandData);
3278+ commandObj->AddStatus (commandPath, status);
3279+ return true ;
33043280}
33053281
33063282bool emberAfColorControlClusterMoveColorCallback (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
33073283 const Commands::MoveColor::DecodableType & commandData)
33083284{
3309- return ColorControlServer::Instance ().moveColorCommand (commandObj, commandPath, commandData);
3285+ Status status = ColorControlServer::Instance ().moveColorCommand (commandPath.mEndpointId , commandData);
3286+ commandObj->AddStatus (commandPath, status);
3287+ return true ;
33103288}
33113289
33123290bool emberAfColorControlClusterStepColorCallback (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
33133291 const Commands::StepColor::DecodableType & commandData)
33143292{
3315- return ColorControlServer::Instance ().stepColorCommand (commandObj, commandPath, commandData);
3293+ Status status = ColorControlServer::Instance ().stepColorCommand (commandPath.mEndpointId , commandData);
3294+ commandObj->AddStatus (commandPath, status);
3295+ return true ;
33163296}
33173297
33183298#endif // MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_XY
@@ -3350,8 +3330,9 @@ void emberAfPluginLevelControlCoupledColorTempChangeCallback(EndpointId endpoint
33503330bool emberAfColorControlClusterStopMoveStepCallback (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
33513331 const Commands::StopMoveStep::DecodableType & commandData)
33523332{
3353- return ColorControlServer::Instance ().stopMoveStepCommand (commandObj, commandPath, commandData.optionsMask ,
3354- commandData.optionsOverride );
3333+ Status status = ColorControlServer::Instance ().stopMoveStepCommand (commandPath.mEndpointId , commandData);
3334+ commandObj->AddStatus (commandPath, status);
3335+ return true ;
33553336}
33563337
33573338void emberAfColorControlClusterServerInitCallback (EndpointId endpoint)
0 commit comments