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 mideayanghui committed Nov 7, 2023
1 parent 49b8f2a commit fbc53e3
Showing 1 changed file with 50 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ using Status = Protocols::InteractionModel::Status;

namespace {

constexpr uint32_t kMaxCookTime = 65535;
constexpr uint32_t kMinCookTime = 1;
constexpr uint32_t kMaxCookTime = 65535;
constexpr uint32_t kMinCookTime = 1;
constexpr uint8_t kDefaultCookTime = 30;
constexpr uint8_t kDefaultCookPower = 100;

Expand Down Expand Up @@ -82,7 +82,7 @@ bool CheckCookTimeIsInRange(uint32_t cookTime)
return (cookTime < kMinCookTime || cookTime > kMaxCookTime) ? false : true;
}

bool CheckPowerSettingIsInRange(uint8_t powerSetting,uint8_t minCookPower,uint8_t maxCookPower)
bool CheckPowerSettingIsInRange(uint8_t powerSetting, uint8_t minCookPower, uint8_t maxCookPower)
{
return (powerSetting < minCookPower || powerSetting > maxCookPower) ? false : true;
}
Expand All @@ -107,9 +107,9 @@ bool emberAfMicrowaveOvenControlClusterSetCookingParametersCallback(
EmberAfStatus emberAfStatus = EMBER_ZCL_STATUS_SUCCESS;
Status status = Status::Success;
OperationalState::Instance * gOperationalStateInstance = nullptr;
auto & CookMode = commandData.cookMode;
auto & CookTime = commandData.cookTime;
auto & PowerSetting = commandData.powerSetting;
auto & CookMode = commandData.cookMode;
auto & CookTime = commandData.cookTime;
auto & PowerSetting = commandData.powerSetting;
uint8_t kMinCookPower;
uint8_t kMaxCookPower;

Expand All @@ -122,93 +122,93 @@ bool emberAfMicrowaveOvenControlClusterSetCookingParametersCallback(
goto exit;
}

if(CookTime.HasValue() && (!CheckCookTimeIsInRange(CookTime.Value())))
if (CookTime.HasValue() && (!CheckCookTimeIsInRange(CookTime.Value())))
{
status = Status::InvalidCommand;
ChipLogError(Zcl,"Failed to set cookTime, cookTime value is out of range");
ChipLogError(Zcl, "Failed to set cookTime, cookTime value is out of range");
goto exit;
}

emberAfStatus = MinPower::Get(endpointId, &kMinCookPower);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = app::ToInteractionModelStatus(emberAfStatus);
ChipLogError(Zcl,"Failed to get MinPower");
ChipLogError(Zcl, "Failed to get MinPower");
goto exit;
}

emberAfStatus = MaxPower::Get(endpointId, &kMaxCookPower);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = app::ToInteractionModelStatus(emberAfStatus);
ChipLogError(Zcl,"Failed to get MaxPower");
ChipLogError(Zcl, "Failed to get MaxPower");
goto exit;
}

if(PowerSetting.HasValue() && (!CheckPowerSettingIsInRange(PowerSetting.Value(),kMinCookPower,kMaxCookPower)))
if (PowerSetting.HasValue() && (!CheckPowerSettingIsInRange(PowerSetting.Value(), kMinCookPower, kMaxCookPower)))
{
status = Status::InvalidCommand;
ChipLogError(Zcl,"Failed to set cookPower, cookPower value is out of range");
ChipLogError(Zcl, "Failed to set cookPower, cookPower value is out of range");
goto exit;
}

opState = gOperationalStateInstance->GetCurrentOperationalState();
if(opState == to_underlying(OperationalStateEnum::kStopped))
if (opState == to_underlying(OperationalStateEnum::kStopped))
{

if(CookMode.HasValue())
if (CookMode.HasValue())
{
//TODO: set Microwave Oven cooking mode by CookMode.Value().
// TODO: set Microwave Oven cooking mode by CookMode.Value().
}
else
{
//TODO: set Microwave Oven cooking mode to normal mode.
// TODO: set Microwave Oven cooking mode to normal mode.
}

if(CookTime.HasValue())
if (CookTime.HasValue())
{
//set Microwave Oven cooking time by getting input value.
// set Microwave Oven cooking time by getting input value.
emberAfStatus = CookTime::Set(endpointId, CookTime.Value());
ChipLogError(Zcl, "emberAfStatus value = %d",emberAfStatus);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
ChipLogError(Zcl, "emberAfStatus value = %d", emberAfStatus);
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = Status::InvalidCommand;
ChipLogError(Zcl, "Failed to set cookTime with value = %ld",CookTime.Value());
ChipLogError(Zcl, "Failed to set cookTime with value = %ld", CookTime.Value());
goto exit;
}
}
else
{
//set Microwave Oven cooking time to 30 seconds(default).
// set Microwave Oven cooking time to 30 seconds(default).
emberAfStatus = CookTime::Set(endpointId, kDefaultCookTime);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = Status::InvalidCommand;
ChipLogError(Zcl, "Failed to set cookTime with value = %d",kDefaultCookTime);
ChipLogError(Zcl, "Failed to set cookTime with value = %d", kDefaultCookTime);
goto exit;
}
}

if(PowerSetting.HasValue())
if (PowerSetting.HasValue())
{
//set Microwave Oven cooking power by getting input value.
// set Microwave Oven cooking power by getting input value.
emberAfStatus = PowerSetting::Set(endpointId, PowerSetting.Value());
ChipLogError(Zcl, "emberAfStatus value = %d",emberAfStatus);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
ChipLogError(Zcl, "emberAfStatus value = %d", emberAfStatus);
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = Status::InvalidCommand;
ChipLogError(Zcl, "Failed to set cooking power with value = %d",PowerSetting.Value());
ChipLogError(Zcl, "Failed to set cooking power with value = %d", PowerSetting.Value());
goto exit;
}
}
else
{
//set Microwave Oven cooking power to max power(default).
// set Microwave Oven cooking power to max power(default).
emberAfStatus = PowerSetting::Set(endpointId, kDefaultCookPower);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = Status::InvalidCommand;
ChipLogError(Zcl, "Failed to set cooking power with value = %d",kDefaultCookPower);
ChipLogError(Zcl, "Failed to set cooking power with value = %d", kDefaultCookPower);
goto exit;
}
}
Expand All @@ -231,57 +231,56 @@ bool emberAfMicrowaveOvenControlClusterAddMoreTimeCallback(
const chip::app::Clusters::MicrowaveOvenControl::Commands::AddMoreTime::DecodableType & commandData)
{
uint8_t opState;
EndpointId endpointId = commandPath.mEndpointId;
EmberAfStatus emberAfStatus = EMBER_ZCL_STATUS_SUCCESS;
Status status = Status::Success;
EndpointId endpointId = commandPath.mEndpointId;
EmberAfStatus emberAfStatus = EMBER_ZCL_STATUS_SUCCESS;
Status status = Status::Success;
OperationalState::Instance * gOperationalStateInstance = nullptr;

//get Operational State instance and current state
// get Operational State instance and current state
gOperationalStateInstance = GetOPInstance(endpointId);
if(gOperationalStateInstance == nullptr)
if (gOperationalStateInstance == nullptr)
{
ChipLogProgress(Zcl, "Server didn't create instance of Operational State");
status = Status::InvalidInState;
goto exit;
}

opState = gOperationalStateInstance->GetCurrentOperationalState();
if(opState == to_underlying(OperationalStateEnum::kStopped) ||
opState == to_underlying(OperationalStateEnum::kRunning) ||
opState == to_underlying(OperationalStateEnum::kPaused))
if (opState == to_underlying(OperationalStateEnum::kStopped) || opState == to_underlying(OperationalStateEnum::kRunning) ||
opState == to_underlying(OperationalStateEnum::kPaused))
{
//add cooking time by TimeToAdd command
// add cooking time by TimeToAdd command
auto & TimeToAdd = commandData.timeToAdd;
uint32_t currentCookTime;
uint32_t addedCookTime;
emberAfStatus = CookTime::Get(endpointId, &currentCookTime);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = app::ToInteractionModelStatus(emberAfStatus);
ChipLogError(Zcl,"Failed to get cuurent cooking time");
ChipLogError(Zcl, "Failed to get cuurent cooking time");
goto exit;
}

addedCookTime = currentCookTime + TimeToAdd;
//if the added cooking time is greater than the max cooking time, the cooking time stay unchanged.
if(addedCookTime < kMaxCookTime)
// if the added cooking time is greater than the max cooking time, the cooking time stay unchanged.
if (addedCookTime < kMaxCookTime)
{
emberAfStatus = CookTime::Set(endpointId, addedCookTime);
if(emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
if (emberAfStatus != EMBER_ZCL_STATUS_SUCCESS)
{
status = Status::InvalidInState;
ChipLogError(Zcl, "Failed to set cookTime with value = %ld",addedCookTime);
ChipLogError(Zcl, "Failed to set cookTime with value = %ld", addedCookTime);
goto exit;
}
}
else
{
status = Status::ConstraintError;
ChipLogError(Zcl,"Failed to set cookTime, cookTime value is out of range");
ChipLogError(Zcl, "Failed to set cookTime, cookTime value is out of range");
goto exit;
}
}
else // operational state is in error
else // operational state is in error
{
status = Status::InvalidInState;
goto exit;
Expand All @@ -291,7 +290,6 @@ bool emberAfMicrowaveOvenControlClusterAddMoreTimeCallback(

commandObj->AddStatus(commandPath, status);
return true;

}

/** @brief Microwave Oven Control Cluster Server Init
Expand Down

0 comments on commit fbc53e3

Please sign in to comment.