22
22
#include < app/util/att-storage.h>
23
23
#include < platform/PlatformManager.h>
24
24
25
+ #include " SwitchEventHandler.h"
26
+
25
27
using namespace chip ;
26
28
using namespace chip ::app;
27
29
using namespace chip ::app::Clusters;
28
30
using namespace chip ::app::Clusters::Switch;
29
31
using namespace chip ::DeviceLayer;
30
32
31
- class SwitchEventHandler
32
- {
33
- public:
34
- SwitchEventHandler (EndpointId endpoint):mEndpointId (endpoint){};
35
-
36
- /* *
37
- * Should be called when the latching switch is moved to a new position.
38
- */
39
- void OnSwitchLatchedHandler (uint8_t newPosition);
40
-
41
- /* *
42
- * Should be called when the momentary switch starts to be pressed.
43
- */
44
- void OnSwitchInitialPressedHandler (uint8_t newPosition);
45
-
46
- /* *
47
- * Should be called when the momentary switch has been pressed for a "long" time.
48
- */
49
- void OnSwitchLongPressedHandler (uint8_t newPosition);
50
-
51
- /* *
52
- * Should be called when the momentary switch has been released.
53
- */
54
- void OnSwitchShortReleasedHandler (uint8_t previousPosition);
55
-
56
- /* *
57
- * Should be called when the momentary switch has been released after having been pressed for a long time.
58
- */
59
- void OnSwitchLongReleasedHandler (uint8_t previousPosition);
60
-
61
- /* *
62
- * Should be called to indicate how many times the momentary switch has been pressed in a multi-press
63
- * sequence, during that sequence.
64
- */
65
- void OnSwitchMultiPressOngoingHandler (uint8_t newPosition, uint8_t count);
66
-
67
- /* *
68
- * Should be called to indicate how many times the momentary switch has been pressed in a multi-press
69
- * sequence, after it has been detected that the sequence has ended.
70
- */
71
- void OnSwitchMultiPressCompleteHandler (uint8_t previousPosition, uint8_t count);
72
-
73
- private:
74
- EndpointId mEndpointId ;
75
- };
76
-
77
-
78
- void SwitchEventHandler::OnSwitchLatchedHandler (uint8_t newPosition)
33
+
34
+ void SwitchEventHandler::OnSwitchLatched (uint8_t newPosition)
79
35
{
80
36
ChipLogDetail (NotSpecified, " The latching switch is moved to a new position:%d" , newPosition);
81
37
82
38
Clusters::SwitchServer::Instance ().OnSwitchLatch (mEndpointId , newPosition);
83
39
}
84
40
85
- void SwitchEventHandler::OnSwitchInitialPressedHandler (uint8_t newPosition)
41
+ void SwitchEventHandler::OnSwitchInitialPressed (uint8_t newPosition)
86
42
{
87
43
ChipLogDetail (NotSpecified, " The new position when the momentary switch starts to be pressed:%d" , newPosition);
88
44
89
45
Clusters::SwitchServer::Instance ().OnInitialPress (mEndpointId , newPosition);
90
46
}
91
47
92
- void SwitchEventHandler::OnSwitchLongPressedHandler (uint8_t newPosition)
48
+ void SwitchEventHandler::OnSwitchLongPressed (uint8_t newPosition)
93
49
{
94
50
ChipLogDetail (NotSpecified, " The new position when the momentary switch has been pressed for a long time:%d" , newPosition);
95
51
96
52
Clusters::SwitchServer::Instance ().OnLongPress (mEndpointId , newPosition);
97
53
}
98
54
99
- void SwitchEventHandler::OnSwitchShortReleasedHandler (uint8_t previousPosition)
55
+ void SwitchEventHandler::OnSwitchShortReleased (uint8_t previousPosition)
100
56
{
101
57
ChipLogDetail (NotSpecified, " The the previous value of the CurrentPosition when the momentary switch has been released:%d" ,
102
58
previousPosition);
103
59
104
60
Clusters::SwitchServer::Instance ().OnShortRelease (mEndpointId , previousPosition);
105
61
}
106
62
107
- void SwitchEventHandler::OnSwitchLongReleasedHandler (uint8_t previousPosition)
63
+ void SwitchEventHandler::OnSwitchLongReleased (uint8_t previousPosition)
108
64
{
109
65
ChipLogDetail (NotSpecified,
110
66
" The the previous value of the CurrentPosition when the momentary switch has been released after having been "
@@ -114,7 +70,7 @@ void SwitchEventHandler::OnSwitchLongReleasedHandler(uint8_t previousPosition)
114
70
Clusters::SwitchServer::Instance ().OnLongRelease (mEndpointId , previousPosition);
115
71
}
116
72
117
- void SwitchEventHandler::OnSwitchMultiPressOngoingHandler (uint8_t newPosition, uint8_t count)
73
+ void SwitchEventHandler::OnSwitchMultiPressOngoing (uint8_t newPosition, uint8_t count)
118
74
{
119
75
ChipLogDetail (NotSpecified, " The new position when the momentary switch has been pressed in a multi-press sequence:%d" ,
120
76
newPosition);
@@ -123,7 +79,7 @@ void SwitchEventHandler::OnSwitchMultiPressOngoingHandler(uint8_t newPosition, u
123
79
Clusters::SwitchServer::Instance ().OnMultiPressOngoing (mEndpointId , newPosition, count);
124
80
}
125
81
126
- void SwitchEventHandler::OnSwitchMultiPressCompleteHandler (uint8_t previousPosition, uint8_t count)
82
+ void SwitchEventHandler::OnSwitchMultiPressComplete (uint8_t previousPosition, uint8_t count)
127
83
{
128
84
ChipLogDetail (NotSpecified, " The previous position when the momentary switch has been pressed in a multi-press sequence:%d" ,
129
85
previousPosition);
@@ -132,22 +88,4 @@ void SwitchEventHandler::OnSwitchMultiPressCompleteHandler(uint8_t previousPosit
132
88
Clusters::SwitchServer::Instance ().OnMultiPressComplete (mEndpointId , previousPosition, count);
133
89
}
134
90
135
- static std::map<int , SwitchEventHandler *> gSwitchEventHandlers {};
136
-
137
- SwitchEventHandler * GetSwitchEventHandler (EndpointId endpointId)
138
- {
139
- if (gSwitchEventHandlers .find (endpointId) == gSwitchEventHandlers .end ()) {
140
- return nullptr ;
141
- }
142
-
143
- return gSwitchEventHandlers [endpointId];
144
- }
145
-
146
- void emberAfSwitchClusterInitCallback (EndpointId endpoint)
147
- {
148
- ChipLogProgress (Zcl, " Chef: emberAfSwitchClusterInitCallback" );
149
- gSwitchEventHandlers [endpoint] = new SwitchEventHandler (endpoint);
150
- printf (" \033 [44m %s, %d, Switch::ID=%u \033 [0m \n " , __func__, __LINE__, Switch::Id);
151
- }
152
-
153
91
0 commit comments