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

Enable chef robotic vacuum cleaner device #33258

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
802b861
Enable chef robotic vacuum cleaner device
stingchang May 1, 2024
76e25cb
Restyled by whitespace
restyled-commits May 1, 2024
e9fe6f8
Restyled by clang-format
restyled-commits May 1, 2024
ab0da73
remove old rvc feature
stingchang May 2, 2024
83bf599
Restyled by clang-format
restyled-commits May 2, 2024
080d80c
update return status
stingchang May 3, 2024
9c3b9e7
Restyled by whitespace
restyled-commits May 3, 2024
4ffc4a9
Restyled by clang-format
restyled-commits May 3, 2024
2f49442
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 3, 2024
497d708
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 6, 2024
ed95550
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 6, 2024
23a0219
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 7, 2024
98ac87e
add back ifdef; remove old feature flag
stingchang May 7, 2024
3f9beca
Restyled by clang-format
restyled-commits May 7, 2024
c5eea35
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 7, 2024
67b77e0
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 11, 2024
9c84e08
write read attributes into buffer
stingchang May 11, 2024
11b4c03
Restyled by clang-format
restyled-commits May 11, 2024
3008435
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 13, 2024
0e89480
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 14, 2024
e6006a8
update readCallback write buffer
stingchang May 15, 2024
efcab14
Restyled by whitespace
restyled-commits May 15, 2024
09b57c1
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 20, 2024
a0d188c
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 23, 2024
c6314be
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 28, 2024
1bc1757
update buffer read in read call back
stingchang May 28, 2024
939bf7f
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 28, 2024
27ef480
Restyled by clang-format
restyled-commits May 28, 2024
7db7377
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 28, 2024
e7ed125
use static instance
stingchang May 28, 2024
b5ccbd4
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang May 28, 2024
284644f
Restyled by clang-format
restyled-commits May 28, 2024
b51c2b4
write attribute into buffer in callback
stingchang Jun 4, 2024
2ea5b3f
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang Jun 4, 2024
44dd73f
use unique_ptr
stingchang Jun 5, 2024
87539ff
Restyled by clang-format
restyled-commits Jun 5, 2024
056dcaf
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang Jun 5, 2024
10850f9
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang Jun 6, 2024
a9bcf50
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
stingchang Jun 6, 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
155 changes: 121 additions & 34 deletions examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

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

#ifdef ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
using namespace chip::app::Clusters::RvcRunMode;
static RvcRunModeDelegate * gRvcRunModeDelegate = nullptr;
static ModeBase::Instance * gRvcRunModeInstance = nullptr;

static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate;
static std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;

CHIP_ERROR RvcRunModeDelegate::Init()
{
Expand Down Expand Up @@ -87,40 +90,82 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTa
return CHIP_NO_ERROR;
}

ModeBase::Instance * RvcRunMode::Instance()
void RvcRunMode::Shutdown()
{
return gRvcRunModeInstance;
gRvcRunModeInstance.reset();
gRvcRunModeDelegate.reset();
}

void RvcRunMode::Shutdown()
chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer)
{
if (gRvcRunModeInstance != nullptr)
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
VerifyOrDie(gRvcRunModeInstance != nullptr);
chip::Protocols::InteractionModel::Status ret;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcRunModeInstance;
gRvcRunModeInstance = nullptr;
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
ret = gRvcRunModeInstance->UpdateCurrentMode(m);
if (chip::Protocols::InteractionModel::Status::Success != ret)
{
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
}
}
if (gRvcRunModeDelegate != nullptr)
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ChipLogError(DeviceLayer, "Unsupported Writng Attribute ID: %d", static_cast<int>(attributeId));
break;
}

return ret;
}

chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcRunModeDelegate;
gRvcRunModeDelegate = nullptr;
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
*buffer = gRvcRunModeInstance->GetCurrentMode();
ChipLogDetail(DeviceLayer, "Reading RunMode CurrentMode : %d", static_cast<int>(attributeId));
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcRunMode", static_cast<int>(attributeId));
break;
}

return ret;
}

void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr);
gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate;
gRvcRunModeInstance =
new ModeBase::Instance(gRvcRunModeDelegate, 0x1, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff));
VerifyOrDie(!gRvcRunModeDelegate && !gRvcRunModeInstance);

gRvcRunModeDelegate = std::make_unique<RvcRunModeDelegate>();
gRvcRunModeInstance = std::make_unique<ModeBase::Instance>(gRvcRunModeDelegate.get(), endpointId, RvcRunMode::Id,
chip::to_underlying(RvcRunMode::Feature::kNoFeatures));
gRvcRunModeInstance->Init();
}

#ifdef ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER

#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
#include <chef-rvc-mode-delegate.h>
using namespace chip::app::Clusters::RvcCleanMode;
static RvcCleanModeDelegate * gRvcCleanModeDelegate = nullptr;
static ModeBase::Instance * gRvcCleanModeInstance = nullptr;
static std::unique_ptr<RvcCleanModeDelegate> gRvcCleanModeDelegate;
static std::unique_ptr<ModeBase::Instance> gRvcCleanModeInstance;

CHIP_ERROR RvcCleanModeDelegate::Init()
{
Expand Down Expand Up @@ -178,33 +223,75 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mode
return CHIP_NO_ERROR;
}

ModeBase::Instance * RvcCleanMode::Instance()
void RvcCleanMode::Shutdown()
{
return gRvcCleanModeInstance;
gRvcCleanModeInstance.reset();
gRvcCleanModeDelegate.reset();
}

void RvcCleanMode::Shutdown()
chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer)
{
if (gRvcCleanModeInstance != nullptr)
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
VerifyOrDie(gRvcCleanModeInstance != nullptr);
chip::Protocols::InteractionModel::Status ret;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcCleanModeInstance;
gRvcCleanModeInstance = nullptr;
case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
ret = gRvcCleanModeInstance->UpdateCurrentMode(m);
if (chip::Protocols::InteractionModel::Status::Success != ret)
{
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
}
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
break;
}
if (gRvcCleanModeDelegate != nullptr)

return ret;
}

chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted);
buffer[0] = gRvcCleanModeInstance->GetCurrentMode();

chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
delete gRvcCleanModeDelegate;
gRvcCleanModeDelegate = nullptr;
case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: {
*buffer = gRvcCleanModeInstance->GetCurrentMode();
ChipLogDetail(DeviceLayer, "Reading CleanMode CurrentMode : %d", static_cast<int>(attributeId));
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcCleanMode", static_cast<int>(attributeId));
break;
}

return ret;
}

void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcCleanModeDelegate == nullptr && gRvcCleanModeInstance == nullptr);
gRvcCleanModeDelegate = new RvcCleanMode::RvcCleanModeDelegate;
gRvcCleanModeInstance =
new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff));
VerifyOrDie(!gRvcCleanModeDelegate && !gRvcCleanModeInstance);

gRvcCleanModeDelegate = std::make_unique<RvcCleanModeDelegate>();
gRvcCleanModeInstance = std::make_unique<ModeBase::Instance>(gRvcCleanModeDelegate.get(), endpointId, RvcCleanMode::Id,
chip::to_underlying(RvcCleanMode::Feature::kNoFeatures));
gRvcCleanModeInstance->Init();
}
#endif // ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
#endif // ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
20 changes: 20 additions & 0 deletions examples/chef/common/chef-rvc-mode-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <cstring>
#include <utility>

using chip::Protocols::InteractionModel::Status;

namespace chip {
namespace app {
namespace Clusters {
Expand Down Expand Up @@ -118,3 +120,21 @@ void Shutdown();
} // namespace Clusters
} // namespace app
} // namespace chip

#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength);
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER

#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer);
chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength);
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
Loading
Loading