-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
static-supported-modes-manager.cpp
72 lines (64 loc) · 2.92 KB
/
static-supported-modes-manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <static-supported-modes-manager.h>
using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;
using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using storage_value_type = const ModeOptionStructType;
namespace {
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag)
{
Structs::ModeOptionStruct::Type option;
option.label = CharSpan(label, strlen(label));
option.mode = mode;
option.semanticTag = semanticTag;
return option;
}
} // namespace
// TODO: Configure your options for each endpoint
storage_value_type StaticSupportedModesManager::coffeeOptions[] = { buildModeOptionStruct("Black", 0, 0),
buildModeOptionStruct("Cappuccino", 4, 0),
buildModeOptionStruct("Espresso", 7, 0) };
const StaticSupportedModesManager::EndpointSpanPair
StaticSupportedModesManager::supportedOptionsByEndpoints[EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = {
EndpointSpanPair(1, Span<storage_value_type>(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1
};
const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager();
const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const
{
for (size_t i = 0; i < EMBER_AF_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT; ++i)
{
const EndpointSpanPair & endpointSpanPair = supportedOptionsByEndpoints[i];
if (endpointSpanPair.mEndpointId == endpointId)
{
return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end());
}
}
return ModeOptionsProvider(nullptr, nullptr);
}
EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
const ModeOptionStructType ** dataPtr) const
{
auto modeOptionsProvider = this->getModeOptionsProvider(endpointId);
if (modeOptionsProvider.begin() == nullptr)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
}
auto * begin = this->getModeOptionsProvider(endpointId).begin();
auto * end = this->getModeOptionsProvider(endpointId).end();
for (auto * it = begin; it != end; ++it)
{
auto & modeOption = *it;
if (modeOption.mode == mode)
{
*dataPtr = &modeOption;
return EMBER_ZCL_STATUS_SUCCESS;
}
}
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Cannot find the mode %" PRIu8, mode);
return EMBER_ZCL_STATUS_INVALID_ARGUMENT;
}
const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager()
{
return &StaticSupportedModesManager::instance;
}