Skip to content

Commit

Permalink
Enable chef robotic vacuum cleaner device
Browse files Browse the repository at this point in the history
  • Loading branch information
stingchang committed May 1, 2024
1 parent 5570be9 commit 802b861
Show file tree
Hide file tree
Showing 9 changed files with 822 additions and 111 deletions.
94 changes: 89 additions & 5 deletions examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#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;
Expand Down Expand Up @@ -106,17 +108,60 @@ void RvcRunMode::Shutdown()
}
}

chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer)
{
chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success;

VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcRunModeInstance != nullptr);

ModeBase::Instance * clusterInstance = gRvcRunModeInstance;
chip::AttributeId attributeId = attributeMetadata->attributeId;

switch (attributeId)
{
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
chip::Protocols::InteractionModel::Status status = clusterInstance->UpdateCurrentMode(m);
if (chip::Protocols::InteractionModel::Status::Success == status)
{
break;
}
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(status));
}
break;
default:
ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute;
ChipLogError(DeviceLayer, "Unsupported 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)
{

return chip::Protocols::InteractionModel::Status::Success;
}

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));
new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff));
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;
Expand Down Expand Up @@ -197,6 +242,46 @@ void RvcCleanMode::Shutdown()
}
}

chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer)
{
chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success;

VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcCleanModeInstance != nullptr);

ModeBase::Instance * clusterInstance = gRvcCleanModeInstance;
chip::AttributeId attributeId = attributeMetadata->attributeId;

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

return ret;
}

chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
uint16_t maxReadLength)
{
return chip::Protocols::InteractionModel::Status::Success;
}

void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
Expand All @@ -206,5 +291,4 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff));
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
18 changes: 18 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,19 @@ 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

0 comments on commit 802b861

Please sign in to comment.