Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]Microwave oven control cluster implementation - add watt setting #31130

Merged
merged 58 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3aa7609
update .xml and .json
liangpy4 Dec 18, 2023
f6216ad
add src/controller
liangpy4 Dec 18, 2023
b1ab642
regen ZAP, add new attributes for microwave oven control cluster
liangpy4 Dec 18, 2023
99f018e
update MicrowaveOvenDevice SDK and APP
liangpy4 Dec 20, 2023
9352679
update comment for MWO
liangpy4 Dec 20, 2023
768e35a
merge master
liangpy4 Dec 20, 2023
c64fd56
Restyled by whitespace
restyled-commits Dec 20, 2023
5eb9153
Restyled by clang-format
restyled-commits Dec 20, 2023
ec590c4
Restyled by prettier-json
restyled-commits Dec 20, 2023
0e525e0
Restyled by isort
restyled-commits Dec 20, 2023
7cad0e9
update XML
liangpy4 Dec 21, 2023
6284485
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Dec 21, 2023
08ddace
update MWO after reviewed
liangpy4 Dec 22, 2023
4605d0d
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Dec 22, 2023
daa26a2
Restyled by clang-format
restyled-commits Dec 22, 2023
e9e6a7c
update MWO sdk after reviewed
liangpy4 Dec 22, 2023
a08ae0e
Restyled by clang-format
restyled-commits Dec 22, 2023
03ec53d
update microwave-oven-device.h
liangpy4 Dec 25, 2023
c11967b
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Dec 25, 2023
a64564a
update MWC-wattSetting after reviewed
liangpy4 Jan 3, 2024
8f72969
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 3, 2024
9b9022e
update comment for HandleSetCookingParametersCallback method
liangpy4 Jan 8, 2024
798db00
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 8, 2024
d4dc555
update MWOCTRL, add new feature PowerInLimits
liangpy4 Jan 10, 2024
3ddd84a
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 10, 2024
98c51b8
push test
liangpy4 Jan 10, 2024
a1c42ed
Restyled by whitespace
restyled-commits Jan 10, 2024
d3d3203
Restyled by clang-format
restyled-commits Jan 10, 2024
3a9c3b2
regen_all and rebuild
liangpy4 Jan 10, 2024
a70e1f6
update MWOCTRL after review
liangpy4 Jan 11, 2024
85c56f2
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 11, 2024
e692620
Restyled by whitespace
restyled-commits Jan 11, 2024
06d12b7
Restyled by clang-format
restyled-commits Jan 11, 2024
b154932
update code after reviewed
liangpy4 Jan 12, 2024
33672ed
merge chip-master
liangpy4 Jan 12, 2024
831338f
update code after reviewed
liangpy4 Jan 12, 2024
0ef9a63
Restyled by whitespace
restyled-commits Jan 12, 2024
f58103b
Restyled by clang-format
restyled-commits Jan 12, 2024
6d7d19f
Restyled by autopep8
restyled-commits Jan 12, 2024
97f7443
update code after reviewed
liangpy4 Jan 13, 2024
ba41f30
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 13, 2024
3d1f15f
update code after reviewed
liangpy4 Jan 13, 2024
cdbd7bf
Restyled by whitespace
restyled-commits Jan 13, 2024
6aa7e78
Restyled by clang-format
restyled-commits Jan 13, 2024
27bb9b4
update code, adding new checking for powerSetting Number
liangpy4 Jan 15, 2024
34d4153
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 15, 2024
1be1bfe
fix restyled issue
liangpy4 Jan 15, 2024
39e37f9
Restyled by whitespace
restyled-commits Jan 15, 2024
23abc48
Restyled by clang-format
restyled-commits Jan 15, 2024
ef42038
update code after reviewed
liangpy4 Jan 16, 2024
4f44bb9
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 16, 2024
9394adc
fix restyled issue
liangpy4 Jan 16, 2024
9be4d15
Restyled by whitespace
restyled-commits Jan 16, 2024
4265e66
Restyled by clang-format
restyled-commits Jan 16, 2024
55854d7
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 16, 2024
0db4b76
update code after reviewed
liangpy4 Jan 17, 2024
f43291d
Merge branch 'chip-master' into sdk-microwave-2
liangpy4 Jan 17, 2024
b2d8108
Restyled by clang-format
restyled-commits Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 GetCurrentWattRating() const override { return mWattRating; };
liangpy4 marked this conversation as resolved.
Show resolved Hide resolved

// 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 = 110u;
liangpy4 marked this conversation as resolved.
Show resolved Hide resolved
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,19 @@ 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 supportedWatts;
callback attribute selectedWattIndex;
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,
liangpy4 marked this conversation as resolved.
Show resolved Hide resolved
"reportableChange": 0
},
{
"name": "MaxCookTime",
"code": 1,
"mfgCode": null,
"side": "server",
Expand Down Expand Up @@ -3261,6 +3277,54 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "SupportedWatts",
"code": 6,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "SelectedWattIndex",
"code": 7,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "WattRating",
"code": 8,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down Expand Up @@ -3332,10 +3396,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,79 @@ 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;
liangpy4 marked this conversation as resolved.
Show resolved Hide resolved
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 (powerSettingNum.HasValue())
{
mPowerSettingNum = powerSettingNum.Value();
liangpy4 marked this conversation as resolved.
Show resolved Hide resolved
}

// if using power in watt, check if wattSettingIndex has value before setting the watt rating and watt list index
if (wattSettingIndex.HasValue())
{
mSelectedWattIndex = wattSettingIndex.Value();
mWattRating = mWattSettingList[mSelectedWattIndex];
}
liangpy4 marked this conversation as resolved.
Show resolved Hide resolved

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
Loading