diff --git a/examples/lighting-app/tizen/src/DBusInterface.cpp b/examples/lighting-app/tizen/src/DBusInterface.cpp index cad184eb1c5158..0918d768a6d0d3 100644 --- a/examples/lighting-app/tizen/src/DBusInterface.cpp +++ b/examples/lighting-app/tizen/src/DBusInterface.cpp @@ -217,7 +217,7 @@ void DBusInterface::InitOnOff() void DBusInterface::InitColor() { { - auto value = 0; + auto value = Clusters::ColorControl::ColorModeEnum::kCurrentHueAndCurrentSaturation; auto status = Clusters::ColorControl::Attributes::ColorMode::Get(mEndpointId, &value); VerifyOrReturn(status == Protocols::InteractionModel::Status::Success, ChipLogError(NotSpecified, "Error getting ColorMode: 0x%x", to_underlying(status))); 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 53f6572125fdc9..397673b6ef30ac 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -129,7 +129,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl { loopDirectionValue = 0x00; } - AddAttributeValuePair(pairs, Attributes::ColorLoopDirection::Id, static_cast(loopDirectionValue), + AddAttributeValuePair(pairs, Attributes::ColorLoopDirection::Id, loopDirectionValue, attributeCount); uint16_t loopTimeValue; @@ -150,12 +150,12 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl AddAttributeValuePair(pairs, Attributes::ColorTemperatureMireds::Id, temperatureValue, attributeCount); } - ColorControl::EnhancedColorModeEnum modeValue; + EnhancedColorMode modeValue; if (Status::Success != Attributes::EnhancedColorMode::Get(endpoint, &modeValue)) { - modeValue = ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY; // Default mode value according to spec + modeValue = EnhancedColorMode::kCurrentXAndCurrentY; // Default mode value according to spec } - AddAttributeValuePair(pairs, Attributes::EnhancedColorMode::Id, static_cast(modeValue), attributeCount); + AddAttributeValuePair(pairs, Attributes::EnhancedColorMode::Id, to_underlying(modeValue), attributeCount); app::DataModel::List attributeValueList(pairs, attributeCount); @@ -200,7 +200,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl #endif // Initialize action attributes to default values in case they are not in the scene - ColorControl::EnhancedColorModeEnum targetColorMode = ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation; + auto targetColorMode = EnhancedColorMode::kCurrentHueAndCurrentSaturation; uint8_t loopActiveValue = 0x00; uint8_t loopDirectionValue = 0x00; uint16_t loopTimeValue = 0x0019; // Default loop time value according to spec @@ -212,7 +212,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl switch (decodePair.attributeID) { case Attributes::CurrentX::Id: - if (SupportsColorMode(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY)) + if (SupportsColorMode(endpoint, EnhancedColorMode::kCurrentXAndCurrentY)) { if (decodePair.attributeValue) colorXTransitionState->finalValue = @@ -220,20 +220,20 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl } break; case Attributes::CurrentY::Id: - if (SupportsColorMode(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY)) + if (SupportsColorMode(endpoint, EnhancedColorMode::kCurrentXAndCurrentY)) { colorYTransitionState->finalValue = std::min(static_cast(decodePair.attributeValue), colorYTransitionState->highLimit); } break; case Attributes::EnhancedCurrentHue::Id: - if (SupportsColorMode(endpoint, ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation)) + if (SupportsColorMode(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)) { colorHueTransitionState->finalEnhancedHue = static_cast(decodePair.attributeValue); } break; case Attributes::CurrentSaturation::Id: - if (SupportsColorMode(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation)) + if (SupportsColorMode(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation)) { colorSaturationTransitionState->finalValue = std::min(static_cast(decodePair.attributeValue), colorSaturationTransitionState->highLimit); @@ -249,7 +249,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl loopTimeValue = static_cast(decodePair.attributeValue); break; case Attributes::ColorTemperatureMireds::Id: - if (SupportsColorMode(endpoint, ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds)) + if (SupportsColorMode(endpoint, EnhancedColorMode::kColorTemperatureMireds)) { colorTempTransitionState->finalValue = std::min(static_cast(decodePair.attributeValue), colorTempTransitionState->highLimit); @@ -257,9 +257,9 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl break; case Attributes::EnhancedColorMode::Id: if (decodePair.attributeValue <= - static_cast(ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation)) + to_underlying(EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation)) { - targetColorMode = static_cast(decodePair.attributeValue); + targetColorMode = static_cast(decodePair.attributeValue); } break; default: @@ -294,25 +294,25 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl // Execute movement to value depending on the mode in the saved scene switch (targetColorMode) { - case ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation: + case 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 ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY: + case 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 ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds: + case 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 ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation: + case EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation: #ifdef MATTER_DM_PLUGIN_COLOR_CONTROL_SERVER_HSV ColorControlServer::Instance().moveToHueAndSaturation( colorHueTransitionState->finalEnhancedHue, static_cast(colorSaturationTransitionState->finalValue), @@ -327,20 +327,20 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl } private: - bool SupportsColorMode(EndpointId endpoint, ColorControl::EnhancedColorModeEnum mode) + bool SupportsColorMode(EndpointId endpoint, EnhancedColorMode mode) { switch (mode) { - case ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation: + case EnhancedColorMode::kCurrentHueAndCurrentSaturation: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kHueAndSaturation); break; - case ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY: + case EnhancedColorMode::kCurrentXAndCurrentY: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kXy); break; - case ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds: + case EnhancedColorMode::kColorTemperatureMireds: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kColorTemperature); break; - case ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation: + case EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation: return ColorControlServer::Instance().HasFeature(endpoint, ColorControlServer::Feature::kEnhancedHue); break; default: @@ -508,24 +508,24 @@ bool ColorControlServer::shouldExecuteIfOff(EndpointId endpoint, chip::BitMask(0xFF) && - optionOverride == static_cast(0xFF)) + if (optionMask == static_cast(0xFF) && + optionOverride == static_cast(0xFF)) { // 0xFF are the default values passed to the command handler when // the payload is not present - in that case there is use of option // attribute to decide execution of the command - return options.Has(ColorControl::OptionsBitmap::kExecuteIfOff); + return options.Has(OptionsBitmap::kExecuteIfOff); } // ---------- The above is to distinguish if the payload is present or not - if (optionMask.Has(ColorControl::OptionsBitmap::kExecuteIfOff)) + if (optionMask.Has(OptionsBitmap::kExecuteIfOff)) { // Mask is present and set in the command payload, this indicates // use the override as temporary option - return optionOverride.Has(ColorControl::OptionsBitmap::kExecuteIfOff); + return optionOverride.Has(OptionsBitmap::kExecuteIfOff); } // if we are here - use the option bits - return options.Has(ColorControl::OptionsBitmap::kExecuteIfOff); + return options.Has(OptionsBitmap::kExecuteIfOff); } /** @@ -539,28 +539,61 @@ bool ColorControlServer::shouldExecuteIfOff(EndpointId endpoint, chip::BitMask(newColorMode)) + // Convert ColorMode to EnhancedColorMode + EnhancedColorMode enhancedColorMode; + switch (oldColorMode) + { + case ColorMode::kCurrentHueAndCurrentSaturation: + enhancedColorMode = EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation; + break; + case ColorMode::kCurrentXAndCurrentY: + enhancedColorMode = EnhancedColorMode::kCurrentXAndCurrentY; + break; + case ColorMode::kColorTemperatureMireds: + enhancedColorMode = EnhancedColorMode::kColorTemperatureMireds; + break; + default: + break; + } + + if (enhancedColorMode == newColorMode) { return; } Attributes::EnhancedColorMode::Set(endpoint, newColorMode); - if (newColorMode == ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation) + if (newColorMode == EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation) { - // Transpose COLOR_MODE_EHSV to ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation after setting - // EnhancedColorModeEnum - newColorMode = ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation; + // Transpose COLOR_MODE_EHSV to ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation after setting + // EnhancedColorMode + newColorMode = EnhancedColorMode::kCurrentHueAndCurrentSaturation; } - Attributes::ColorMode::Set(endpoint, static_cast(newColorMode)); + // 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; + } + Attributes::ColorMode::Set(endpoint, colorMode); - colorModeTransition = static_cast((static_cast(newColorMode) << 4) + static_cast(oldColorMode)); + colorModeTransition = static_cast((to_underlying(newColorMode) << 4) + to_underlying(oldColorMode)); // Note: It may be OK to not do anything here. switch (colorModeTransition) @@ -960,7 +993,7 @@ void ColorControlServer::startColorLoop(EndpointId endpoint, uint8_t startFromSt colorHueTransitionState->initialEnhancedHue = startHue; - if (direction == to_underlying(ColorLoopDirectionEnum::kIncrement)) + if (direction == to_underlying(ColorLoopDirection::kIncrement)) { colorHueTransitionState->finalEnhancedHue = static_cast(startHue - 1); } @@ -969,7 +1002,7 @@ void ColorControlServer::startColorLoop(EndpointId endpoint, uint8_t startFromSt colorHueTransitionState->finalEnhancedHue = static_cast(startHue + 1); } - colorHueTransitionState->up = (direction == to_underlying(ColorLoopDirectionEnum::kIncrement)); + colorHueTransitionState->up = (direction == to_underlying(ColorLoopDirection::kIncrement)); colorHueTransitionState->repeat = true; colorHueTransitionState->stepsRemaining = static_cast(time * TRANSITION_STEPS_PER_1S); @@ -1211,7 +1244,7 @@ Status ColorControlServer::moveToSaturation(uint8_t saturation, uint16_t transit stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); // now, kick off the state machine. initSaturationTransitionState(endpoint, colorSaturationTransitionState); @@ -1262,11 +1295,11 @@ Status ColorControlServer::moveToHueAndSaturation(uint16_t hue, uint8_t saturati // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); } else { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); } // now, kick off the state machine. @@ -1331,7 +1364,7 @@ Status ColorControlServer::moveToHueAndSaturation(uint16_t hue, uint8_t saturati * @return false Failed */ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, - MoveModeEnum moveMode, uint16_t rate, chip::BitMask optionsMask, + HueMoveMode moveMode, uint16_t rate, chip::BitMask optionsMask, chip::BitMask optionsOverride, bool isEnhanced) { MATTER_TRACE_SCOPE("moveHue", "ColorControl"); @@ -1342,7 +1375,7 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const VerifyOrExit(colorHueTransitionState != nullptr, status = Status::UnsupportedEndpoint); // check moveMode before any operation is done on the transition states - if (moveMode == MoveModeEnum::kUnknownEnumValue || (rate == 0 && moveMode != MoveModeEnum::kStop)) + if (moveMode == HueMoveMode::kUnknownEnumValue || (rate == 0 && moveMode != HueMoveMode::kStop)) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -1359,7 +1392,7 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const // now, kick off the state machine. initHueTransitionState(endpoint, colorHueTransitionState, isEnhanced); - if (moveMode == MoveModeEnum::kStop) + if (moveMode == HueMoveMode::kStop) { // Per spec any saturation transition must also be cancelled. Color16uTransitionState * saturationState = getSaturationTransitionState(endpoint); @@ -1371,14 +1404,14 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); } else { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); } - if (moveMode == MoveModeEnum::kUp) + if (moveMode == HueMoveMode::kUp) { if (isEnhanced) { @@ -1391,7 +1424,7 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const colorHueTransitionState->up = true; } - else if (moveMode == MoveModeEnum::kDown) + else if (moveMode == HueMoveMode::kDown) { if (isEnhanced) { @@ -1427,7 +1460,7 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const * * @param[in] endpoint * @param[in] hue - * @param[in] MoveModeEnum + * @param[in] HueMoveMode * @param[in] transitionTime * @param[in] optionsMask * @param[in] optionsOverride @@ -1437,7 +1470,7 @@ bool ColorControlServer::moveHueCommand(app::CommandHandler * commandObj, const * @return false Failed */ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, - uint16_t hue, DirectionEnum moveDirection, uint16_t transitionTime, + uint16_t hue, HueDirection moveDirection, uint16_t transitionTime, chip::BitMask optionsMask, chip::BitMask optionsOverride, bool isEnhanced) { @@ -1446,7 +1479,7 @@ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, cons Status status = Status::Success; uint16_t currentHue = 0; - DirectionEnum direction; + HueDirection direction; ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); @@ -1475,33 +1508,33 @@ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, cons // Convert the ShortestDistance/LongestDistance moveDirection values into Up/Down. switch (moveDirection) { - case DirectionEnum::kShortest: + case HueDirection::kShortest: if ((isEnhanced && (static_cast(currentHue - hue) > HALF_MAX_UINT16T)) || (!isEnhanced && (static_cast(currentHue - hue) > HALF_MAX_UINT8T))) { - direction = DirectionEnum::kUp; + direction = HueDirection::kUp; } else { - direction = DirectionEnum::kDown; + direction = HueDirection::kDown; } break; - case DirectionEnum::kLongest: + case HueDirection::kLongest: if ((isEnhanced && (static_cast(currentHue - hue) > HALF_MAX_UINT16T)) || (!isEnhanced && (static_cast(currentHue - hue) > HALF_MAX_UINT8T))) { - direction = DirectionEnum::kDown; + direction = HueDirection::kDown; } else { - direction = DirectionEnum::kUp; + direction = HueDirection::kUp; } break; - case DirectionEnum::kUp: - case DirectionEnum::kDown: + case HueDirection::kUp: + case HueDirection::kDown: direction = moveDirection; break; - case DirectionEnum::kUnknownEnumValue: + case HueDirection::kUnknownEnumValue: commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; /* No default case, so if a new direction value gets added we will just fail @@ -1520,11 +1553,11 @@ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, cons // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); } else { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); } // now, kick off the state machine. @@ -1543,7 +1576,7 @@ bool ColorControlServer::moveToHueCommand(app::CommandHandler * commandObj, cons colorHueTransitionState->stepsTotal = colorHueTransitionState->stepsRemaining; colorHueTransitionState->timeRemaining = transitionTime; colorHueTransitionState->endpoint = endpoint; - colorHueTransitionState->up = (direction == DirectionEnum::kUp); + colorHueTransitionState->up = (direction == HueDirection::kUp); colorHueTransitionState->repeat = false; SetHSVRemainingTime(endpoint); @@ -1614,7 +1647,7 @@ bool ColorControlServer::moveToHueAndSaturationCommand(app::CommandHandler * com * @return false Failed */ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const 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) { @@ -1627,7 +1660,7 @@ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const VerifyOrExit(colorHueTransitionState != nullptr, status = Status::UnsupportedEndpoint); // Confirm validity of the step mode received - if (stepMode == StepModeEnum::kUnknownEnumValue) + if (stepMode == HueStepMode::kUnknownEnumValue) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -1645,11 +1678,11 @@ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const // Handle color mode transition, if necessary. if (isEnhanced) { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kEnhancedCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation); } else { - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); } // now, kick off the state machine. @@ -1658,12 +1691,12 @@ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const if (isEnhanced) { - if (stepMode == StepModeEnum::kUp) + if (stepMode == HueStepMode::kUp) { colorHueTransitionState->finalEnhancedHue = addEnhancedHue(colorHueTransitionState->currentEnhancedHue, stepSize); colorHueTransitionState->up = true; } - else if (stepMode == StepModeEnum::kDown) + else if (stepMode == HueStepMode::kDown) { colorHueTransitionState->finalEnhancedHue = subtractEnhancedHue(colorHueTransitionState->currentEnhancedHue, stepSize); colorHueTransitionState->up = false; @@ -1671,12 +1704,12 @@ bool ColorControlServer::stepHueCommand(app::CommandHandler * commandObj, const } else { - if (stepMode == StepModeEnum::kUp) + if (stepMode == HueStepMode::kUp) { colorHueTransitionState->finalHue = addHue(colorHueTransitionState->currentHue, static_cast(stepSize)); colorHueTransitionState->up = true; } - else if (stepMode == StepModeEnum::kDown) + else if (stepMode == HueStepMode::kDown) { colorHueTransitionState->finalHue = subtractHue(colorHueTransitionState->currentHue, static_cast(stepSize)); colorHueTransitionState->up = false; @@ -1714,7 +1747,7 @@ bool ColorControlServer::moveSaturationCommand(app::CommandHandler * commandObj, VerifyOrExit(colorSaturationTransitionState != nullptr, status = Status::UnsupportedEndpoint); // check moveMode before any operation is done on the transition states - if (moveMode == MoveModeEnum::kUnknownEnumValue || (rate == 0 && moveMode != MoveModeEnum::kStop)) + if (moveMode == SaturationMoveMode::kUnknownEnumValue || (rate == 0 && moveMode != SaturationMoveMode::kStop)) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -1734,7 +1767,7 @@ bool ColorControlServer::moveSaturationCommand(app::CommandHandler * commandObj, // now, kick off the state machine. initSaturationTransitionState(endpoint, colorSaturationTransitionState); - if (moveMode == MoveModeEnum::kStop) + if (moveMode == SaturationMoveMode::kStop) { // Per spec any hue transition must also be cancelled. ColorHueTransitionState * hueState = getColorHueTransitionState(endpoint); @@ -1744,13 +1777,13 @@ bool ColorControlServer::moveSaturationCommand(app::CommandHandler * commandObj, } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); - if (moveMode == MoveModeEnum::kUp) + if (moveMode == SaturationMoveMode::kUp) { colorSaturationTransitionState->finalValue = MAX_SATURATION_VALUE; } - else if (moveMode == MoveModeEnum::kDown) + else if (moveMode == SaturationMoveMode::kDown) { colorSaturationTransitionState->finalValue = MIN_SATURATION_VALUE; } @@ -1825,7 +1858,7 @@ bool ColorControlServer::stepSaturationCommand(app::CommandHandler * commandObj, VerifyOrExit(colorSaturationTransitionState != nullptr, status = Status::UnsupportedEndpoint); // Confirm validity of the step mode received - if (stepMode == StepModeEnum::kUnknownEnumValue) + if (stepMode == SaturationStepMode::kUnknownEnumValue) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -1841,17 +1874,17 @@ bool ColorControlServer::stepSaturationCommand(app::CommandHandler * commandObj, stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentHueAndCurrentSaturation); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentHueAndCurrentSaturation); // now, kick off the state machine. initSaturationTransitionState(endpoint, colorSaturationTransitionState); currentSaturation = static_cast(colorSaturationTransitionState->currentValue); - if (stepMode == StepModeEnum::kUp) + if (stepMode == SaturationStepMode::kUp) { colorSaturationTransitionState->finalValue = addSaturation(currentSaturation, stepSize); } - else if (stepMode == StepModeEnum::kDown) + else if (stepMode == SaturationStepMode::kDown) { colorSaturationTransitionState->finalValue = subtractSaturation(currentSaturation, stepSize); } @@ -1892,7 +1925,7 @@ bool ColorControlServer::colorLoopCommand(app::CommandHandler * commandObj, cons VerifyOrExit(colorHueTransitionState != nullptr, status = Status::UnsupportedEndpoint); // Validate the action and direction parameters of the command - if (action == ColorLoopActionEnum::kUnknownEnumValue || direction == ColorLoopDirectionEnum::kUnknownEnumValue) + if (action == ColorLoopAction::kUnknownEnumValue || direction == ColorLoopDirection::kUnknownEnumValue) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -1906,19 +1939,19 @@ bool ColorControlServer::colorLoopCommand(app::CommandHandler * commandObj, cons Attributes::ColorLoopActive::Get(endpoint, &isColorLoopActive); - deactiveColorLoop = updateFlags.Has(UpdateFlagsBitmap::kUpdateAction) && (action == ColorLoopActionEnum::kDeactivate); + deactiveColorLoop = updateFlags.Has(ColorLoopUpdateFlags::kUpdateAction) && (action == ColorLoopAction::kDeactivate); - if (updateFlags.Has(UpdateFlagsBitmap::kUpdateDirection)) + if (updateFlags.Has(ColorLoopUpdateFlags::kUpdateDirection)) { Attributes::ColorLoopDirection::Set(endpoint, to_underlying(direction)); // Checks if color loop is active and stays active if (isColorLoopActive && !deactiveColorLoop) { - colorHueTransitionState->up = (direction == ColorLoopDirectionEnum::kIncrement); + colorHueTransitionState->up = (direction == ColorLoopDirection::kIncrement); colorHueTransitionState->initialEnhancedHue = colorHueTransitionState->currentEnhancedHue; - if (direction == ColorLoopDirectionEnum::kIncrement) + if (direction == ColorLoopDirection::kIncrement) { colorHueTransitionState->finalEnhancedHue = static_cast(colorHueTransitionState->initialEnhancedHue - 1); } @@ -1930,7 +1963,7 @@ bool ColorControlServer::colorLoopCommand(app::CommandHandler * commandObj, cons } } - if (updateFlags.Has(UpdateFlagsBitmap::kUpdateTime)) + if (updateFlags.Has(ColorLoopUpdateFlags::kUpdateTime)) { Attributes::ColorLoopTime::Set(endpoint, time); @@ -1952,14 +1985,14 @@ bool ColorControlServer::colorLoopCommand(app::CommandHandler * commandObj, cons } } - if (updateFlags.Has(UpdateFlagsBitmap::kUpdateStartHue)) + if (updateFlags.Has(ColorLoopUpdateFlags::kUpdateStartHue)) { Attributes::ColorLoopStartEnhancedHue::Set(endpoint, startHue); } - if (updateFlags.Has(UpdateFlagsBitmap::kUpdateAction)) + if (updateFlags.Has(ColorLoopUpdateFlags::kUpdateAction)) { - if (action == ColorLoopActionEnum::kDeactivate) + if (action == ColorLoopAction::kDeactivate) { if (isColorLoopActive) { @@ -1976,11 +2009,11 @@ bool ColorControlServer::colorLoopCommand(app::CommandHandler * commandObj, cons // Do Nothing since it's not on } } - else if (action == ColorLoopActionEnum::kActivateFromColorLoopStartEnhancedHue) + else if (action == ColorLoopAction::kActivateFromColorLoopStartEnhancedHue) { startColorLoop(endpoint, true); } - else if (action == ColorLoopActionEnum::kActivateFromEnhancedCurrentHue) + else if (action == ColorLoopAction::kActivateFromEnhancedCurrentHue) { startColorLoop(endpoint, false); } @@ -2156,7 +2189,7 @@ Status ColorControlServer::moveToColor(uint16_t colorX, uint16_t colorY, uint16_ stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentXAndCurrentY); // now, kick off the state machine. Attributes::CurrentX::Get(endpoint, &(colorXTransitionState->initialValue)); @@ -2239,7 +2272,7 @@ bool ColorControlServer::moveColorCommand(app::CommandHandler * commandObj, cons } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentXAndCurrentY); // now, kick off the state machine. Attributes::CurrentX::Get(endpoint, &(colorXTransitionState->initialValue)); @@ -2337,7 +2370,7 @@ bool ColorControlServer::stepColorCommand(app::CommandHandler * commandObj, cons stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kCurrentXAndCurrentY); + handleModeSwitch(endpoint, EnhancedColorMode::kCurrentXAndCurrentY); // now, kick off the state machine. colorXTransitionState->initialValue = currentColorX; @@ -2453,7 +2486,7 @@ Status ColorControlServer::moveToColorTemp(EndpointId aEndpoint, uint16_t colorT stopAllColorTransitions(endpoint); // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds); + handleModeSwitch(endpoint, EnhancedColorMode::kColorTemperatureMireds); if (colorTemperature < temperatureMin) { @@ -2561,10 +2594,25 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint) if (status == Status::Success) { // Set ColorMode attributes to reflect ColorTemperature. - auto updateColorMode = ColorControl::ColorModeEnum::kColorTemperatureMireds; + auto updateColorMode = ColorMode::kColorTemperatureMireds; Attributes::ColorMode::Set(endpoint, updateColorMode); - - Attributes::EnhancedColorMode::Set(endpoint, static_cast(updateColorMode)); + // Convert ColorMode to EnhancedColorMode + EnhancedColorModeEnum enhancedColorMode; + 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); } } } @@ -2650,7 +2698,7 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj, VerifyOrExit(colorTempTransitionState != nullptr, status = Status::UnsupportedEndpoint); // check moveMode before any operation is done on the transition states - if (moveMode == MoveModeEnum::kUnknownEnumValue || (rate == 0 && moveMode != MoveModeEnum::kStop)) + if (moveMode == HueMoveMode::kUnknownEnumValue || (rate == 0 && moveMode != HueMoveMode::kStop)) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -2668,7 +2716,7 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj, // New command. Need to stop any active transitions. stopAllColorTransitions(endpoint); - if (moveMode == MoveModeEnum::kStop) + if (moveMode == HueMoveMode::kStop) { commandObj->AddStatus(commandPath, Status::Success); return true; @@ -2689,14 +2737,14 @@ bool ColorControlServer::moveColorTempCommand(app::CommandHandler * commandObj, } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds); + handleModeSwitch(endpoint, EnhancedColorMode::kColorTemperatureMireds); // now, kick off the state machine. colorTempTransitionState->initialValue = 0; Attributes::ColorTemperatureMireds::Get(endpoint, &colorTempTransitionState->initialValue); colorTempTransitionState->currentValue = colorTempTransitionState->initialValue; - if (moveMode == MoveModeEnum::kUp) + if (moveMode == HueMoveMode::kUp) { if (tempPhysicalMax > colorTemperatureMaximum) { @@ -2772,7 +2820,7 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj, VerifyOrExit(colorTempTransitionState != nullptr, status = Status::UnsupportedEndpoint); // Confirm validity of the step mode received - if (stepMode == StepModeEnum::kUnknownEnumValue) + if (stepMode == HueStepMode::kUnknownEnumValue) { commandObj->AddStatus(commandPath, Status::InvalidCommand); return true; @@ -2805,14 +2853,14 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj, } // Handle color mode transition, if necessary. - handleModeSwitch(endpoint, ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds); + handleModeSwitch(endpoint, EnhancedColorMode::kColorTemperatureMireds); // now, kick off the state machine. colorTempTransitionState->initialValue = 0; Attributes::ColorTemperatureMireds::Get(endpoint, &colorTempTransitionState->initialValue); colorTempTransitionState->currentValue = colorTempTransitionState->initialValue; - if (stepMode == StepModeEnum::kUp) + if (stepMode == HueStepMode::kUp) { uint32_t finalValue32u = static_cast(colorTempTransitionState->initialValue) + static_cast(stepSize); if (finalValue32u > UINT16_MAX) @@ -2824,7 +2872,7 @@ bool ColorControlServer::stepColorTempCommand(app::CommandHandler * commandObj, colorTempTransitionState->finalValue = static_cast(finalValue32u); } } - else if (stepMode == StepModeEnum::kDown) + else if (stepMode == HueStepMode::kDown) { uint32_t finalValue32u = static_cast(colorTempTransitionState->initialValue) - static_cast(stepSize); if (finalValue32u > UINT16_MAX) @@ -2891,10 +2939,27 @@ void ColorControlServer::levelControlColorTempChangeCommand(EndpointId endpoint) return; } - auto colorMode = ColorControl::ColorModeEnum::kCurrentHueAndCurrentSaturation; + auto colorMode = ColorModeEnum::kCurrentHueAndCurrentSaturation; Attributes::ColorMode::Get(endpoint, &colorMode); - if (static_cast(colorMode) == ColorControl::EnhancedColorModeEnum::kColorTemperatureMireds) + // Convert ColorMode to EnhancedColorMode + EnhancedColorModeEnum enhancedColorMode; + 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) { app::DataModel::Nullable currentLevel; Status status = LevelControl::Attributes::CurrentLevel::Get(endpoint, currentLevel); diff --git a/src/app/common/CompatEnumNames.h b/src/app/common/CompatEnumNames.h index 2051617644e5dc..246b9cd35de791 100644 --- a/src/app/common/CompatEnumNames.h +++ b/src/app/common/CompatEnumNames.h @@ -83,9 +83,17 @@ using LevelControlOptions = OptionsBitmap; namespace ColorControl { // https://github.com/project-chip/connectedhomeip/pull/33612 renamed this using ColorMode = ColorModeEnum; +using EnhancedColorMode = EnhancedColorModeEnum; using ColorCapabilities = ColorCapabilitiesBitmap; using ColorLoopUpdateFlags = UpdateFlagsBitmap; using ColorLoopAction = ColorLoopActionEnum; +using ColorLoopDirection = ColorLoopDirectionEnum; +using HueMoveMode = MoveModeEnum; +using HueDirection = DirectionEnum; +using HueStepMode = StepModeEnum; +using SaturationMoveMode = MoveModeEnum; +using SaturationStepMode = StepModeEnum; + } // namespace ColorControl namespace RefrigeratorAlarm {