diff --git a/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h b/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h index 442e3dbf14d3da..c12fc4027390ff 100644 --- a/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h +++ b/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h @@ -18,14 +18,14 @@ #pragma once +#include #include -#include #include -#include +#include #include -#include #include #include +#include #include namespace chip { @@ -34,7 +34,7 @@ namespace Clusters { /** * set default value for the optional attributes -*/ + */ constexpr uint8_t kDefaultMinPower = 10u; constexpr uint8_t kDefaultMaxPower = 100u; constexpr uint8_t kDefaultPowerStep = 10u; @@ -42,15 +42,17 @@ constexpr uint8_t kDefaultPowerStep = 10u; constexpr uint8_t ModeNormal = 0; constexpr uint8_t ModeDefrost = 1; -class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public ModeBase::Delegate, public OperationalState::Delegate +class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, + public ModeBase::Delegate, + public OperationalState::Delegate { private: - //define delegates and instances for Microwave Oven device + // define delegates and instances for Microwave Oven device MicrowaveOvenControl::Instance mMicrowaveOvenControlInstance; OperationalState::Instance mOperationalStateInstance; ModeBase::Instance mMicrowaveOvenModeInstance; - //MicrowaveOvenMode types + // MicrowaveOvenMode types using ModeTagStructType = detail::Structs::ModeTagStruct::Type; ModeTagStructType modeTagsNormal[1] = { { .value = to_underlying(MicrowaveOvenMode::ModeTag::kNormal) } }; ModeTagStructType modeTagsDefrost[1] = { { .value = to_underlying(MicrowaveOvenMode::ModeTag::kDefrost) } }; @@ -64,8 +66,7 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public .modeTags = DataModel::List(modeTagsDefrost) } }; - - //Operational States + // Operational States const OperationalState::GenericOperationalState opStateList[4] = { OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)), OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)), @@ -73,14 +74,16 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)), }; - app::DataModel::List mOperationalStateList = Span(opStateList); + app::DataModel::List mOperationalStateList = + Span(opStateList); const OperationalState::GenericOperationalPhase opPhaseList[1] = { // Phase List is null OperationalState::GenericOperationalPhase(DataModel::Nullable()), }; - Span mOperationalPhaseList = Span(opPhaseList); + Span mOperationalPhaseList = + Span(opPhaseList); public: /** @@ -89,16 +92,19 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public * @param aClustersEndpoint The endpoint ID where all the microwave oven clusters exist. */ explicit ExampleMicrowaveOvenDevice(EndpointId aClustersEndpoint) : - mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id, &mOperationalStateInstance, &mMicrowaveOvenModeInstance), + mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id, &mOperationalStateInstance, + &mMicrowaveOvenModeInstance), mOperationalStateInstance(this, aClustersEndpoint, OperationalState::Id), - mMicrowaveOvenModeInstance(this, aClustersEndpoint, MicrowaveOvenMode::Id, chip::to_underlying(MicrowaveOvenMode::Feature::kOnOff)){} + mMicrowaveOvenModeInstance(this, aClustersEndpoint, MicrowaveOvenMode::Id, + chip::to_underlying(MicrowaveOvenMode::Feature::kOnOff)) + {} /** * Init all the clusters used by this device. */ void MicrowaveOvenInit(EndpointId aEndpoint); - //delegates from MicrowaveOvenControl cluster + // delegates from MicrowaveOvenControl cluster /** * handle command for microwave oven control: set cooking parameters */ @@ -125,9 +131,7 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public */ uint8_t GetPowerStep() const override { return kDefaultPowerStep; } - - - //delegates from OperationalState cluster + // delegates from OperationalState cluster /** * Get the countdown time. * return actual cook time. @@ -186,9 +190,7 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public */ void HandleStopStateCallback(OperationalState::GenericOperationalError & err) override; - - - //delegates from mode-base cluster + // delegates from mode-base cluster CHIP_ERROR Init() override; /** diff --git a/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp b/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp index 53775b6a7ab54a..a9a0feda3d1a96 100644 --- a/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp +++ b/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp @@ -29,7 +29,6 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct using OperationalStateEnum = chip::app::Clusters::OperationalState::OperationalStateEnum; using Status = Protocols::InteractionModel::Status; - void ExampleMicrowaveOvenDevice::MicrowaveOvenInit(EndpointId aEndpoint) { mOperationalStateInstance.SetOperationalState(to_underlying(OperationalStateEnum::kStopped)); @@ -40,16 +39,16 @@ void ExampleMicrowaveOvenDevice::MicrowaveOvenInit(EndpointId aEndpoint) /** * MicrowaveOvenControl cluster -*/ + */ Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(Optional cookMode, uint32_t cookTime, uint8_t powerSetting) { // placeholder implementation Status status; uint8_t reqCookMode; - if(cookMode.HasValue()){ + if (cookMode.HasValue()) + { reqCookMode = cookMode.Value(); - } else { @@ -57,7 +56,7 @@ ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(Optional reqCookMode = ModeNormal; } - if((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(reqCookMode)) != Status::Success) + if ((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(reqCookMode)) != Status::Success) { return status; } @@ -73,17 +72,16 @@ Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleModifyCook return Status::Success; } - - /** * OperationalState cluster -*/ + */ app::DataModel::Nullable ExampleMicrowaveOvenDevice::GetCountdownTime() { return static_cast>(mMicrowaveOvenControlInstance.GetCookTime()); } -CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalStateAtIndex(size_t index, OperationalState::GenericOperationalState & operationalState) +CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalStateAtIndex(size_t index, + OperationalState::GenericOperationalState & operationalState) { if (index > mOperationalStateList.size() - 1) { @@ -93,7 +91,8 @@ CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalStateAtIndex(size_t index, return CHIP_NO_ERROR; } -CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalPhaseAtIndex(size_t index, OperationalState::GenericOperationalPhase & operationalPhase) +CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalPhaseAtIndex(size_t index, + OperationalState::GenericOperationalPhase & operationalPhase) { if (index > mOperationalPhaseList.size() - 1) { @@ -159,18 +158,16 @@ void ExampleMicrowaveOvenDevice::HandleStopStateCallback(OperationalState::Gener } } - /** * MicrowaveOvenMode Cluster -*/ + */ CHIP_ERROR ExampleMicrowaveOvenDevice::Init() { return CHIP_NO_ERROR; } // todo refactor code by making a parent class for all ModeInstance classes to reduce flash usage. -void ExampleMicrowaveOvenDevice::HandleChangeToMode(uint8_t NewMode, - ModeBase::Commands::ChangeToModeResponse::Type & response) +void ExampleMicrowaveOvenDevice::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands::ChangeToModeResponse::Type & response) { response.status = to_underlying(ModeBase::StatusCode::kSuccess); } diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp index 1cd5b6fc233159..b396a305c43c72 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp @@ -33,16 +33,17 @@ using namespace chip::app::Clusters::ModeBase; using namespace chip::app::Clusters::MicrowaveOvenControl::Attributes; using Status = Protocols::InteractionModel::Status; - namespace chip { namespace app { namespace Clusters { namespace MicrowaveOvenControl { -Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, Clusters::OperationalState::Instance * aOpStateInstance, Clusters::ModeBase::Instance * aMicrowaveOvenModeInstance) : - CommandHandlerInterface(MakeOptional(aEndpointId), aClusterId), AttributeAccessInterface(MakeOptional(aEndpointId), aClusterId), - mDelegate(aDelegate), mEndpointId(aEndpointId), mClusterId(aClusterId), - mOpStateInstance(aOpStateInstance), mMicrowaveOvenModeInstance(aMicrowaveOvenModeInstance) +Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, + Clusters::OperationalState::Instance * aOpStateInstance, + Clusters::ModeBase::Instance * aMicrowaveOvenModeInstance) : + CommandHandlerInterface(MakeOptional(aEndpointId), aClusterId), + AttributeAccessInterface(MakeOptional(aEndpointId), aClusterId), mDelegate(aDelegate), mEndpointId(aEndpointId), + mClusterId(aClusterId), mOpStateInstance(aOpStateInstance), mMicrowaveOvenModeInstance(aMicrowaveOvenModeInstance) { mDelegate->SetInstance(this); } @@ -61,12 +62,12 @@ CHIP_ERROR Instance::Init() ChipLogError(Zcl, "Microwave Oven Control: The cluster with ID %lu was not enabled in zap.", long(mClusterId)); return CHIP_ERROR_INVALID_ARGUMENT; } - if(!mOpStateInstance) + if (!mOpStateInstance) { ChipLogError(Zcl, "Microwave Oven Control: Operational State instance is NULL"); return CHIP_ERROR_INVALID_ARGUMENT; } - if(!mMicrowaveOvenModeInstance) + if (!mMicrowaveOvenModeInstance) { ChipLogError(Zcl, "Microwave Oven Control: Microwave Oven Mode instance is NULL"); return CHIP_ERROR_INVALID_ARGUMENT; @@ -90,7 +91,7 @@ uint8_t Instance::GetPowerSetting() const void Instance::SetCookTime(uint32_t cookTime) { uint32_t oldCookTime = mCookTime; - mCookTime = cookTime; + mCookTime = cookTime; if (mCookTime != oldCookTime) { MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::CookTime::Id); @@ -100,7 +101,7 @@ void Instance::SetCookTime(uint32_t cookTime) void Instance::SetPowerSetting(uint8_t powerSetting) { uint8_t oldPowerSetting = mPowerSetting; - mPowerSetting = powerSetting; + mPowerSetting = powerSetting; if (mPowerSetting != oldPowerSetting) { MatterReportingAttributeChangeCallback(mEndpointId, mClusterId, Attributes::PowerSetting::Id); @@ -171,7 +172,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: auto & powerSetting = req.powerSetting; // check if the input cooking value is invalid - if(cookMode.HasValue() && (!mMicrowaveOvenModeInstance->IsSupportedMode(cookMode.Value()))) + if (cookMode.HasValue() && (!mMicrowaveOvenModeInstance->IsSupportedMode(cookMode.Value()))) { status = Status::InvalidCommand; ChipLogError(Zcl, "Failed to set cookMode, cookMode is not support"); @@ -193,9 +194,9 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: goto exit; } - //get current operational state + // get current operational state opState = mOpStateInstance->GetCurrentOperationalState(); - if(opState != to_underlying(OperationalStateEnum::kStopped)) + if (opState != to_underlying(OperationalStateEnum::kStopped)) { status = Status::InvalidInState; goto exit; @@ -237,7 +238,7 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi Status status; uint8_t opState; - //get current operational state + // get current operational state opState = mOpStateInstance->GetCurrentOperationalState(); if (opState == to_underlying(OperationalStateEnum::kStopped) || opState == to_underlying(OperationalStateEnum::kRunning) || opState == to_underlying(OperationalStateEnum::kPaused)) @@ -278,7 +279,6 @@ bool IsPowerSettingInRange(uint8_t powerSetting, uint8_t minCookPower, uint8_t m return (powerSetting < minCookPower || powerSetting > maxCookPower) ? false : true; } - } // namespace MicrowaveOvenControl } // namespace Clusters } // namespace app diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h index c8f8c692b10acf..13ee2db4ac2e92 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h @@ -21,8 +21,8 @@ #include #include #include -#include #include +#include #include #include @@ -53,7 +53,8 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface * Note: a MicrowaveOvenControl instance must live relying on an Operational State instance and a Microwave Oven Mode instance, * caller should be initialized that 2 instances before initializing MicorwaveOvenControl instance. */ - Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, Clusters::OperationalState::Instance * aOpStateInstance, Clusters::ModeBase::Instance * aMicrowaveOvenModeInstance); + Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, + Clusters::OperationalState::Instance * aOpStateInstance, Clusters::ModeBase::Instance * aMicrowaveOvenModeInstance); ~Instance() override; @@ -90,7 +91,7 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface /** * set default values */ - uint32_t mCookTime = kDefaultCookTime; + uint32_t mCookTime = kDefaultCookTime; uint8_t mPowerSetting = kDefaultPowerSetting; /** @@ -134,7 +135,7 @@ class Delegate * @param cookTime: the input cook time value * @param powerSetting: the input power setting value */ - virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional cookMode, uint32_t cookTime, + virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional cookMode, uint32_t cookTime, uint8_t powerSetting) = 0; /** @@ -172,7 +173,6 @@ class Delegate protected: Instance * GetInstance() const { return mInstance; } - }; /** @@ -189,8 +189,6 @@ bool IsCookTimeInRange(uint32_t cookTime); */ bool IsPowerSettingInRange(uint8_t powerSetting, uint8_t minCookPower, uint8_t maxCookPower); - - } // namespace MicrowaveOvenControl } // namespace Clusters } // namespace app