Skip to content

Commit

Permalink
[Feature]Microwave oven control cluster implementation - add watt set…
Browse files Browse the repository at this point in the history
…ting (project-chip#31130)

* update .xml and .json

* add src/controller

* regen ZAP, add new attributes for microwave oven control cluster

* update MicrowaveOvenDevice SDK and APP

* update comment for MWO

* Restyled by whitespace

* Restyled by clang-format

* Restyled by prettier-json

* Restyled by isort

* update XML

* update MWO after reviewed

* Restyled by clang-format

* update MWO sdk after reviewed

* Restyled by clang-format

* update microwave-oven-device.h

* update MWC-wattSetting after reviewed

* update comment for HandleSetCookingParametersCallback method

* update MWOCTRL, add new feature PowerInLimits

* push test

* Restyled by whitespace

* Restyled by clang-format

* regen_all and rebuild

* update MWOCTRL after review

* Restyled by whitespace

* Restyled by clang-format

* update code after reviewed

* update code after reviewed

* Restyled by whitespace

* Restyled by clang-format

* Restyled by autopep8

* update code after reviewed

* update code after reviewed

* Restyled by whitespace

* Restyled by clang-format

* update code, adding new checking for powerSetting Number

* fix restyled issue

* Restyled by whitespace

* Restyled by clang-format

* update code after reviewed

* fix restyled issue

* Restyled by whitespace

* Restyled by clang-format

* update code after reviewed

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
liangpy4 and restyled-commits authored Jan 17, 2024
1 parent 4abbe28 commit 09f014c
Show file tree
Hide file tree
Showing 39 changed files with 2,242 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ namespace chip {
namespace app {
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
Expand All @@ -56,8 +46,10 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
explicit ExampleMicrowaveOvenDevice(EndpointId aClustersEndpoint) :
mOperationalStateInstance(this, aClustersEndpoint),
mMicrowaveOvenModeInstance(this, aClustersEndpoint, MicrowaveOvenMode::Id, 0),
mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id, mOperationalStateInstance,
mMicrowaveOvenModeInstance)
mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id,
BitMask<MicrowaveOvenControl::Feature>(MicrowaveOvenControl::Feature::kPowerAsNumber,
MicrowaveOvenControl::Feature::kPowerNumberLimits),
mOperationalStateInstance, mMicrowaveOvenModeInstance)
{}

/**
Expand All @@ -69,28 +61,60 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
/**
* handle command for microwave oven control: set cooking parameters
*/
Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime,
uint8_t powerSetting) override;
Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTimeSec,
bool startAfterSetting,
Optional<uint8_t> powerSettingNum,
Optional<uint8_t> wattSettingIndex) override;

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

/**
* Get the watt setting from the supported watts array.
* @param index The index of the watt setting to be returned. It is assumed that watt setting are indexable from 0 and with no
* gaps.
* @param wattSetting A reference to receive the watt setting on success.
* @return Returns a CHIP_NO_ERROR if there was no error and the label was returned successfully.
* CHIP_ERROR_NOT_FOUND if the index in beyond the list of available labels.
*/
CHIP_ERROR GetWattSettingByIndex(uint8_t index, uint16_t & wattSetting) override;

/**
* Get the value of power setting number.
*/
uint8_t GetPowerSettingNum() const override { return mPowerSettingNum; }

/**
* Get the value of min power number.
*/
uint8_t GetMinPowerNum() const override { return kMinPowerNum; }

/**
* Get the value of MinPower.
* Get the value of max power number.
*/
uint8_t GetMinPower() const override { return kDefaultMinPower; }
uint8_t GetMaxPowerNum() const override { return kMaxPowerNum; }

/**
* Get the value of MaxPower.
* Get the value of power step number.
*/
uint8_t GetMaxPower() const override { return kDefaultMaxPower; }
uint8_t GetPowerStepNum() const override { return kPowerStepNum; }

/**
* Get the value of PowerStep.
* Get the value of max cook time in seconds.
*/
uint8_t GetPowerStep() const override { return kDefaultPowerStep; }
uint32_t GetMaxCookTimeSec() const override { return kMaxCookTimeSec; }

/**
* Get the value of selected watt index.
*/
uint8_t GetCurrentWattIndex() const override { return mSelectedWattIndex; };

/**
* Get the value of watt rating.
*/
uint16_t GetWattRating() const override { return mWattRating; };

// delegates from OperationalState cluster
using ModeTagStructType = detail::Structs::ModeTagStruct::Type;
Expand Down Expand Up @@ -201,16 +225,41 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
ModeBase::Instance mMicrowaveOvenModeInstance;
MicrowaveOvenControl::Instance mMicrowaveOvenControlInstance;

// set default value for the optional attributes
static constexpr uint8_t kMinPowerNum = 20u;
static constexpr uint8_t kMaxPowerNum = 90u;
static constexpr uint8_t kPowerStepNum = 10u;
static constexpr uint32_t kMaxCookTimeSec = 86400u;
static constexpr uint8_t kDefaultPowerSettingNum = 100u;

// define the mode value
static constexpr uint8_t kModeNormal = 0u;
static constexpr uint8_t kModeDefrost = 1u;

// define the example watts
static constexpr uint16_t kExampleWatt1 = 100u;
static constexpr uint16_t kExampleWatt2 = 300u;
static constexpr uint16_t kExampleWatt3 = 500u;
static constexpr uint16_t kExampleWatt4 = 800u;
static constexpr uint16_t kExampleWatt5 = 1000u;

// MicrowaveOvenControl variables
uint8_t mPowerSettingNum = kDefaultPowerSettingNum;
uint8_t mSelectedWattIndex = 0;
uint16_t mWattRating = 0;

const uint16_t mWattSettingList[5] = { kExampleWatt1, kExampleWatt2, kExampleWatt3, kExampleWatt4, kExampleWatt5 };

// MicrowaveOvenMode types
ModeTagStructType modeTagsNormal[1] = { { .value = to_underlying(MicrowaveOvenMode::ModeTag::kNormal) } };
ModeTagStructType modeTagsDefrost[1] = { { .value = to_underlying(MicrowaveOvenMode::ModeTag::kDefrost) } };

const detail::Structs::ModeOptionStruct::Type kModeOptions[2] = {
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Normal"),
.mode = ModeNormal,
.mode = kModeNormal,
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsNormal) },
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Defrost"),
.mode = ModeDefrost,
.mode = kModeDefrost,
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsDefrost) }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,11 +1033,21 @@ provisional cluster MicrowaveOvenMode = 94 {
provisional cluster MicrowaveOvenControl = 95 {
revision 1; // NOTE: Default/not specifically set

readonly attribute elapsed_s cookTime = 1;
readonly attribute int8u powerSetting = 2;
bitmap Feature : bitmap32 {
kPowerAsNumber = 0x1;
kPowerInWatts = 0x2;
kPowerNumberLimits = 0x4;
}

readonly attribute elapsed_s cookTime = 0;
readonly attribute elapsed_s maxCookTime = 1;
readonly attribute optional int8u powerSetting = 2;
readonly attribute optional int8u minPower = 3;
readonly attribute optional int8u maxPower = 4;
readonly attribute optional int8u powerStep = 5;
readonly attribute optional int16u supportedWatts[] = 6;
readonly attribute optional int8u selectedWattIndex = 7;
readonly attribute optional int16u wattRating = 8;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
Expand All @@ -1049,6 +1059,8 @@ provisional cluster MicrowaveOvenControl = 95 {
optional int8u cookMode = 0;
optional elapsed_s cookTime = 1;
optional int8u powerSetting = 2;
optional int8u wattSettingIndex = 3;
optional boolean startAfterSetting = 4;
}

request struct AddMoreTimeRequest {
Expand Down Expand Up @@ -1396,15 +1408,17 @@ endpoint 1 {

server cluster MicrowaveOvenControl {
callback attribute cookTime;
callback attribute maxCookTime;
callback attribute powerSetting;
callback attribute minPower;
callback attribute maxPower;
callback attribute powerStep;
callback attribute wattRating;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0;
callback attribute featureMap;
ram attribute clusterRevision default = 1;

handle command SetCookingParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,22 @@
"attributes": [
{
"name": "CookTime",
"code": 0,
"mfgCode": null,
"side": "server",
"type": "elapsed_s",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "MaxCookTime",
"code": 1,
"mfgCode": null,
"side": "server",
Expand Down Expand Up @@ -3261,6 +3277,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "WattRating",
"code": 8,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down Expand Up @@ -3332,10 +3364,10 @@
"side": "server",
"type": "bitmap32",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,83 @@ void ExampleMicrowaveOvenDevice::MicrowaveOvenInit()
mOperationalStateInstance.Init();
mMicrowaveOvenModeInstance.Init();
mMicrowaveOvenControlInstance.Init();

// set default value for attribute SelectedWattIndex and WattRating
if (mMicrowaveOvenControlInstance.HasFeature(MicrowaveOvenControl::Feature::kPowerInWatts))
{
static_assert(ArraySize(mWattSettingList) > 0, "Watt setting list is empty!");
mSelectedWattIndex = ArraySize(mWattSettingList) - 1;
mWattRating = mWattSettingList[mSelectedWattIndex];
}
else
{
mWattRating = kExampleWatt5;
}
}

/**
* MicrowaveOvenControl cluster
*/
Protocols::InteractionModel::Status
ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, uint8_t powerSetting)
ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTimeSec, bool startAfterSetting,
Optional<uint8_t> powerSettingNum,
Optional<uint8_t> wattSettingIndex)
{
// placeholder implementation
Status status;
// Update cook mode.
if ((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(cookMode)) != Status::Success)
{
return status;
}
mMicrowaveOvenControlInstance.SetCookTime(cookTime);
mMicrowaveOvenControlInstance.SetPowerSetting(powerSetting);

mMicrowaveOvenControlInstance.SetCookTimeSec(cookTimeSec);

// If using power as number, check if powerSettingNum has value before setting the power number.
// If powerSetting field is missing in the command, the powerSettingNum passed here is handled to the max value
// and user can use this value directly.
if (powerSettingNum.HasValue())
{
mPowerSettingNum = powerSettingNum.Value();
}

// If using power in watt, check if wattSettingIndex has value before setting the watt rating and watt list index.
// If wattSettinIndex field is missing in the command, the wattSettingIndex passed here is handled to the max value
// and user can use this value directly.
if (wattSettingIndex.HasValue())
{
mSelectedWattIndex = wattSettingIndex.Value();
mWattRating = mWattSettingList[mSelectedWattIndex];
}

if (startAfterSetting)
{
mOperationalStateInstance.SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
}
return Status::Success;
}

Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleModifyCookTimeCallback(uint32_t finalCookTime)
Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleModifyCookTimeSecondsCallback(uint32_t finalCookTimeSec)
{
// placeholder implementation
mMicrowaveOvenControlInstance.SetCookTime(finalCookTime);
mMicrowaveOvenControlInstance.SetCookTimeSec(finalCookTimeSec);
return Status::Success;
}

CHIP_ERROR ExampleMicrowaveOvenDevice::GetWattSettingByIndex(uint8_t index, uint16_t & wattSetting)
{
VerifyOrReturnError(index < ArraySize(mWattSettingList), CHIP_ERROR_NOT_FOUND);

wattSetting = mWattSettingList[index];
return CHIP_NO_ERROR;
}

/**
* OperationalState cluster
*/
app::DataModel::Nullable<uint32_t> ExampleMicrowaveOvenDevice::GetCountdownTime()
{
return DataModel::MakeNullable(mMicrowaveOvenControlInstance.GetCookTime());
return DataModel::MakeNullable(mMicrowaveOvenControlInstance.GetCookTimeSec());
}

CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalStateAtIndex(size_t index,
Expand Down
Loading

0 comments on commit 09f014c

Please sign in to comment.