diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index 6f891d244e4cd1..05823dd50a8f6c 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -211,7 +211,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl switch (decodePair.attributeID) { case Attributes::CurrentX::Id: - if (SupportsColorMode(endpoint, EnhancedColorMode::kCurrentXAndCurrentY)) + if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kCurrentXAndCurrentY)) { VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); colorXTransitionState->finalValue = @@ -219,7 +219,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl } break; case Attributes::CurrentY::Id: - if (SupportsColorMode(endpoint, EnhancedColorMode::kCurrentXAndCurrentY)) + if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kCurrentXAndCurrentY)) { VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); colorYTransitionState->finalValue = @@ -227,14 +227,14 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl } break; case Attributes::EnhancedCurrentHue::Id: - if (SupportsColorMode(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)) + if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)) { VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); colorHueTransitionState->finalEnhancedHue = decodePair.valueUnsigned16.Value(); } break; case Attributes::CurrentSaturation::Id: - if (SupportsColorMode(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation)) + if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)) { VerifyOrReturnError(decodePair.valueUnsigned8.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); colorSaturationTransitionState->finalValue = std::min(static_cast(decodePair.valueUnsigned8.Value()), @@ -254,7 +254,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl loopTimeValue = decodePair.valueUnsigned16.Value(); break; case Attributes::ColorTemperatureMireds::Id: - if (SupportsColorMode(endpoint, EnhancedColorMode::kColorTemperatureMireds)) + if (SupportsColorMode(endpoint, ColorControl::EnhancedColorMode::kColorTemperatureMireds)) { VerifyOrReturnError(decodePair.valueUnsigned16.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); colorTempTransitionState->finalValue = @@ -264,9 +264,9 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl case Attributes::EnhancedColorMode::Id: VerifyOrReturnError(decodePair.valueUnsigned8.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); if (decodePair.valueUnsigned8.Value() <= - static_cast(EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation)) + static_cast(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)) { - targetColorMode = static_cast(decodePair.valueUnsigned8.Value()); + targetColorMode = static_cast(decodePair.valueUnsigned8.Value()); } break; default: @@ -279,7 +279,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl // Switch to the mode saved in the scene if (SupportsColorMode(endpoint, targetColorMode)) { - ColorControlServer::Instance().handleModeSwitch(endpoint, targetColorMode); + ColorControlServer::Instance().handleModeSwitch(endpoint, static_cast(targetColorMode)); } else { @@ -301,25 +301,25 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl // Execute movement to value depending on the mode in the saved scene switch (targetColorMode) { - case EnhancedColorMode::kCurrentHueAndCurrentSaturation: + case ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation: #ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_HSV ColorControlServer::Instance().moveToSaturation(static_cast(colorSaturationTransitionState->finalValue), transitionTime10th, endpoint); #endif // MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_HSV break; - case EnhancedColorMode::kCurrentXAndCurrentY: + case ColorControl::EnhancedColorMode::kCurrentXAndCurrentY: #ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_XY ColorControlServer::Instance().moveToColor(colorXTransitionState->finalValue, colorYTransitionState->finalValue, transitionTime10th, endpoint); #endif // MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_XY break; - case EnhancedColorMode::kColorTemperatureMireds: + case ColorControl::EnhancedColorMode::kColorTemperatureMireds: #ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_TEMP ColorControlServer::Instance().moveToColorTemp( endpoint, static_cast(colorTempTransitionState->finalValue), transitionTime10th); #endif // MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_TEMP break; - case EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation: + case ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation: #ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_HSV ColorControlServer::Instance().moveToHueAndSaturation( colorHueTransitionState->finalEnhancedHue, static_cast(colorSaturationTransitionState->finalValue), @@ -334,20 +334,20 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl } private: - bool SupportsColorMode(EndpointId endpoint, EnhancedColorMode mode) + bool SupportsColorMode(EndpointId endpoint, ColorControl::EnhancedColorMode mode) { switch (mode) { - case EnhancedColorMode::kCurrentHueAndCurrentSaturation: + case ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kHueAndSaturation); break; - case EnhancedColorMode::kCurrentXAndCurrentY: + case ColorControl::EnhancedColorMode::kCurrentXAndCurrentY: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kXy); break; - case EnhancedColorMode::kColorTemperatureMireds: + case ColorControl::EnhancedColorMode::kColorTemperatureMireds: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kColorTemperature); break; - case EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation: + case ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kEnhancedHue); break; default: @@ -562,61 +562,30 @@ bool ColorControlServer::shouldExecuteIfOff(EndpointId endpoint, chip::BitMask(newColorMode); + ColorControl::EnhancedColorMode newEnhanceColorModeEnum = static_cast(newColorMode); + if (oldColorMode == newColorModeEnum) { return; } - Attributes::EnhancedColorMode::Set(endpoint, newColorMode); - if (newColorMode == EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation) + Attributes::EnhancedColorMode::Set(endpoint, newEnhanceColorModeEnum); + if (newEnhanceColorModeEnum == ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation) { // Transpose COLOR_MODE_EHSV to ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation after setting // EnhancedColorMode - newColorMode = EnhancedColorMode::kCurrentHueAndCurrentSaturation; - } - // Convert EnhancedColorModeEnum to ColorModeEnum for setting ColorMode attribute - ColorModeEnum colorMode = ColorModeEnum::kUnknownEnumValue; - switch (newColorMode) - { - case EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation: - colorMode = ColorModeEnum::kCurrentHueAndCurrentSaturation; - break; - case EnhancedColorModeEnum::kCurrentXAndCurrentY: - colorMode = ColorModeEnum::kCurrentXAndCurrentY; - break; - case EnhancedColorModeEnum::kColorTemperatureMireds: - colorMode = ColorModeEnum::kColorTemperatureMireds; - break; - default: - break; + newEnhanceColorModeEnum = ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation; } - Attributes::ColorMode::Set(endpoint, colorMode); + Attributes::ColorMode::Set(endpoint, newColorModeEnum); - colorModeTransition = static_cast((to_underlying(newColorMode) << 4) + to_underlying(oldColorMode)); + colorModeTransition = static_cast((to_underlying(newColorModeEnum) << 4) + to_underlying(oldColorMode)); // Note: It may be OK to not do anything here. switch (colorModeTransition) @@ -1267,7 +1236,7 @@ Status ColorControlServer::moveToSaturation(uint8_t saturation, uint16_t transit stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)); // now, kick off the state machine. initSaturationTransitionState(endpoint, colorSaturationTransitionState); @@ -1318,11 +1287,11 @@ Status ColorControlServer::moveToHueAndSaturation(uint16_t hue, uint8_t saturati // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)); } else { - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(EnhancedColorMode::kCurrentHueAndCurrentSaturation)); } // now, kick off the state machine. @@ -1427,11 +1396,11 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)); } else { - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)); } if (moveMode == HueMoveMode::kUp) @@ -1483,7 +1452,7 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const * * @param[in] endpoint * @param[in] hue - * @param[in] HueMoveMode + * @param[in] hueMoveMode * @param[in] transitionTime * @param[in] optionsMask * @param[in] optionsOverride @@ -1576,11 +1545,11 @@ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, cons // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)); } else { - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)); } // now, kick off the state machine. @@ -1701,11 +1670,11 @@ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)); } else { - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)); } // now, kick off the state machine. @@ -1800,7 +1769,7 @@ bool ColorControlServer::moveSaturationCommand(app::CommandHandler * commandObj, } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)); if (moveMode == SaturationMoveMode::kUp) { @@ -1897,7 +1866,7 @@ bool ColorControlServer::stepSaturationCommand(app::CommandHandler * commandObj, stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation)); // now, kick off the state machine. initSaturationTransitionState(endpoint, colorSaturationTransitionState); @@ -2212,7 +2181,7 @@ Status ColorControlServer::moveToColor(uint16_t colorX, uint16_t colorY, uint16_ stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentXAndCurrentY); + handleModeSwitch(endpoint, static_cast(EnhancedColorMode::kCurrentXAndCurrentY)); // now, kick off the state machine. Attributes::CurrentX::Get(endpoint, &(colorXTransitionState->initialValue)); @@ -2295,7 +2264,7 @@ bool ColorControlServer::moveColorCommand(app::CommandHandler * commandObj, cons } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentXAndCurrentY); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentXAndCurrentY)); // now, kick off the state machine. Attributes::CurrentX::Get(endpoint, &(colorXTransitionState->initialValue)); @@ -2393,7 +2362,7 @@ bool ColorControlServer::stepColorCommand(app::CommandHandler * commandObj, cons stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kCurrentXAndCurrentY); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kCurrentXAndCurrentY)); // now, kick off the state machine. colorXTransitionState->initialValue = currentColorX; @@ -2509,7 +2478,7 @@ Status ColorControlServer::moveToColorTemp(EndpointId aEndpoint, uint16_t colorT stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kColorTemperatureMireds); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kColorTemperatureMireds)); if (colorTemperature < temperatureMin) { @@ -2617,25 +2586,11 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint) if (status == Status::Success) { // Set ColorMode attributes to reflect ColorTemperature. - auto updateColorMode = ColorMode::kColorTemperatureMireds; + auto updateColorMode = ColorControl::ColorMode::kColorTemperatureMireds; Attributes::ColorMode::Set(endpoint, updateColorMode); - // Convert ColorMode to EnhancedColorMode - EnhancedColorModeEnum enhancedColorMode = EnhancedColorModeEnum::kUnknownEnumValue; - switch (updateColorMode) - { - case ColorModeEnum::kCurrentHueAndCurrentSaturation: - enhancedColorMode = EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation; - break; - case ColorModeEnum::kCurrentXAndCurrentY: - enhancedColorMode = EnhancedColorModeEnum::kCurrentXAndCurrentY; - break; - case ColorModeEnum::kColorTemperatureMireds: - enhancedColorMode = EnhancedColorModeEnum::kColorTemperatureMireds; - break; - default: - break; - } - Attributes::EnhancedColorMode::Set(endpoint, enhancedColorMode); + + auto updateEnhanceColorMode = ColorControl::EnhancedColorMode::kColorTemperatureMireds; + Attributes::EnhancedColorMode::Set(endpoint, updateEnhanceColorMode); } } } @@ -2760,7 +2715,7 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj, } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kColorTemperatureMireds); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kColorTemperatureMireds)); // now, kick off the state machine. colorTempTransitionState->initialValue = 0; @@ -2876,7 +2831,7 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj, } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, EnhancedColorMode::kColorTemperatureMireds); + handleModeSwitch(endpoint, static_cast(ColorControl::EnhancedColorMode::kColorTemperatureMireds)); // now, kick off the state machine. colorTempTransitionState->initialValue = 0; @@ -2965,24 +2920,7 @@ void ColorControlServer::levelControlColorTempChangeCommand(EndpointId endpoint) auto colorMode = ColorModeEnum::kCurrentHueAndCurrentSaturation; Attributes::ColorMode::Get(endpoint, &colorMode); - // Convert ColorMode to EnhancedColorMode - EnhancedColorModeEnum enhancedColorMode = EnhancedColorModeEnum::kUnknownEnumValue; - switch (colorMode) - { - case ColorModeEnum::kCurrentHueAndCurrentSaturation: - enhancedColorMode = EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation; - break; - case ColorModeEnum::kCurrentXAndCurrentY: - enhancedColorMode = EnhancedColorModeEnum::kCurrentXAndCurrentY; - break; - case ColorModeEnum::kColorTemperatureMireds: - enhancedColorMode = EnhancedColorModeEnum::kColorTemperatureMireds; - break; - default: - break; - } - - if (enhancedColorMode == EnhancedColorMode::kColorTemperatureMireds) + if (colorMode == ColorControl::ColorModeEnum::kColorTemperatureMireds) { app::DataModel::Nullable currentLevel; Status status = LevelControl::Attributes::CurrentLevel::Get(endpoint, currentLevel); diff --git a/src/app/clusters/color-control-server/color-control-server.h b/src/app/clusters/color-control-server/color-control-server.h index 969968fb94c201..b320243e55d031 100644 --- a/src/app/clusters/color-control-server/color-control-server.h +++ b/src/app/clusters/color-control-server/color-control-server.h @@ -69,10 +69,10 @@ class ColorControlServer /********************************************************** * Enums *********************************************************/ - using StepModeEnum = chip::app::Clusters::ColorControl::StepModeEnum; - using MoveModeEnum = chip::app::Clusters::ColorControl::MoveModeEnum; - using DirectionEnum = chip::app::Clusters::ColorControl::DirectionEnum; - using Feature = chip::app::Clusters::ColorControl::Feature; + using HueStepMode = chip::app::Clusters::ColorControl::StepModeEnum; + using HueMoveMode = chip::app::Clusters::ColorControl::MoveModeEnum; + using HueDirection = chip::app::Clusters::ColorControl::DirectionEnum; + using Feature = chip::app::Clusters::ColorControl::Feature; enum Conversion { @@ -141,20 +141,21 @@ class ColorControlServer #ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_HSV bool moveHueCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - MoveModeEnum moveMode, uint16_t rate, + HueMoveMode moveMode, uint16_t rate, chip::BitMask optionsMask, chip::BitMask optionsOverride, bool isEnhanced); bool moveToHueCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, uint16_t hue, - DirectionEnum moveDirection, uint16_t transitionTime, + HueDirection moveDirection, uint16_t transitionTime, chip::BitMask optionsMask, - chip::BitMask optionsOverride, bool isEnhanced); + chip::BitMask optionsOverride, + bool isEnhanced); bool moveToHueAndSaturationCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - uint16_t hue, uint8_t saturation, uint16_t transitionTime, + uint16_t hue, uint8_t saturation, uint16_t transitionTime, chip::BitMask optionsMask, chip::BitMask optionsOverride, bool isEnhanced); bool stepHueCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - StepModeEnum stepMode, uint16_t stepSize, uint16_t transitionTime, + HueStepMode stepMode, uint16_t stepSize, uint16_t transitionTime, chip::BitMask optionsMask, chip::BitMask optionsOverride, bool isEnhanced); bool moveSaturationCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, @@ -201,7 +202,7 @@ class ColorControlServer ColorControlServer() {} bool shouldExecuteIfOff(chip::EndpointId endpoint, chip::BitMask optionMask, chip::BitMask optionOverride); - void handleModeSwitch(chip::EndpointId endpoint, chip::app::Clusters::ColorControl::EnhancedColorModeEnum newColorMode); + void handleModeSwitch(chip::EndpointId endpoint, uint8_t newColorMode); uint16_t computeTransitionTimeFromStateAndRate(Color16uTransitionState * p, uint16_t rate); EmberEventControl * getEventControl(chip::EndpointId endpoint); void computePwmFromHsv(chip::EndpointId endpoint);