forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZclCallbacks.cpp
164 lines (155 loc) · 6.81 KB
/
ZclCallbacks.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <lib/support/logging/CHIPLogging.h>
#include "AppTask.h"
#include "LightingManager.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <app/util/af-types.h>
#include <assert.h>
#include <lib/support/logging/CHIPLogging.h>
using namespace ::chip;
using namespace chip::app::Clusters;
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
uint8_t * value)
{
EndpointId endpoint = attributePath.mEndpointId;
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;
if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
{
LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION, 0, size, value);
}
else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id)
{
if (size == 1)
{
ChipLogProgress(Zcl, "New level: %u", *value);
LightingMgr().InitiateAction(LightingManager::LEVEL_ACTION, 0, size, value);
}
else
{
ChipLogError(Zcl, "wrong length for level: %d", size);
}
}
else if (clusterId == ColorControl::Id)
{
/* ignore several attributes that are currently not processed */
if ((attributeId == ColorControl::Attributes::RemainingTime::Id) ||
(attributeId == ColorControl::Attributes::EnhancedColorMode::Id) ||
(attributeId == ColorControl::Attributes::ColorMode::Id))
{
return;
}
/* XY color space */
if (attributeId == ColorControl::Attributes::CurrentX::Id || attributeId == ColorControl::Attributes::CurrentY::Id)
{
if (size != sizeof(uint16_t))
{
ChipLogError(Zcl, "Wrong length for ColorControl value: %d", size);
return;
}
XyColor_t xy;
if (attributeId == ColorControl::Attributes::CurrentX::Id)
{
xy.x = *reinterpret_cast<uint16_t *>(value);
// get Y from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentY::Get(endpoint, &xy.y);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
if (attributeId == ColorControl::Attributes::CurrentY::Id)
{
xy.y = *reinterpret_cast<uint16_t *>(value);
// get X from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentX::Get(endpoint, &xy.x);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
ChipLogProgress(Zcl, "New XY color: %u|%u", xy.x, xy.y);
LightingMgr().InitiateAction(LightingManager::COLOR_ACTION_XY, 0, sizeof(xy), (uint8_t *) &xy);
}
/* HSV color space */
else if (attributeId == ColorControl::Attributes::CurrentHue::Id ||
attributeId == ColorControl::Attributes::CurrentSaturation::Id ||
attributeId == ColorControl::Attributes::EnhancedCurrentHue::Id)
{
if (size != sizeof(uint8_t))
{
ChipLogError(Zcl, "Wrong length for ColorControl value: %d", size);
return;
}
HsvColor_t hsv;
if (attributeId == ColorControl::Attributes::EnhancedCurrentHue::Id)
{
// We only support 8-bit hue. Assuming hue is linear, normalize 16-bit to 8-bit.
hsv.h = (uint8_t)((*reinterpret_cast<uint16_t *>(value)) >> 8);
// get saturation from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentSaturation::Get(endpoint, &hsv.s);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
else if (attributeId == ColorControl::Attributes::CurrentHue::Id)
{
hsv.h = *value;
// get saturation from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentSaturation::Get(endpoint, &hsv.s);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
else if (attributeId == ColorControl::Attributes::CurrentSaturation::Id)
{
hsv.s = *value;
// get hue from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentHue::Get(endpoint, &hsv.h);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
ChipLogProgress(Zcl, "New HSV color: %u|%u", hsv.h, hsv.s);
LightingMgr().InitiateAction(LightingManager::COLOR_ACTION_HSV, 0, sizeof(hsv), (uint8_t *) &hsv);
}
else if (attributeId == ColorControl::Attributes::ColorTemperatureMireds::Id)
{
CtColor_t ct;
ct.ctMireds = *reinterpret_cast<uint16_t *>(value);
ChipLogProgress(Zcl, "New CT color: %u", ct.ctMireds);
LightingMgr().InitiateAction(LightingManager::COLOR_ACTION_CT, 0, sizeof(ct), (uint8_t *) &ct.ctMireds);
}
else
{
ChipLogProgress(Zcl, "Unknown attribute ID: " ChipLogFormatMEI, ChipLogValueMEI(attributeId));
return;
}
}
}
/** @brief OnOff Cluster Init
*
* This function is called when a specific cluster is initialized. It gives the
* application an opportunity to take care of cluster initialization procedures.
* It is called exactly once for each endpoint where cluster is present.
*
* @param endpoint Ver.: always
*
* TODO Issue #3841
* emberAfOnOffClusterInitCallback happens before the stack initialize the cluster
* attributes to the default value.
* The logic here expects something similar to the deprecated Plugins callback
* emberAfPluginOnOffClusterServerPostInitCallback.
*
*/
void emberAfOnOffClusterInitCallback(EndpointId endpoint)
{
// No additional init currently - startup state handled by cluster.
}