8000 feat: add Chef Microwave Oven device by stingchang · Pull Request #39221 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add Chef Microwave Oven device #39221

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

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d2a5f91
add: chef app for microwave oven
gcobs0834 Apr 24, 2025
dc2b705
rebase master
gcobs0834 Apr 25, 2025
82934db
change file name
gcobs0834 Apr 25, 2025
9cc93d3
remove old files
gcobs0834 Apr 25, 2025
ad90549
Merge remote-tracking branch 'upstream/master' into microwave-chef
gcobs0834 Apr 28, 2025
9db17cf
add: add required attribute
gcobs0834 May 1, 2025
536703e
fix typo
gcobs0834 May 1, 2025
18cde60
Restyled by whitespace
restyled-commits May 1, 2025
98d17a6
Merge branch 'master' into microwave-chef
gcobs0834 May 1, 2025
9003dd9
merge master
gcobs0834 May 1, 2025
2d2e80d
add microwave oven control cluster impl
stingchang May 27, 2025
da99de1
Restyled by whitespace
restyled-commits May 27, 2025
2791ceb
Restyled by clang-format
restyled-commits May 27, 2025
a0cd475
Merge branch 'master' into pr-38628-work-copy
stingchang May 27, 2025
3a5b1b7
Merge branch 'master' into pr-38628-work-copy
stingchang May 28, 2025
fef83f3
remove multiple type inheritance
stingchang May 28, 2025
f997e93
Restyled by clang-format
restyled-commits May 28, 2025
dc3bc75
Merge branch 'master' into pr-38628-work-copy
stingchang May 28, 2025
552fe5f
ModeTagStructType
stingchang May 28, 2025
1be10ea
t Merge branch 'master' into pr-38628-work-copy
stingchang Jun 2, 2025
0693ac8
update pointer
stingchang Jun 9, 2025
d230b87
Merge branch 'master' into pr-38628-work-copy
stingchang Jun 9, 2025
7787c7d
Restyled by whitespace
restyled-commits Jun 9, 2025
845f2c3
Restyled by clang-format
restyled-commits Jun 9, 2025
1990b3b
rebuild matter file, enable WattRating attribute
stingchang Jun 10, 2025
8f941c2
Merge branch 'master' into pr-38628-work-copy
stingchang Jun 10, 2025
519f637
determine endpoint when device start
stingchang Jun 10, 2025
c10be2e
Restyled by clang-format
restyled-commits Jun 10, 2025
aafb94d
Merge branch 'master' into pr-38628-work-copy
stingchang Jun 11, 2025
c9e9112
fix ptr
stingchang Jun 11, 2025
132dd6b
Restyled by whitespace
restyled-commits Jun 11, 2025
42bd0d9
Restyled by clang-format
restyled-commits Jun 11, 2025
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
@@ -0,0 +1,129 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "chef-microwave-oven-control.h"
#include <app/util/attribute-storage.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::OperationalState;
using namespace chip::app::Clusters::ModeBase;
using namespace chip::app::Clusters::MicrowaveOvenControl;
template <typename T>
using List = chip::app::DataModel::List<T>;
using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;
using Status = Protocols::InteractionModel::Status;

#ifdef MATTER_DM_PLUGIN_MICROWAVE_OVEN_CONTROL_SERVER

ChefMicrowaveOvenDevice::ChefMicrowaveOvenDevice(EndpointId aClustersEndpoint) :
mOperationalStateInstancePtr(OperationalState::GetOperationalStateInstance()),
mMicrowaveOvenModeInstancePtr(ChefMicrowaveOvenMode::GetInstance(aClustersEndpoint)),
mMicrowaveOvenControlInstance(this, aClustersEndpoint, MicrowaveOvenControl::Id,
BitMask<MicrowaveOvenControl::Feature>(MicrowaveOvenControl::Feature::kPowerAsNumber,
MicrowaveOvenControl::Feature::kPowerNumberLimits),
*mOperationalStateInstancePtr, *mMicrowaveOvenModeInstancePtr)
{
VerifyOrDie(mOperationalStateInstancePtr != nullptr);
VerifyOrDie(mMicrowaveOvenModeInstancePtr != nullptr);
}

void ChefMicrowaveOvenDevice::MicrowaveOvenInit()
{
mOperationalStateInstancePtr->SetOperationalState(to_underlying(OperationalStateEnum::kStopped));
mMicrowaveOvenControlInstance.Init();
}

/**
* MicrowaveOvenControl cluster
*/
Protocols::InteractionModel::Status
ChefMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTimeSec, bool startAfterSetting,
Optional<uint8_t> powerSettingNum, Optional<uint8_t> wattSettingIndex)
{
Status status;
// Update cook mode.
if ((status = mMicrowaveOvenModeInstancePtr->UpdateCurrentMode(cookMode)) != Status::Success)
{
return status;
}

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 (startAfterSetting)
{
mOperationalStateInstancePtr->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
}

return Status::Success;
}

Protocols::InteractionModel::Status ChefMicrowaveOvenDevice::HandleModifyCookTimeSecondsCallback(uint32_t finalCookTimeSec)
{
mMicrowaveOvenControlInstance.SetCookTimeSec(finalCookTimeSec);
return Status::Success;
}

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

wattSetting = mWattSettingList[index];
return CHIP_NO_ERROR;
}

namespace {
constexpr size_t kMicrowaveOvenDeviceSize = MATTER_DM_MICROWAVE_OVEN_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT;
static_assert(kMicrowaveOvenDeviceSize <= kEmberInvalidEndpointIndex, "MicrowaveOvenDevice table size error");

std::unique_ptr<ChefMicrowaveOvenDevice> gMicrowaveOvenDevice[kMicrowaveOvenDeviceSize];
} // namespace

void InitChefMicrowaveOvenControlCluster()
{
ChipLogProgress(NotSpecified, "Deferred Initializing MicrowaveOvenControl cluster for all relevant endpoints.");
for (uint16_t i = 0; i < emberAfEndpointCount(); ++i)
{
EndpointId endpoint = emberAfEndpointFromIndex(i);
if (emberAfContainsServer(endpoint, MicrowaveOvenControl::Id))
{
uint16_t epIndex = emberAfGetClusterServerEndpointIndex(endpoint, MicrowaveOvenControl::Id, kMicrowaveOvenDeviceSize);
if (epIndex < kMicrowaveOvenDeviceSize)
{
// Check if an instance already exists for this endpoint.
if (gMicrowaveOvenDevice[epIndex])
{
continue;
}
gMicrowaveOvenDevice[epIndex] = std::make_unique<ChefMicrowaveOvenDevice>(endpoint);
gMicrowaveOvenDevice[epIndex]->MicrowaveOvenInit();
}
}
}
}

#endif // MATTER_DM_PLUGIN_MICROWAVE_OVEN_CONTROL_SERVER
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/clusters/microwave-oven-control-server/microwave-oven-control-server.h>
#include <app/util/config.h>
#include <cstring>
#include <protocols/interaction_model/StatusCode.h>
#include <utility>

#include "../../chef-operational-state-delegate-impl.h"
#include "../microwave-oven-mode/chef-microwave-oven-mode.h"

#ifdef MATTER_DM_PLUGIN_MICROWAVE_OVEN_CONTROL_SERVER

namespace chip {
namespace app {
namespace Clusters {

class ChefMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate
{
public:
explicit ChefMicrowaveOvenDevice(EndpointId aClustersEndpoint);

void MicrowaveOvenInit();

/**
* handle command for microwave oven control: set cooking parameters
*/
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 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;

uint8_t GetPowerSettingNum() const override { return mPowerSettingNum; }

uint8_t GetMinPowerNum() const override { return kMinPowerNum; }

uint8_t GetMaxPowerNum() const override { return kMaxPowerNum; }

uint8_t GetPowerStepNum() const override { return kPowerStepNum; }

uint32_t GetMaxCookTimeSec() const override { return 100; }

uint8_t GetCurrentWattIndex() const override { return mSelectedWattIndex; };

uint16_t GetWattRating() const override { return mWattRating; };

private:
chip::app::Clusters::OperationalState::Instance * mOperationalStateInstancePtr;
chip::app::Clusters::ModeBase::Instance * mMicrowaveOvenModeInstancePtr;

MicrowaveOvenControl::Instance mMicrowaveOvenControlInstance;

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 = kMaxPowerNum;

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;

uint8_t mPowerSettingNum = kDefaultPowerSettingNum;
uint8_t mSelectedWattIndex = 0;
uint16_t mWattRating = 0;

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

} // namespace Clusters
} // namespace app
} // namespace chip

void InitChefMicrowaveOvenControlCluster();

#endif // MATTER_DM_PLUGIN_MICROWAVE_OVEN_CONTROL_SERVER
F438
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "chef-microwave-oven-mode.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>
#include <app/util/endpoint-config-api.h>
#include <lib/support/logging/CHIPLogging.h>

#ifdef MATTER_DM_PLUGIN_MICROWAVE_OVEN_MODE_SERVER

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeBase;
using chip::Protocols::InteractionModel::Status;
template <typename T>
using List = chip::app::DataModel::List<T>;
using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;

namespace ChefMicrowaveOvenMode {

constexpr size_t kMicrowaveOvenModeTableSize = MATTER_DM_MICROWAVE_OVEN_MODE_CLUSTER_SERVER_ENDPOINT_COUNT;
static_assert(kMicrowaveOvenModeTableSize <= kEmberInvalidEndpointIndex, "MicrowaveOvenMode table size error");

std::unique_ptr<MicrowaveOvenMode::ChefDelegate> gDelegateTable[kMicrowaveOvenModeTableSize];
std::unique_ptr<ModeBase::Instance> gInstanceTable[kMicrowaveOvenModeTableSize];

/**
* Initializes MicrowaveOvenMode cluster for the app (all endpoints).
*/
void InitChefMicrowaveOvenModeCluster()
{
const uint16_t endpointCount = emberAfEndpointCount();

for (uint16_t endpointIndex = 0; endpointIndex < endpointCount; endpointIndex++)
{
EndpointId endpointId = emberAfEndpointFromIndex(endpointIndex);
if (endpointId == kInvalidEndpointId)
{
continue;
}

// Check if endpoint has MicrowaveOvenMode cluster enabled
uint16_t epIndex = emberAfGetClusterServerEndpointIndex(endpointId, MicrowaveOvenMode::Id,
MATTER_DM_MICROWAVE_OVEN_MODE_CLUSTER_SERVER_ENDPOINT_COUNT);
if (epIndex >= kMicrowaveOvenModeTableSize)
continue;

gDelegateTable[epIndex] = std::make_unique<MicrowaveOvenMode::ChefDelegate>();
gDelegateTable[epIndex]->Init();

constexpr uint32_t featureMap = 0;
gInstanceTable[epIndex] =
std::make_unique<ModeBase::Instance>(gDelegateTable[epIndex].get(), endpointId, MicrowaveOvenMode::Id, featureMap);
gInstanceTable[epIndex]->Init();

ChipLogProgress(DeviceLayer, "Endpoint %d MicrowaveOvenMode Initialized.", endpointId);
}
}

ModeBase::Instance * GetInstance(EndpointId endpointId)
{
uint16_t epIndex = emberAfGetClusterServerEndpointIndex(endpointId, MicrowaveOvenMode::Id,
MATTER_DM_MICROWAVE_OVEN_MODE_CLUSTER_SERVER_ENDPOINT_COUNT);
if (epIndex < kMicrowaveOvenModeTableSize)
{
return gInstanceTable[epIndex].get();
}
return nullptr;
}
} // namespace ChefMicrowaveOvenMode

CHIP_ERROR MicrowaveOvenMode::ChefDelegate::Init()
{
return CHIP_NO_ERROR;
}

void MicrowaveOvenMode::ChefDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands::ChangeToModeResponse::Type & response)
{
EndpointId endpointId = mInstance->GetEndpointId();
ChipLogDetail(DeviceLayer, "HandleChangeToMode: Endpoint %d", endpointId);
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
}

CHIP_ERROR MicrowaveOvenMode::ChefDelegate::GetModeLabelByIndex(uint8_t modeIndex, chip::MutableCharSpan & label)
{
EndpointId endpointId = mInstance->GetEndpointId();
ChipLogDetail(DeviceLayer, "GetModeLabelByIndex: Endpoint %d", endpointId);
if (modeIndex >= MATTER_ARRAY_SIZE(kModeOptions))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
return chip::CopyCharSpanToMutableCharSpan(kModeOptions[modeIndex].label, label);
}

CHIP_ERROR MicrowaveOvenMode::ChefDelegate::GetModeValueByIndex(uint8_t modeIndex, uint8_t & value)
{
EndpointId endpointId = mInstance->GetEndpointId();
ChipLogDetail(DeviceLayer, "GetModeValueByIndex: Endpoint %d", endpointId);
if (modeIndex >= MATTER_ARRAY_SIZE(kModeOptions))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}
value = kModeOptions[modeIndex].mode;
return CHIP_NO_ERROR;
}

CHIP_ERROR MicrowaveOvenMode::ChefDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTagStructType> & tags)
{
EndpointId endpointId = mInstance->GetEndpointId();
ChipLogDetail(DeviceLayer, "GetModeTagsByIndex: Endpoint %d", endpointId);
if (modeIndex >= MATTER_ARRAY_SIZE(kModeOptions))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}

if (tags.size() < kModeOptions[modeIndex].modeTags.size())
{
return CHIP_ERROR_INVALID_ARGUMENT;
}

std::copy(kModeOptions[modeIndex].modeTags.begin(), kModeOptions[modeIndex].modeTags.end(), tags.begin());
tags.reduce_size(kModeOptions[modeIndex].modeTags.size());

return CHIP_NO_ERROR;
}

#endif // MATTER_DM_PLUGIN_Microwave_OVEN_MODE_SERVER
Loading
Loading
0