Skip to content

Commit

Permalink
add api for ModeBase and updated MicrowaveOvenControl
Browse files Browse the repository at this point in the history
  • Loading branch information
liangpy4 committed Dec 15, 2023
1 parent ec23337 commit c6f9a0d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
* @param aClustersEndpoint The endpoint ID where all the microwave oven clusters exist.
*/
explicit ExampleMicrowaveOvenDevice(EndpointId aClustersEndpoint) :
mOperationalStateInstance(this, aClustersEndpoint, OperationalState::Id),
mOperationalStateInstance(this, aClustersEndpoint),
mMicrowaveOvenModeInstance(this, aClustersEndpoint, MicrowaveOvenMode::Id, 0),
mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id, mOperationalStateInstance,
mMicrowaveOvenModeInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
ChipLogDetail(Zcl, "Microwave Oven Control: HandleSetCookingParameters");
Status status;
uint8_t opState;
uint8_t modeValue;
uint8_t reqCookMode;
uint32_t reqCookTime;
uint8_t reqPowerSetting;
Expand All @@ -172,7 +173,12 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
VerifyOrExit(cookMode.HasValue() || cookTime.HasValue() || powerSetting.HasValue(), status = Status::InvalidCommand;
ChipLogError(Zcl, "Microwave Oven Control: Failed to set cooking parameters, all command fields are missing "));

reqCookMode = cookMode.ValueOr(to_underlying(MicrowaveOvenMode::ModeTag::kNormal) - kDerivedModeTag);
modeValue = 0;
VerifyOrExit(mMicrowaveOvenModeInstance.GetModeValueByModeTag(to_underlying(MicrowaveOvenMode::ModeTag::kNormal), modeValue) == CHIP_NO_ERROR,
status = Status::InvalidCommand;
ChipLogError(Zcl, "Microwave Oven Control: Failed to set cookMode, Normal mode is not found"));

reqCookMode = cookMode.ValueOr(modeValue);
VerifyOrExit(mMicrowaveOvenModeInstance.IsSupportedMode(reqCookMode), status = Status::InvalidCommand;
ChipLogError(Zcl, "Microwave Oven Control: Failed to set cookMode, cookMode is not supported"));

Expand Down
20 changes: 20 additions & 0 deletions src/app/clusters/mode-base-server/mode-base-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,26 @@ bool Instance::IsSupportedMode(uint8_t modeValue)
return false;
}

CHIP_ERROR Instance::GetModeValueByModeTag(uint16_t modeTagValue, uint8_t & value)
{
ModeTagStructType tagsBuffer[kMaxNumOfModeTags];
DataModel::List<ModeTagStructType> mTags(tagsBuffer);
for (uint8_t i = 0; mDelegate->GetModeTagsByIndex(i, mTags) != CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; i++)
{
for(uint8_t ii = 0; ii < mTags.size() ;ii++)
{
if (mTags[ii].value == modeTagValue)
{
mDelegate->GetModeValueByIndex(i, value);
return CHIP_NO_ERROR;
}
}
mTags = tagsBuffer;
}
ChipLogDetail(Zcl, "Cannot find a mode with mode tag %x", modeTagValue);
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}

// private methods
template <typename RequestT, typename FuncT>
void Instance::HandleCommand(HandlerContext & handlerContext, FuncT func)
Expand Down
3 changes: 3 additions & 0 deletions src/app/clusters/mode-base-server/mode-base-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface
// Unregisters this instance if already registered.
void Shutdown();

// Get mode value by mode tag
CHIP_ERROR GetModeValueByModeTag(uint16_t modeTag, uint8_t & value);

private:
Delegate * mDelegate;

Expand Down

0 comments on commit c6f9a0d

Please sign in to comment.