Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and liangpy4 committed Nov 29, 2023
1 parent d4a9b56 commit 9fcb147
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/clusters/microwave-oven-control-server/microwave-oven-control-server.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>
#include <app/util/config.h>
#include <cstring>
#include <protocols/interaction_model/StatusCode.h>
#include <utility>

namespace chip {
Expand All @@ -34,23 +34,25 @@ namespace Clusters {

/**
* set default value for the optional attributes
*/
*/
constexpr uint8_t kDefaultMinPower = 10u;
constexpr uint8_t kDefaultMaxPower = 100u;
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) } };
Expand All @@ -64,23 +66,24 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsDefrost) }
};


//Operational States
// Operational States
const OperationalState::GenericOperationalState opStateList[4] = {
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
};

app::DataModel::List<const OperationalState::GenericOperationalState> mOperationalStateList = Span<const OperationalState::GenericOperationalState>(opStateList);
app::DataModel::List<const OperationalState::GenericOperationalState> mOperationalStateList =
Span<const OperationalState::GenericOperationalState>(opStateList);

const OperationalState::GenericOperationalPhase opPhaseList[1] = {
// Phase List is null
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
};

Span<const OperationalState::GenericOperationalPhase> mOperationalPhaseList = Span<const OperationalState::GenericOperationalPhase>(opPhaseList);
Span<const OperationalState::GenericOperationalPhase> mOperationalPhaseList =
Span<const OperationalState::GenericOperationalPhase>(opPhaseList);

public:
/**
Expand All @@ -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
*/
Expand All @@ -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.
Expand Down Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -40,24 +39,24 @@ void ExampleMicrowaveOvenDevice::MicrowaveOvenInit(EndpointId aEndpoint)

/**
* MicrowaveOvenControl cluster
*/
*/
Protocols::InteractionModel::Status
ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(Optional<uint8_t> cookMode, uint32_t cookTime, uint8_t powerSetting)
{
// placeholder implementation
Status status;
uint8_t reqCookMode;
if(cookMode.HasValue()){
if (cookMode.HasValue())
{
reqCookMode = cookMode.Value();

}
else
{
// set Microwave Oven cooking mode to normal mode(default).
reqCookMode = ModeNormal;
}

if((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(reqCookMode)) != Status::Success)
if ((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(reqCookMode)) != Status::Success)
{
return status;
}
Expand All @@ -73,17 +72,16 @@ Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleModifyCook
return Status::Success;
}



/**
* OperationalState cluster
*/
*/
app::DataModel::Nullable<uint32_t> ExampleMicrowaveOvenDevice::GetCountdownTime()
{
return static_cast<app::DataModel::Nullable<uint32_t>>(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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <app-common/zap-generated/cluster-objects.h>
#include <app/AttributeAccessInterface.h>
#include <app/CommandHandlerInterface.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<uint8_t> cookMode, uint32_t cookTime,
virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional<uint8_t> cookMode, uint32_t cookTime,
uint8_t powerSetting) = 0;

/**
Expand Down Expand Up @@ -172,7 +173,6 @@ class Delegate

protected:
Instance * GetInstance() const { return mInstance; }

};

/**
Expand All @@ -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
Expand Down

0 comments on commit 9fcb147

Please sign in to comment.