Skip to content

Commit ccf4d20

Browse files
authored
[Chef] Initialise identify cluster instance at app init (#40213)
* identify * gemini suggestion
1 parent 7d6b84e commit ccf4d20

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/chef/common/stubs.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <app/data-model/Nullable.h>
55
#include <app/util/attribute-storage.h>
66
#include <app/util/config.h>
7+
#include <app/util/endpoint-config-api.h>
78
#include <lib/core/DataModelTypes.h>
89

910
using chip::app::DataModel::Nullable;
@@ -46,6 +47,40 @@ using namespace chip::app::Clusters;
4647
#endif // MATTER_DM_PLUGIN_ON_OFF_SERVER
4748
#endif // MATTER_DM_PLUGIN_PUMP_CONFIGURATION_AND_CONTROL_SERVER
4849

50+
#if MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT > 0
51+
#include <app/clusters/identify-server/identify-server.h>
52+
53+
namespace {
54+
// TODO: Move this to a standalone cluster cpp file.
55+
56+
constexpr size_t kIdentifyTableSize = MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT;
57+
static_assert(kIdentifyTableSize <= kEmberInvalidEndpointIndex, "Identify table size error");
58+
std::unique_ptr<struct Identify> gIdentifyInstanceTable[kIdentifyTableSize];
59+
60+
void InitIdentifyCluster()
61+
{
62+
const uint16_t endpointCount = emberAfEndpointCount();
63+
64+
for (uint16_t endpointIndex = 0; endpointIndex < endpointCount; endpointIndex++)
65+
{
66+
chip::EndpointId endpointId = emberAfEndpointFromIndex(endpointIndex);
67+
if (endpointId == kInvalidEndpointId)
68+
{
69+
continue;
70+
}
71+
72+
// Check if endpoint has Identify cluster enabled
73+
uint16_t epIndex = emberAfGetClusterServerEndpointIndex(endpointId, chip::app::Clusters::Identify::Id,
74+
MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT);
75+
if (epIndex >= kIdentifyTableSize)
76+
continue;
77+
78+
gIdentifyInstanceTable[epIndex] =
79+
std::make_unique<struct Identify>(endpointId, nullptr, nullptr, chip::app::Clusters::Identify::IdentifyTypeEnum::kNone);
80+
}
81+
}
82+
} // namespace
83+
#endif // MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT
4984
namespace {
5085

5186
// Please refer to https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/namespaces
@@ -541,6 +576,10 @@ void ApplicationInit()
541576
ChipLogProgress(NotSpecified, "Initializing MicrowaveOvenControl cluster.");
542577
InitChefMicrowaveOvenControlCluster();
543578
#endif // MATTER_DM_PLUGIN_MICROWAVE_OVEN_CONTROL_SERVER
579+
580+
#if MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT > 0
581+
InitIdentifyCluster();
582+
#endif // MATTER_DM_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT
544583
}
545584

546585
void ApplicationShutdown()

0 commit comments

Comments
 (0)