Skip to content

Commit d15f6c1

Browse files
Enable chef robotic vacuum cleaner device (#33258)
* Enable chef robotic vacuum cleaner device * Restyled by whitespace * Restyled by clang-format * remove old rvc feature * Restyled by clang-format * update return status * Restyled by whitespace * Restyled by clang-format * add back ifdef; remove old feature flag * Restyled by clang-format * write read attributes into buffer * Restyled by clang-format * update readCallback write buffer * Restyled by whitespace * update buffer read in read call back * Restyled by clang-format * use static instance * Restyled by clang-format * write attribute into buffer in callback * use unique_ptr * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent be94090 commit d15f6c1

8 files changed

+862
-147
lines changed

examples/chef/common/chef-rvc-mode-delegate.cpp

+121-34
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
#include <app-common/zap-generated/attributes/Accessors.h>
1919
#include <app/util/config.h>
2020

21+
using namespace chip;
22+
using namespace chip::app;
2123
using namespace chip::app::Clusters;
2224
using chip::Protocols::InteractionModel::Status;
2325
template <typename T>
2426
using List = chip::app::DataModel::List<T>;
2527
using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type;
2628

27-
#ifdef ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
29+
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
2830
#include <chef-rvc-mode-delegate.h>
2931
using namespace chip::app::Clusters::RvcRunMode;
30-
static RvcRunModeDelegate * gRvcRunModeDelegate = nullptr;
31-
static ModeBase::Instance * gRvcRunModeInstance = nullptr;
32+
33+
static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate;
34+
static std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;
3235

3336
CHIP_ERROR RvcRunModeDelegate::Init()
3437
{
@@ -87,40 +90,82 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<ModeTa
8790
return CHIP_NO_ERROR;
8891
}
8992

90-
ModeBase::Instance * RvcRunMode::Instance()
93+
void RvcRunMode::Shutdown()
9194
{
92-
return gRvcRunModeInstance;
95+
gRvcRunModeInstance.reset();
96+
gRvcRunModeDelegate.reset();
9397
}
9498

95-
void RvcRunMode::Shutdown()
99+
chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
100+
const EmberAfAttributeMetadata * attributeMetadata,
101+
uint8_t * buffer)
96102
{
97-
if (gRvcRunModeInstance != nullptr)
103+
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
104+
VerifyOrDie(gRvcRunModeInstance != nullptr);
105+
chip::Protocols::InteractionModel::Status ret;
106+
chip::AttributeId attributeId = attributeMetadata->attributeId;
107+
108+
switch (attributeId)
98109
{
99-
delete gRvcRunModeInstance;
100-
gRvcRunModeInstance = nullptr;
110+
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
111+
uint8_t m = static_cast<uint8_t>(buffer[0]);
112+
ret = gRvcRunModeInstance->UpdateCurrentMode(m);
113+
if (chip::Protocols::InteractionModel::Status::Success != ret)
114+
{
115+
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
116+
}
101117
}
102-
if (gRvcRunModeDelegate != nullptr)
118+
break;
119+
default:
120+
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
121+
ChipLogError(DeviceLayer, "Unsupported Writng Attribute ID: %d", static_cast<int>(attributeId));
122+
break;
123+
}
124+
125+
return ret;
126+
}
127+
128+
chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
129+
const EmberAfAttributeMetadata * attributeMetadata,
130+
uint8_t * buffer, uint16_t maxReadLength)
131+
{
132+
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
133+
chip::AttributeId attributeId = attributeMetadata->attributeId;
134+
135+
switch (attributeId)
103136
{
104-
delete gRvcRunModeDelegate;
105-
gRvcRunModeDelegate = nullptr;
137+
case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: {
138+
*buffer = gRvcRunModeInstance->GetCurrentMode();
139+
ChipLogDetail(DeviceLayer, "Reading RunMode CurrentMode : %d", static_cast<int>(attributeId));
140+
}
141+
break;
142+
default:
143+
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
144+
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcRunMode", static_cast<int>(attributeId));
145+
break;
106146
}
147+
148+
return ret;
107149
}
108150

109151
void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId)
110152
{
111153
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
112-
VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr);
113-
gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate;
114-
gRvcRunModeInstance =
115-
new ModeBase::Instance(gRvcRunModeDelegate, 0x1, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff));
154+
VerifyOrDie(!gRvcRunModeDelegate && !gRvcRunModeInstance);
155+
156+
gRvcRunModeDelegate = std::make_unique<RvcRunModeDelegate>();
157+
gRvcRunModeInstance = std::make_unique<ModeBase::Instance>(gRvcRunModeDelegate.get(), endpointId, RvcRunMode::Id,
158+
chip::to_underlying(RvcRunMode::Feature::kNoFeatures));
116159
gRvcRunModeInstance->Init();
117160
}
118161

119-
#ifdef ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
162+
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
163+
164+
#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
120165
#include <chef-rvc-mode-delegate.h>
121166
using namespace chip::app::Clusters::RvcCleanMode;
122-
static RvcCleanModeDelegate * gRvcCleanModeDelegate = nullptr;
123-
static ModeBase::Instance * gRvcCleanModeInstance = nullptr;
167+
static std::unique_ptr<RvcCleanModeDelegate> gRvcCleanModeDelegate;
168+
static std::unique_ptr<ModeBase::Instance> gRvcCleanModeInstance;
124169

125170
CHIP_ERROR RvcCleanModeDelegate::Init()
126171
{
@@ -178,33 +223,75 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List<Mode
178223
return CHIP_NO_ERROR;
179224
}
180225

181-
ModeBase::Instance * RvcCleanMode::Instance()
226+
void RvcCleanMode::Shutdown()
182227
{
183-
return gRvcCleanModeInstance;
228+
gRvcCleanModeInstance.reset();
229+
gRvcCleanModeDelegate.reset();
184230
}
185231

186-
void RvcCleanMode::Shutdown()
232+
chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
233+
const EmberAfAttributeMetadata * attributeMetadata,
234+
uint8_t * buffer)
187235
{
188-
if (gRvcCleanModeInstance != nullptr)
236+
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1
237+
VerifyOrDie(gRvcCleanModeInstance != nullptr);
238+
chip::Protocols::InteractionModel::Status ret;
239+
chip::AttributeId attributeId = attributeMetadata->attributeId;
240+
241+
switch (attributeId)
189242
{
190-
delete gRvcCleanModeInstance;
191-
gRvcCleanModeInstance = nullptr;
243+
case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: {
244+
uint8_t m = static_cast<uint8_t>(buffer[0]);
245+
ret = gRvcCleanModeInstance->UpdateCurrentMode(m);
246+
if (chip::Protocols::InteractionModel::Status::Success != ret)
247+
{
248+
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(ret));
249+
}
250+
}
251+
break;
252+
default:
253+
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
254+
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
255+
break;
192256
}
193-
if (gRvcCleanModeDelegate != nullptr)
257+
258+
return ret;
259+
}
260+
261+
chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId,
262+
const EmberAfAttributeMetadata * attributeMetadata,
263+
uint8_t * buffer, uint16_t maxReadLength)
264+
{
265+
VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted);
266+
buffer[0] = gRvcCleanModeInstance->GetCurrentMode();
267+
268+
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
269+
chip::AttributeId attributeId = attributeMetadata->attributeId;
270+
271+
switch (attributeId)
194272
{
195-
delete gRvcCleanModeDelegate;
196-
gRvcCleanModeDelegate = nullptr;
273+
case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: {
274+
*buffer = gRvcCleanModeInstance->GetCurrentMode();
275+
ChipLogDetail(DeviceLayer, "Reading CleanMode CurrentMode : %d", static_cast<int>(attributeId));
197276
}
277+
break;
278+
default:
279+
ret = chip::Protocols::InteractionModel::Status::UnsupportedRead;
280+
ChipLogDetail(DeviceLayer, "Unsupported attributeId %d from reading RvcCleanMode", static_cast<int>(attributeId));
281+
break;
282+
}
283+
284+
return ret;
198285
}
199286

200287
void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId)
201288
{
202289
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
203-
VerifyOrDie(gRvcCleanModeDelegate == nullptr && gRvcCleanModeInstance == nullptr);
204-
gRvcCleanModeDelegate = new RvcCleanMode::RvcCleanModeDelegate;
205-
gRvcCleanModeInstance =
206-
new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff));
290+
VerifyOrDie(!gRvcCleanModeDelegate && !gRvcCleanModeInstance);
291+
292+
gRvcCleanModeDelegate = std::make_unique<RvcCleanModeDelegate>();
293+
gRvcCleanModeInstance = std::make_unique<ModeBase::Instance>(gRvcCleanModeDelegate.get(), endpointId, RvcCleanMode::Id,
294+
chip::to_underlying(RvcCleanMode::Feature::kNoFeatures));
207295
gRvcCleanModeInstance->Init();
208296
}
209-
#endif // ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER
210-
#endif // ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER
297+
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER

examples/chef/common/chef-rvc-mode-delegate.h

+20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <cstring>
2424
#include <utility>
2525

26+
using chip::Protocols::InteractionModel::Status;
27+
2628
namespace chip {
2729
namespace app {
2830
namespace Clusters {
@@ -118,3 +120,21 @@ void Shutdown();
118120
} // namespace Clusters
119121
} // namespace app
120122
} // namespace chip
123+
124+
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
125+
chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
126+
const EmberAfAttributeMetadata * attributeMetadata,
127+
uint8_t * buffer);
128+
chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
129+
const EmberAfAttributeMetadata * attributeMetadata,
130+
uint8_t * buffer, uint16_t maxReadLength);
131+
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
132+
133+
#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER
134+
chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
135+
const EmberAfAttributeMetadata * attributeMetadata,
136+
uint8_t * buffer);
137+
chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
138+
const EmberAfAttributeMetadata * attributeMetadata,
139+
uint8_t * buffer, uint16_t maxReadLength);
140+
#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER

0 commit comments

Comments
 (0)