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 Jan 16, 2024
1 parent 9be4d15 commit 4265e66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
mMicrowaveOvenModeInstance(this, aClustersEndpoint, MicrowaveOvenMode::Id, 0),
mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id,
BitMask<MicrowaveOvenControl::Feature>(MicrowaveOvenControl::Feature::kPowerAsNumber,
MicrowaveOvenControl::Feature::kPowerNumberLimits),
MicrowaveOvenControl::Feature::kPowerNumberLimits),
mOperationalStateInstance, mMicrowaveOvenModeInstance)
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,32 @@ Instance::~Instance()
CHIP_ERROR Instance::Init()
{
// Check if the cluster has been selected in zap
VerifyOrReturnError(emberAfContainsServer(mEndpointId, mClusterId),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl, "Microwave Oven Control: The cluster with ID %lu was not enabled in zap.", long(mClusterId)));
VerifyOrReturnError(
emberAfContainsServer(mEndpointId, mClusterId), CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl, "Microwave Oven Control: The cluster with ID %lu was not enabled in zap.", long(mClusterId)));

// Exactly one of the PowerAsNumber and PowerInWatts features must be supported, per spec.
VerifyOrReturnError(mFeature.Has(MicrowaveOvenControl::Feature::kPowerAsNumber) || mFeature.Has(MicrowaveOvenControl::Feature::kPowerInWatts),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl, "Microwave Oven Control: feature bits error, feature must support one of PowerInWatts and PowerAsNumber"));
VerifyOrReturnError(
mFeature.Has(MicrowaveOvenControl::Feature::kPowerAsNumber) || mFeature.Has(MicrowaveOvenControl::Feature::kPowerInWatts),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl,
"Microwave Oven Control: feature bits error, feature must support one of PowerInWatts and PowerAsNumber"));

// Check that the feature bits do not include both PowerAsNumber and PowerInWatts
VerifyOrReturnError(!mFeature.Has(MicrowaveOvenControl::Feature::kPowerAsNumber) || !mFeature.Has(MicrowaveOvenControl::Feature::kPowerInWatts),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl,
"Microwave Oven Control: feature bits error, feature could not support both PowerAsNumber and PowerInWatts"));
VerifyOrReturnError(
!mFeature.Has(MicrowaveOvenControl::Feature::kPowerAsNumber) || !mFeature.Has(MicrowaveOvenControl::Feature::kPowerInWatts),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl,
"Microwave Oven Control: feature bits error, feature could not support both PowerAsNumber and PowerInWatts"));

// Per spec, the PowerNumberLimits feature is only allowed if the PowerAsNumber feature is supported.
VerifyOrReturnError(!mFeature.Has(MicrowaveOvenControl::Feature::kPowerNumberLimits) || mFeature.Has(MicrowaveOvenControl::Feature::kPowerAsNumber),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl,
"Microwave Oven Control: feature bits error, if feature supports PowerNumberLimits it must support PowerAsNumber"));
VerifyOrReturnError(
!mFeature.Has(MicrowaveOvenControl::Feature::kPowerNumberLimits) ||
mFeature.Has(MicrowaveOvenControl::Feature::kPowerAsNumber),
CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(
Zcl,
"Microwave Oven Control: feature bits error, if feature supports PowerNumberLimits it must support PowerAsNumber"));

ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this));
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);
Expand All @@ -87,8 +93,7 @@ CHIP_ERROR Instance::Init()
if (HasFeature(MicrowaveOvenControl::Feature::kPowerInWatts))
{
mSupportedWattLevels = GetCountOfSupportedWattLevels();
VerifyOrReturnError(mSupportedWattLevels > 0,
CHIP_ERROR_INVALID_ARGUMENT,
VerifyOrReturnError(mSupportedWattLevels > 0, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(Zcl, "Microwave Oven Control: supported watt levels is empty"));
}
return CHIP_NO_ERROR;
Expand Down Expand Up @@ -137,50 +142,35 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu
return aEncoder.Encode(mDelegate->GetMaxCookTimeSec());

case MicrowaveOvenControl::Attributes::PowerSetting::Id:
VerifyOrReturnError(
HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber),
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get PowerSetting number, feature is not supported")
);
VerifyOrReturnError(HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get PowerSetting number, feature is not supported"));

return aEncoder.Encode(mDelegate->GetPowerSettingNum());

case MicrowaveOvenControl::Attributes::MinPower::Id:
VerifyOrReturnError(
HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber),
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get MinPower number, feature is not supported")
);
VerifyOrReturnError(HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get MinPower number, feature is not supported"));

return aEncoder.Encode(
HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits) ? mDelegate->GetMinPowerNum() : kDefaultMinPowerNum);
return aEncoder.Encode(HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits) ? mDelegate->GetMinPowerNum()
: kDefaultMinPowerNum);

case MicrowaveOvenControl::Attributes::MaxPower::Id:
VerifyOrReturnError(
HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber),
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get MaxPower number, feature is not supported")
);
VerifyOrReturnError(HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get MaxPower number, feature is not supported"));

return aEncoder.Encode(
HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits) ? mDelegate->GetMaxPowerNum() : kDefaultMaxPowerNum);
return aEncoder.Encode(HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits) ? mDelegate->GetMaxPowerNum()
: kDefaultMaxPowerNum);

case MicrowaveOvenControl::Attributes::PowerStep::Id:
VerifyOrReturnError(
HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber),
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get PowerStep number, feature is not supported")
);
VerifyOrReturnError(HasFeature(MicrowaveOvenControl::Feature::kPowerAsNumber), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get PowerStep number, feature is not supported"));

return aEncoder.Encode(HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits)
? mDelegate->GetPowerStepNum() : kDefaultPowerStepNum);
return aEncoder.Encode(HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits) ? mDelegate->GetPowerStepNum()
: kDefaultPowerStepNum);

case MicrowaveOvenControl::Attributes::SupportedWatts::Id:
VerifyOrReturnError(
HasFeature(MicrowaveOvenControl::Feature::kPowerInWatts),
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get SuppoertWatts list, feature is not supported")
);
VerifyOrReturnError(HasFeature(MicrowaveOvenControl::Feature::kPowerInWatts), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get SuppoertWatts list, feature is not supported"));

return aEncoder.EncodeList([delegate = mDelegate](const auto & encoder) -> CHIP_ERROR {
uint16_t wattRating;
Expand All @@ -200,10 +190,8 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu

case MicrowaveOvenControl::Attributes::SelectedWattIndex::Id:
VerifyOrReturnError(
HasFeature(MicrowaveOvenControl::Feature::kPowerInWatts),
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get SelectedWattIndex number, feature is not supported")
);
HasFeature(MicrowaveOvenControl::Feature::kPowerInWatts), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
ChipLogError(Zcl, "Microwave Oven Control: can not get SelectedWattIndex number, feature is not supported"));

return aEncoder.Encode(mDelegate->GetCurrentWattIndex());

Expand All @@ -212,7 +200,6 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu

case MicrowaveOvenControl::Attributes::FeatureMap::Id:
return aEncoder.Encode(mFeature.Raw());

}
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -286,8 +273,8 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
{
// if using power as number, check if the param is invalid and set PowerSetting number.
uint8_t reqPowerSettingNum;
uint8_t maxPowerNum = kDefaultMaxPowerNum;
uint8_t minPowerNum = kDefaultMinPowerNum;
uint8_t maxPowerNum = kDefaultMaxPowerNum;
uint8_t minPowerNum = kDefaultMinPowerNum;
uint8_t powerStepNum = kDefaultPowerStepNum;
VerifyOrExit(!wattSettingIndex.HasValue(), status = Status::InvalidCommand; ChipLogError(
Zcl, "Microwave Oven Control: Failed to set cooking parameters, should have no value for wattSettingIndex"));
Expand All @@ -298,17 +285,18 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::

if (HasFeature(MicrowaveOvenControl::Feature::kPowerNumberLimits))
{
maxPowerNum = mDelegate->GetMaxPowerNum();
minPowerNum = mDelegate->GetMinPowerNum();
maxPowerNum = mDelegate->GetMaxPowerNum();
minPowerNum = mDelegate->GetMinPowerNum();
powerStepNum = mDelegate->GetPowerStepNum();
}
reqPowerSettingNum = powerSetting.ValueOr(maxPowerNum);
VerifyOrExit(IsPowerSettingNumberInRange(reqPowerSettingNum, minPowerNum, maxPowerNum), status = Status::ConstraintError;
ChipLogError(Zcl, "Microwave Oven Control: Failed to set PowerSetting, PowerSetting value is out of range"));


VerifyOrExit(reqPowerSettingNum % powerStepNum == 0, status = Status::InvalidCommand;
ChipLogError(Zcl, "Microwave Oven Control: Failed to set PowerSetting, PowerSetting value must be multiple of PowerStep number"));
VerifyOrExit(
reqPowerSettingNum % powerStepNum == 0, status = Status::InvalidCommand; ChipLogError(
Zcl,
"Microwave Oven Control: Failed to set PowerSetting, PowerSetting value must be multiple of PowerStep number"));

status = mDelegate->HandleSetCookingParametersCallback(reqCookMode, reqCookTimeSec, reqStartAfterSetting,
MakeOptional(reqPowerSettingNum), NullOptional);
Expand Down

0 comments on commit 4265e66

Please sign in to comment.