@@ -2431,12 +2431,12 @@ ColorControlServer::Color16uTransitionState * ColorControlServer::getTempTransit
2431
2431
}
2432
2432
2433
2433
/* *
2434
- * @brief executes move to color temp logic
2434
+ * @brief Executes move to color temp logic.
2435
2435
*
2436
2436
* @param aEndpoint
2437
2437
* @param colorTemperature
2438
2438
* @param transitionTime
2439
- * @return Status::Success if successful, Status::UnsupportedEndpoint if the endpoint doesn't support color temperature
2439
+ * @return Status::Success if successful, Status::UnsupportedEndpoint if the endpoint doesn't support color temperature.
2440
2440
*/
2441
2441
Status ColorControlServer::moveToColorTemp (EndpointId aEndpoint, uint16_t colorTemperature, uint16_t transitionTime)
2442
2442
{
@@ -2632,49 +2632,28 @@ void ColorControlServer::updateTempCommand(EndpointId endpoint)
2632
2632
}
2633
2633
2634
2634
/* *
2635
- * @brief move color temp command
2636
- *
2637
- * @param moveMode
2638
- * @param rate
2639
- * @param colorTemperatureMinimum
2640
- * @param colorTemperatureMaximum
2641
- * @param optionsMask
2642
- * @param optionsOverride
2643
- * @return true
2644
- * @return false
2635
+ * @brief Executes move color temp command.
2636
+ * @param endpoint EndpointId of the recipient Color control cluster.
2637
+ * @param commandData Struct containing the parameters of the command.
2638
+ * @return Status::Success when successful,
2639
+ * Status::InvalidCommand when a rate of 0 for a non-stop move or an unknown HueMoveMode is provided
2640
+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a color temp transition state.
2645
2641
*/
2646
- bool ColorControlServer::moveColorTempCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2647
- const Commands::MoveColorTemperature::DecodableType & commandData)
2648
- {
2649
- auto moveMode = commandData.moveMode ;
2650
- uint16_t rate = commandData.rate ;
2651
- uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
2652
- uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
2653
- BitMask<OptionsBitmap> optionsMask = commandData.optionsMask ;
2654
- BitMask<OptionsBitmap> optionsOverride = commandData.optionsOverride ;
2655
- EndpointId endpoint = commandPath.mEndpointId ;
2656
- Status status = Status::Success;
2657
- uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2658
- uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2659
- uint16_t transitionTime;
2660
-
2661
- Color16uTransitionState * colorTempTransitionState = getTempTransitionState (endpoint);
2662
- VerifyOrExit (colorTempTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2663
-
2642
+ Status ColorControlServer::moveColorTempCommand (EndpointId endpoint,
2643
+ const Commands::MoveColorTemperature::DecodableType & commandData)
2644
+ {
2664
2645
// check moveMode and rate before any operation is done on the transition states
2665
2646
// rate value is ignored if the MoveMode is stop
2666
- if (moveMode == HueMoveMode::kUnknownEnumValue || (rate == 0 && moveMode != HueMoveMode::kStop ))
2667
- {
2668
- commandObj->AddStatus (commandPath, Status::InvalidCommand);
2669
- return true ;
2670
- }
2647
+ VerifyOrReturnValue (commandData.moveMode != HueMoveMode::kUnknownEnumValue , Status::InvalidCommand);
2648
+ VerifyOrReturnValue ((commandData.rate != 0 || commandData.moveMode == HueMoveMode::kStop ), Status::InvalidCommand);
2671
2649
2672
- if (!shouldExecuteIfOff (endpoint, optionsMask, optionsOverride))
2673
- {
2674
- commandObj->AddStatus (commandPath, Status::Success);
2675
- return true ;
2676
- }
2650
+ Color16uTransitionState * colorTempTransitionState = getTempTransitionState (endpoint);
2651
+ VerifyOrReturnValue (colorTempTransitionState != nullptr , Status::UnsupportedEndpoint);
2677
2652
2653
+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
2654
+
2655
+ uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2656
+ uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2678
2657
Attributes::ColorTempPhysicalMinMireds::Get (endpoint, &tempPhysicalMin);
2679
2658
Attributes::ColorTempPhysicalMaxMireds::Get (endpoint, &tempPhysicalMax);
2680
2659
@@ -2683,22 +2662,20 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
2683
2662
2684
2663
// New command. Need to stop any active transitions.
2685
2664
stopAllColorTransitions (endpoint);
2686
-
2687
- if (moveMode == HueMoveMode::kStop )
2688
- {
2689
- commandObj->AddStatus (commandPath, Status::Success);
2690
- return true ;
2691
- }
2665
+ // For HueMoveMode::kStop we are done here.
2666
+ VerifyOrReturnValue (commandData.moveMode != HueMoveMode::kStop , Status::Success);
2692
2667
2693
2668
// Per spec, colorTemperatureMinimumMireds field is limited to ColorTempPhysicalMinMireds and
2694
2669
// when colorTemperatureMinimumMireds field is 0, ColorTempPhysicalMinMireds shall be used (always > 0)
2670
+ uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
2695
2671
if (colorTemperatureMinimum < tempPhysicalMin)
2696
2672
{
2697
2673
colorTemperatureMinimum = tempPhysicalMin;
2698
2674
}
2699
2675
2700
2676
// Per spec, colorTemperatureMaximumMireds field is limited to ColorTempPhysicalMaxMireds and
2701
2677
// when colorTemperatureMaximumMireds field is 0, ColorTempPhysicalMaxMireds shall be used
2678
+ uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
2702
2679
if ((colorTemperatureMaximum == 0 ) || (colorTemperatureMaximum > tempPhysicalMax))
2703
2680
{
2704
2681
colorTemperatureMaximum = tempPhysicalMax;
@@ -2712,7 +2689,7 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
2712
2689
Attributes::ColorTemperatureMireds::Get (endpoint, &colorTempTransitionState->initialValue );
2713
2690
colorTempTransitionState->currentValue = colorTempTransitionState->initialValue ;
2714
2691
2715
- if (moveMode == HueMoveMode::kUp )
2692
+ if (commandData. moveMode == HueMoveMode::kUp )
2716
2693
{
2717
2694
if (tempPhysicalMax > colorTemperatureMaximum)
2718
2695
{
@@ -2734,7 +2711,8 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
2734
2711
colorTempTransitionState->finalValue = tempPhysicalMin;
2735
2712
}
2736
2713
}
2737
- transitionTime = computeTransitionTimeFromStateAndRate (colorTempTransitionState, rate);
2714
+
2715
+ uint16_t transitionTime = computeTransitionTimeFromStateAndRate (colorTempTransitionState, commandData.rate );
2738
2716
colorTempTransitionState->stepsRemaining = transitionTime;
2739
2717
colorTempTransitionState->stepsTotal = transitionTime;
2740
2718
colorTempTransitionState->timeRemaining = transitionTime;
@@ -2747,63 +2725,54 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj,
2747
2725
2748
2726
// kick off the state machine:
2749
2727
scheduleTimerCallbackMs (configureTempEventControl (endpoint), TRANSITION_UPDATE_TIME_MS.count ());
2750
-
2751
- exit :
2752
- commandObj->AddStatus (commandPath, status);
2753
- return true ;
2728
+ return Status::Success;
2754
2729
}
2755
2730
2756
- bool ColorControlServer::moveToColorTempCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2757
- const Commands::MoveToColorTemperature::DecodableType & commandData)
2731
+ /* *
2732
+ * @brief Executes move to color temp command.
2733
+ * @param endpoint EndpointId of the recipient Color control cluster.
2734
+ * @param commandData Struct containing the parameters of the command.
2735
+ * @return Status::Success when successful,
2736
+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a color XY transition state (verified in
2737
+ * moveToColorTemp function).
2738
+ */
2739
+ Status ColorControlServer::moveToColorTempCommand (EndpointId endpoint,
2740
+ const Commands::MoveToColorTemperature::DecodableType & commandData)
2758
2741
{
2759
- if (!shouldExecuteIfOff (commandPath.mEndpointId , commandData.optionsMask , commandData.optionsOverride ))
2760
- {
2761
- commandObj->AddStatus (commandPath, Status::Success);
2762
- return true ;
2763
- }
2742
+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
2764
2743
2765
- Status status = moveToColorTemp (commandPath. mEndpointId , commandData.colorTemperatureMireds , commandData.transitionTime );
2744
+ Status status = moveToColorTemp (endpoint , commandData.colorTemperatureMireds , commandData.transitionTime );
2766
2745
#ifdef MATTER_DM_PLUGIN_SCENES_MANAGEMENT
2767
- ScenesManagement::ScenesServer::Instance ().MakeSceneInvalidForAllFabrics (commandPath. mEndpointId );
2746
+ ScenesManagement::ScenesServer::Instance ().MakeSceneInvalidForAllFabrics (endpoint );
2768
2747
#endif // MATTER_DM_PLUGIN_SCENES_MANAGEMENT
2769
- commandObj->AddStatus (commandPath, status);
2770
- return true ;
2748
+ return status;
2771
2749
}
2772
2750
2773
- bool ColorControlServer::stepColorTempCommand (app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
2774
- const Commands::StepColorTemperature::DecodableType & commandData)
2751
+ /* *
2752
+ * @brief Executes step color temp command.
2753
+ * @param endpoint EndpointId of the recipient Color control cluster.
2754
+ * @param commandData Struct containing the parameters of the command
2755
+ * @return Status::Success when successful,
2756
+ * Status::InvalidCommand when stepSize is 0 or an unknown stepMode is provided
2757
+ * Status::UnsupportedEndpoint when the provided endpoint doesn't correspond with a color temp transition state.
2758
+ */
2759
+ Status ColorControlServer::stepColorTempCommand (EndpointId endpoint,
2760
+ const Commands::StepColorTemperature::DecodableType & commandData)
2775
2761
{
2776
- auto stepMode = commandData.stepMode ;
2777
- uint16_t stepSize = commandData.stepSize ;
2778
- uint16_t transitionTime = commandData.transitionTime ;
2779
- uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
2780
- uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
2781
- BitMask<OptionsBitmap> optionsMask = commandData.optionsMask ;
2782
- BitMask<OptionsBitmap> optionsOverride = commandData.optionsOverride ;
2783
- EndpointId endpoint = commandPath.mEndpointId ;
2784
- Status status = Status::Success;
2785
- uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2786
- uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2762
+ // Confirm validity of the step mode and step size received
2763
+ VerifyOrReturnValue (commandData.stepMode != HueStepMode::kUnknownEnumValue , Status::InvalidCommand);
2764
+ VerifyOrReturnValue (commandData.stepSize != 0 , Status::InvalidCommand);
2787
2765
2788
2766
Color16uTransitionState * colorTempTransitionState = getTempTransitionState (endpoint);
2789
- VerifyOrExit (colorTempTransitionState != nullptr , status = Status::UnsupportedEndpoint);
2767
+ VerifyOrReturnValue (colorTempTransitionState != nullptr , Status::UnsupportedEndpoint);
2790
2768
2791
- // Confirm validity of the step mode and step size received
2792
- if (stepMode == HueStepMode::kUnknownEnumValue || stepSize == 0 )
2793
- {
2794
- commandObj->AddStatus (commandPath, Status::InvalidCommand);
2795
- return true ;
2796
- }
2797
-
2798
- if (!shouldExecuteIfOff (endpoint, optionsMask, optionsOverride))
2799
- {
2800
- commandObj->AddStatus (commandPath, Status::Success);
2801
- return true ;
2802
- }
2769
+ VerifyOrReturnValue (shouldExecuteIfOff (endpoint, commandData.optionsMask , commandData.optionsOverride ), Status::Success);
2803
2770
2804
2771
// New command. Need to stop any active transitions.
2805
2772
stopAllColorTransitions (endpoint);
2806
2773
2774
+ uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE;
2775
+ uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE;
2807
2776
Attributes::ColorTempPhysicalMinMireds::Get (endpoint, &tempPhysicalMin);
2808
2777
Attributes::ColorTempPhysicalMaxMireds::Get (endpoint, &tempPhysicalMax);
2809
2778
@@ -2812,13 +2781,15 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
2812
2781
2813
2782
// Per spec, colorTemperatureMinimumMireds field is limited to ColorTempPhysicalMinMireds and
2814
2783
// when colorTemperatureMinimumMireds field is 0, ColorTempPhysicalMinMireds shall be used (always > 0)
2784
+ uint16_t colorTemperatureMinimum = commandData.colorTemperatureMinimumMireds ;
2815
2785
if (colorTemperatureMinimum < tempPhysicalMin)
2816
2786
{
2817
2787
colorTemperatureMinimum = tempPhysicalMin;
2818
2788
}
2819
2789
2820
2790
// Per spec, colorTemperatureMaximumMireds field is limited to ColorTempPhysicalMaxMireds and
2821
2791
// when colorTemperatureMaximumMireds field is 0, ColorTempPhysicalMaxMireds shall be used
2792
+ uint16_t colorTemperatureMaximum = commandData.colorTemperatureMaximumMireds ;
2822
2793
if ((colorTemperatureMaximum == 0 ) || (colorTemperatureMaximum > tempPhysicalMax))
2823
2794
{
2824
2795
colorTemperatureMaximum = tempPhysicalMax;
@@ -2834,9 +2805,10 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
2834
2805
2835
2806
colorTempTransitionState->currentValue = colorTempTransitionState->initialValue ;
2836
2807
2837
- if (stepMode == HueStepMode::kUp )
2808
+ if (commandData. stepMode == HueStepMode::kUp )
2838
2809
{
2839
- uint32_t finalValue32u = static_cast <uint32_t >(colorTempTransitionState->initialValue ) + static_cast <uint32_t >(stepSize);
2810
+ uint32_t finalValue32u =
2811
+ static_cast <uint32_t >(colorTempTransitionState->initialValue ) + static_cast <uint32_t >(commandData.stepSize );
2840
2812
if (finalValue32u > UINT16_MAX)
2841
2813
{
2842
2814
colorTempTransitionState->finalValue = UINT16_MAX;
@@ -2846,9 +2818,10 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
2846
2818
colorTempTransitionState->finalValue = static_cast <uint16_t >(finalValue32u);
2847
2819
}
2848
2820
}
2849
- else if (stepMode == HueStepMode::kDown )
2821
+ else if (commandData. stepMode == HueStepMode::kDown )
2850
2822
{
2851
- uint32_t finalValue32u = static_cast <uint32_t >(colorTempTransitionState->initialValue ) - static_cast <uint32_t >(stepSize);
2823
+ uint32_t finalValue32u =
2824
+ static_cast <uint32_t >(colorTempTransitionState->initialValue ) - static_cast <uint32_t >(commandData.stepSize );
2852
2825
if (finalValue32u > UINT16_MAX)
2853
2826
{
2854
2827
colorTempTransitionState->finalValue = 0 ;
@@ -2858,22 +2831,20 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj,
2858
2831
colorTempTransitionState->finalValue = static_cast <uint16_t >(finalValue32u);
2859
2832
}
2860
2833
}
2861
- colorTempTransitionState->stepsRemaining = std::max<uint16_t >(transitionTime, 1 );
2834
+ colorTempTransitionState->stepsRemaining = std::max<uint16_t >(commandData. transitionTime , 1 );
2862
2835
colorTempTransitionState->stepsTotal = colorTempTransitionState->stepsRemaining ;
2863
- colorTempTransitionState->timeRemaining = transitionTime;
2864
- colorTempTransitionState->transitionTime = transitionTime;
2836
+ colorTempTransitionState->timeRemaining = commandData. transitionTime ;
2837
+ colorTempTransitionState->transitionTime = commandData. transitionTime ;
2865
2838
colorTempTransitionState->endpoint = endpoint;
2866
2839
colorTempTransitionState->lowLimit = colorTemperatureMinimum;
2867
2840
colorTempTransitionState->highLimit = colorTemperatureMaximum;
2868
2841
2869
- SetQuietReportRemainingTime (endpoint, transitionTime, true /* isNewTransition */ );
2842
+ SetQuietReportRemainingTime (endpoint, commandData. transitionTime , true /* isNewTransition */ );
2870
2843
2871
2844
// kick off the state machine:
2872
- scheduleTimerCallbackMs (configureTempEventControl (endpoint), transitionTime ? TRANSITION_UPDATE_TIME_MS.count () : 0 );
2873
-
2874
- exit :
2875
- commandObj->AddStatus (commandPath, status);
2876
- return true ;
2845
+ scheduleTimerCallbackMs (configureTempEventControl (endpoint),
2846
+ commandData.transitionTime ? TRANSITION_UPDATE_TIME_MS.count () : 0 );
2847
+ return Status::Success;
2877
2848
}
2878
2849
2879
2850
void ColorControlServer::levelControlColorTempChangeCommand (EndpointId endpoint)
@@ -3220,21 +3191,27 @@ bool emberAfColorControlClusterMoveToColorTemperatureCallback(app::CommandHandle
3220
3191
const app::ConcreteCommandPath & commandPath,
3221
3192
const Commands::MoveToColorTemperature::DecodableType & commandData)
3222
3193
{
3223
- return ColorControlServer::Instance ().moveToColorTempCommand (commandObj, commandPath, commandData);
3194
+ Status status = ColorControlServer::Instance ().moveToColorTempCommand (commandPath.mEndpointId , commandData);
3195
+ commandObj->AddStatus (commandPath, status);
3196
+ return true ;
3224
3197
}
3225
3198
3226
3199
bool emberAfColorControlClusterMoveColorTemperatureCallback (app::CommandHandler * commandObj,
3227
3200
const app::ConcreteCommandPath & commandPath,
3228
3201
const Commands::MoveColorTemperature::DecodableType & commandData)
3229
3202
{
3230
- return ColorControlServer::Instance ().moveColorTempCommand (commandObj, commandPath, commandData);
3203
+ Status status = ColorControlServer::Instance ().moveColorTempCommand (commandPath.mEndpointId , commandData);
3204
+ commandObj->AddStatus (commandPath, status);
3205
+ return true ;
3231
3206
}
3232
3207
3233
3208
bool emberAfColorControlClusterStepColorTemperatureCallback (app::CommandHandler * commandObj,
3234
3209
const app::ConcreteCommandPath & commandPath,
3235
3210
const Commands::StepColorTemperature::DecodableType & commandData)
3236
3211
{
3237
- return ColorControlServer::Instance ().stepColorTempCommand (commandObj, commandPath, commandData);
3212
+ Status status = ColorControlServer::Instance ().stepColorTempCommand (commandPath.mEndpointId , commandData);
3213
+ commandObj->AddStatus (commandPath, status);
3214
+ return true ;
3238
3215
}
3239
3216
3240
3217
void emberAfPluginLevelControlCoupledColorTempChangeCallback (EndpointId endpoint)
0 commit comments