7
7
8
8
#include " GoogleMultiDeviceCommon.h"
9
9
10
- #include " GoogleMultiDeviceInfoProvider.h"
11
- #include " GoogleMultiDeviceAttestationProvider.h"
12
- #include " GenericSwitchStateMachine.h"
13
10
#include " DefaultGenericSwitchStateMachineDriver.h"
11
+ #include " GenericSwitchStateMachine.h"
12
+ #include " GoogleMultiDeviceAttestationProvider.h"
14
13
#include " GoogleMultiDeviceDishwasherOpstate.h"
14
+ #include " GoogleMultiDeviceInfoProvider.h"
15
15
16
- #include < app/server/Server.h>
17
16
#include < app-common/zap-generated/cluster-enums.h>
17
+ #include < app/server/Server.h>
18
18
#include < include/platform/ConnectivityManager.h>
19
19
#include < include/platform/DeviceInstanceInfoProvider.h>
20
- #include < lib/support/CodeUtils.h>
21
20
#include < lib/core/CHIPError.h>
22
21
#include < lib/core/DataModelTypes.h>
23
22
#include < lib/support/BitFlags.h>
23
+ #include < lib/support/CodeUtils.h>
24
24
25
25
#include < system/SystemClock.h>
26
26
#include < system/SystemLayer.h>
@@ -43,8 +43,8 @@ GoogleMultiDeviceAttestationProvider sAttestationProvider;
43
43
44
44
class OccupancyDelegate : public OccupancySensing ::Instance::Delegate
45
45
{
46
- public:
47
- // OccupancyDelegate() = delete;
46
+ public:
47
+ // OccupancyDelegate() = delete;
48
48
OccupancyDelegate (EndpointId endpointId) : mEndpoint (endpointId) {}
49
49
50
50
// Not copyable.
@@ -102,9 +102,11 @@ class OccupancyDelegate : public OccupancySensing::Instance::Delegate
102
102
bool StartHoldTimer (uint16_t numSeconds, std::function<void ()> callback) override
103
103
{
104
104
mHoldTimerCallback = callback;
105
- return CHIP_NO_ERROR == chip::DeviceLayer::SystemLayer ().StartTimer (chip::System::Clock::Timeout (numSeconds * 1000u ), &HoldTimerHandler, this );
105
+ return CHIP_NO_ERROR ==
106
+ chip::DeviceLayer::SystemLayer ().StartTimer (chip::System::Clock::Timeout (numSeconds * 1000u ), &HoldTimerHandler, this );
106
107
}
107
- private:
108
+
109
+ private:
108
110
static void HoldTimerHandler (System::Layer * layer, void * ctx)
109
111
{
110
112
if (ctx != nullptr )
@@ -149,8 +151,7 @@ void GoogleMultiDeviceIntegration::InitializeProduct()
149
151
{
150
152
mGenericSwitchDriverEp2 .SetEndpointId (2 );
151
153
BitFlags<Clusters::Switch::Feature> ep2Features;
152
- ep2Features
153
- .Set (Clusters::Switch::Feature::kActionSwitch )
154
+ ep2Features.Set (Clusters::Switch::Feature::kActionSwitch )
154
155
.Set (Clusters::Switch::Feature::kMomentarySwitch )
155
156
.Set (Clusters::Switch::Feature::kMomentarySwitchLongPress )
156
157
.Set (Clusters::Switch::Feature::kMomentarySwitchMultiPress );
@@ -166,8 +167,7 @@ void GoogleMultiDeviceIntegration::InitializeProduct()
166
167
{
167
168
mGenericSwitchDriverEp3 .SetEndpointId (3 );
168
169
BitFlags<Clusters::Switch::Feature> ep3Features;
169
- ep3Features
170
- .Set (Clusters::Switch::Feature::kMomentarySwitch )
170
+ ep3Features.Set (Clusters::Switch::Feature::kMomentarySwitch )
171
171
.Set (Clusters::Switch::Feature::kMomentarySwitchLongPress )
172
172
.Set (Clusters::Switch::Feature::kMomentarySwitchRelease )
173
173
.Set (Clusters::Switch::Feature::kMomentarySwitchMultiPress );
@@ -192,64 +192,105 @@ void GoogleMultiDeviceIntegration::InitializeProduct()
192
192
mGenericSwitchStateMachineEp4 .SetDriver (&mGenericSwitchDriverEp4 );
193
193
194
194
// Initialize initial state.
195
- mGenericSwitchDriverEp4 .SetButtonPosition (GetEp4LatchInitialPosition ());
195
+ mLatchPos = GetEp4LatchInitialPosition ();
196
+ mGenericSwitchDriverEp4 .SetButtonPosition (mLatchPos );
196
197
}
197
198
198
199
// EP5: Occupancy sensor setup
199
200
const EndpointId kOccupancyEndpointId = 5 ;
200
- mOccupancyDelegateEp5 = std::make_unique<OccupancyDelegate>(kOccupancyEndpointId );
201
+ mOccupancyDelegateEp5 = std::make_unique<OccupancyDelegate>(kOccupancyEndpointId );
201
202
mOccupancyInstanceEp5 = std::make_unique<OccupancySensing::Instance>(mOccupancyDelegateEp5 .get (), kOccupancyEndpointId );
202
203
VerifyOrDie (mOccupancyInstanceEp5 ->Init () == CHIP_NO_ERROR);
203
204
204
205
// EP6: Dishwasher setup
205
206
const EndpointId kDishwasherEndpointId = 6 ;
206
- mFakeDishwasherEp6 = MakeGoogleFakeDishwasher (kDishwasherEndpointId );
207
+ mFakeDishwasherEp6 = MakeGoogleFakeDishwasher (kDishwasherEndpointId );
207
208
mOpStateInstanceEp6 = std::make_unique<OperationalState::Instance>(mFakeDishwasherEp6 ->GetDelegate (), kDishwasherEndpointId );
208
209
209
210
mOpStateInstanceEp6 ->SetOperationalState (to_underlying (OperationalState::OperationalStateEnum::kStopped ));
210
211
mOpStateInstanceEp6 ->Init ();
211
212
212
213
if (chip::Server::GetInstance ().GetFabricTable ().FabricCount () == 0 )
213
214
{
214
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([](){
215
- chip::DeviceLayer::ConnectivityMgr ().SetBLEAdvertisingMode (chip::DeviceLayer::ConnectivityManager::BLEAdvertisingMode::kFastAdvertising );
215
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([]() {
216
+ chip::DeviceLayer::ConnectivityMgr ().SetBLEAdvertisingMode (
217
+ chip::DeviceLayer::ConnectivityManager::BLEAdvertisingMode::kFastAdvertising );
216
218
});
217
219
}
218
220
}
219
221
220
222
void GoogleMultiDeviceIntegration::HandleButtonPress (ButtonId buttonId)
221
223
{
222
- uint8_t latchPos = 0 ;
223
224
bool isLatch = false ;
224
225
225
226
switch (buttonId)
226
227
{
227
228
case ButtonId::kRed :
228
229
// Position 1 on EP2
229
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ](){
230
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
230
231
this ->mGenericSwitchStateMachineEp2 .HandleEvent (GenericSwitchStateMachine::Event::MakeButtonPressEvent (1 ));
231
232
});
232
233
break ;
233
234
case ButtonId::kYellow :
234
235
// Position 1 on EP3
235
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ](){
236
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
236
237
this ->mGenericSwitchStateMachineEp3 .HandleEvent (GenericSwitchStateMachine::Event::MakeButtonPressEvent (1 ));
237
238
});
238
239
break ;
239
- case ButtonId::kGreen :
240
- // TODO: Handle for opstate
241
- break ;
240
+ case ButtonId::kGreen : {
241
+ if (mLatchPos == 1 )
242
+ {
243
+ // Controlling start and stop
244
+ if (mOpStateInstanceEp6 ->GetCurrentOperationalState () ==
245
+ to_underlying (OperationalState::OperationalStateEnum::kRunning ))
246
+ {
247
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
248
+ OperationalState::GenericOperationalError err (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
249
+ mFakeDishwasherEp6 ->GetDelegate ()->HandleStopStateCallback (err);
250
+ });
251
+ }
252
+ else if (mOpStateInstanceEp6 ->GetCurrentOperationalState () ==
253
+ to_underlying (OperationalState::OperationalStateEnum::kStopped ))
254
+ {
255
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
256
+ OperationalState::GenericOperationalError err (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
257
+ mFakeDishwasherEp6 ->GetDelegate ()->HandleStartStateCallback (err);
258
+ });
259
+ }
260
+ }
261
+ else if (mLatchPos == 2 )
262
+ {
263
+ // Controlling pause and resume
264
+ if (mOpStateInstanceEp6 ->GetCurrentOperationalState () ==
265
+ to_underlying (OperationalState::OperationalStateEnum::kRunning ))
266
+ {
267
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
268
+ OperationalState::GenericOperationalError err (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
269
+ mFakeDishwasherEp6 ->GetDelegate ()->HandlePauseStateCallback (err);
270
+ });
271
+ }
272
+ else if (mOpStateInstanceEp6 ->GetCurrentOperationalState () ==
273
+ to_underlying (OperationalState::OperationalStateEnum::kPaused ))
274
+ {
275
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
276
+ OperationalState::GenericOperationalError err (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
277
+ mFakeDishwasherEp6 ->GetDelegate ()->HandleResumeStateCallback (err);
278
+ });
279
+ }
280
+ }
281
+ }
282
+ break ;
242
283
case ButtonId::kLatch1 :
243
- latchPos = 0 ;
244
- isLatch = true ;
284
+ mLatchPos = 0 ;
285
+ isLatch = true ;
245
286
break ;
246
287
case ButtonId::kLatch2 :
247
- latchPos = 1 ;
248
- isLatch = true ;
288
+ mLatchPos = 1 ;
289
+ isLatch = true ;
249
290
break ;
250
291
case ButtonId::kLatch3 :
251
- latchPos = 2 ;
252
- isLatch = true ;
292
+ mLatchPos = 2 ;
293
+ isLatch = true ;
253
294
break ;
254
295
default :
255
296
break ;
@@ -258,7 +299,8 @@ void GoogleMultiDeviceIntegration::HandleButtonPress(ButtonId buttonId)
258
299
if (isLatch)
259
300
{
260
301
// Latch positions on EP4
261
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this , latchPos](){
302
+ uint8_t latchPos = mLatchPos ;
303
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this , latchPos]() {
262
304
this ->mGenericSwitchStateMachineEp4 .HandleEvent (GenericSwitchStateMachine::Event::MakeLatchSwitchChangeEvent (latchPos));
263
305
});
264
306
}
@@ -270,13 +312,13 @@ void GoogleMultiDeviceIntegration::HandleButtonRelease(ButtonId buttonId)
270
312
{
271
313
case ButtonId::kRed :
272
314
// Position 1 on EP2
273
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ](){
315
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
274
316
this ->mGenericSwitchStateMachineEp2 .HandleEvent (GenericSwitchStateMachine::Event::MakeButtonReleaseEvent (1 ));
275
317
});
276
318
break ;
277
319
case ButtonId::kYellow :
278
320
// Position 1 on EP3
279
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ](){
321
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ]() {
280
322
this ->mGenericSwitchStateMachineEp3 .HandleEvent (GenericSwitchStateMachine::Event::MakeButtonReleaseEvent (1 ));
281
323
});
282
324
break ;
@@ -292,19 +334,17 @@ void GoogleMultiDeviceIntegration::HandleOccupancyDetected(uint8_t sensorId)
292
334
{
293
335
if (sensorId == 0 )
294
336
{
295
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ](){
296
- this ->mOccupancyInstanceEp5 ->SetOccupancyDetectedFromSensor (true );
297
- });
337
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda (
338
+ [this ]() { this ->mOccupancyInstanceEp5 ->SetOccupancyDetectedFromSensor (true ); });
298
339
}
299
340
}
300
341
301
342
void GoogleMultiDeviceIntegration::HandleOccupancyUndetected (uint8_t sensorId)
302
343
{
303
344
if (sensorId == 0 )
304
345
{
305
- chip::DeviceLayer::SystemLayer ().ScheduleLambda ([this ](){
306
- this ->mOccupancyInstanceEp5 ->SetOccupancyDetectedFromSensor (false );
307
- });
346
+ chip::DeviceLayer::SystemLayer ().ScheduleLambda (
347
+ [this ]() { this ->mOccupancyInstanceEp5 ->SetOccupancyDetectedFromSensor (false ); });
308
348
}
309
349
}
310
350
0 commit comments