Skip to content

Commit

Permalink
compiling app, sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
liangpy4 committed Nov 29, 2023
1 parent 8f3bac4 commit b5d680f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public
/**
* handle command for microwave oven control: set cooking parameters
*/
Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime,
Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional<uint8_t> cookMode, uint32_t cookTime,
uint8_t powerSetting) override;

/**
* handle command for microwave oven control: add more time
*/
Protocols::InteractionModel::Status HandleSetCookTimeCallback(uint32_t finalCookTime) override;
Protocols::InteractionModel::Status HandleModifyCookTimeCallback(uint32_t finalCookTime) override;

/**
* Get the value of MinPower.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ void ExampleMicrowaveOvenDevice::MicrowaveOvenInit(EndpointId aEndpoint)
* MicrowaveOvenControl cluster
*/
Protocols::InteractionModel::Status
ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, uint8_t powerSetting)
ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(Optional<uint8_t> cookMode, uint32_t cookTime, uint8_t powerSetting)
{
// placeholder implementation
Status status;
if((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(cookMode)) != Status::Success)
uint8_t reqCookMode;
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)
{
return status;
}
Expand All @@ -55,7 +65,7 @@ ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode,
return Status::Success;
}

Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleSetCookTimeCallback(uint32_t finalCookTime)
Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleModifyCookTimeCallback(uint32_t finalCookTime)
{
// placeholder implementation
mMicrowaveOvenControlInstance.SetCookTime(finalCookTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ 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)
{
ChipLogError(Zcl, "Microwave Oven Control: Operational State instance is NULL");
return CHIP_ERROR_INVALID_ARGUMENT;
}
if(!mMicrowaveOvenModeInstance)
{
ChipLogError(Zcl, "Microwave Oven Control: Microwave Oven Mode instance is NULL");
return CHIP_ERROR_INVALID_ARGUMENT;
}
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this));
VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE);

Expand Down Expand Up @@ -183,23 +192,18 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
ChipLogError(Zcl, "Failed to set cookPower, cookPower value is out of range");
goto exit;
}

//get current operational state
opState = mOpStateInstance->GetCurrentOperationalState();
if (opState == to_underlying(OperationalStateEnum::kStopped))
if(opState != to_underlying(OperationalStateEnum::kStopped))
{
status = Status::InvalidInState;
goto exit;
}
else
{
uint8_t reqCookMode = 0;
uint32_t reqCookTime = 0;
uint8_t reqPowerSetting = 0;
if (cookMode.HasValue())
{
reqCookMode = cookMode.Value();
}
else
{
// set Microwave Oven cooking mode to normal mode(default).
reqCookMode = Clusters::ModeNormal;
}

if (cookTime.HasValue())
{
Expand All @@ -220,13 +224,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
// set Microwave Oven cooking power to max power(default).
reqPowerSetting = mDelegate->GetMaxPower();
}
status = mDelegate->HandleSetCookingParametersCallback(reqCookMode, reqCookTime, reqPowerSetting);
goto exit;
}
else
{
status = Status::InvalidInState;
goto exit;
status = mDelegate->HandleSetCookingParametersCallback(cookMode, reqCookTime, reqPowerSetting);
}

exit:
Expand All @@ -250,7 +248,7 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi
// if the added cooking time is greater than the max cooking time, the cooking time stay unchanged.
if (finalCookTime < kMaxCookTime)
{
status = mDelegate->HandleSetCookTimeCallback(finalCookTime);
status = mDelegate->HandleModifyCookTimeCallback(finalCookTime);
goto exit;
}
else
Expand All @@ -260,7 +258,7 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi
goto exit;
}
}
else // operational state is in error
else // operational state is 'Error'
{
status = Status::InvalidInState;
goto exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface
/**
* Operational State instance
*/
Clusters::OperationalState::Instance * mOpStateInstance;
Clusters::OperationalState::Instance * mOpStateInstance = nullptr;
/**
* Microwave Oven Mode instance
*/
Clusters::ModeBase::Instance * mMicrowaveOvenModeInstance;
Clusters::ModeBase::Instance * mMicrowaveOvenModeInstance = nullptr;

/**
* set default values
Expand Down Expand Up @@ -130,15 +130,19 @@ class Delegate
/**
* @brief Handle Command Callback in application: SetCookingParameters
* @return Returns the Interaction Model status code which was user determined in the business logic
* @param cookMode: the user defined modes which from the Microwave Oven Mode application level
* @param cookTime: the input cook time value
* @param powerSetting: the input power setting value
*/
virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime,
virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional<uint8_t> cookMode, uint32_t cookTime,
uint8_t powerSetting) = 0;

/**
* @brief Handle Command Callback in application: AddMoreTime
* @return Returns the Interaction Model status code which was user determined in the business logic
* @param finalCookTime: the cook time value after adding input time
*/
virtual Protocols::InteractionModel::Status HandleSetCookTimeCallback(uint32_t finalCookTime) = 0;
virtual Protocols::InteractionModel::Status HandleModifyCookTimeCallback(uint32_t finalCookTime) = 0;

/**
* @brief get the MinPower
Expand Down

0 comments on commit b5d680f

Please sign in to comment.