@@ -54,7 +54,7 @@ using namespace chip::DeviceLayer;
54
54
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
55
55
#define OTA_START_TRIGGER_TIMEOUT 1500
56
56
57
- #define APP_TASK_STACK_SIZE (3 * 1024 )
57
+ #define APP_TASK_STACK_SIZE (2 * 1024 )
58
58
#define APP_TASK_PRIORITY 2
59
59
#define APP_EVENT_QUEUE_SIZE 10
60
60
#define QPG_LOCK_ENDPOINT_ID (1 )
@@ -135,6 +135,8 @@ CHIP_ERROR AppTask::Init()
135
135
{
136
136
CHIP_ERROR err = CHIP_NO_ERROR;
137
137
138
+ PlatformMgr ().AddEventHandler (MatterEventHandler, 0 );
139
+
138
140
ChipLogProgress (NotSpecified, " Current Software Version: %s" , CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
139
141
140
142
// Init ZCL Data Model and start server
@@ -165,70 +167,23 @@ CHIP_ERROR AppTask::Init()
165
167
ConfigurationMgr ().LogDeviceConfig ();
166
168
PrintOnboardingCodes (chip::RendezvousInformationFlags (chip::RendezvousInformationFlag::kBLE ));
167
169
170
+ UpdateLEDs ();
171
+
168
172
return err;
169
173
}
170
174
171
175
void AppTask::AppTaskMain (void * pvParameter)
172
176
{
173
177
AppEvent event;
174
178
175
- CHIP_ERROR err = sAppTask .Init ();
176
- if (err != CHIP_NO_ERROR)
177
- {
178
- ChipLogError (NotSpecified, " AppTask.Init() failed: %" CHIP_ERROR_FORMAT, err.Format ());
179
- }
180
-
181
- ChipLogProgress (NotSpecified, " App Task started" );
182
-
183
179
while (true )
184
180
{
185
- BaseType_t eventReceived = xQueueReceive (sAppEventQueue , &event, pdMS_TO_TICKS ( 10 ) );
181
+ BaseType_t eventReceived = xQueueReceive (sAppEventQueue , &event, portMAX_DELAY );
186
182
while (eventReceived == pdTRUE)
187
183
{
188
184
sAppTask .DispatchEvent (&event);
189
185
eventReceived = xQueueReceive (sAppEventQueue , &event, 0 );
190
186
}
191
-
192
- // Collect connectivity and configuration state from the CHIP stack. Because
193
- // the CHIP event loop is being run in a separate task, the stack must be
194
- // locked while these values are queried. However we use a non-blocking
195
- // lock request (TryLockCHIPStack()) to avoid blocking other UI activities
196
- // when the CHIP task is busy (e.g. with a long crypto operation).
197
- if (PlatformMgr ().TryLockChipStack ())
198
- {
199
- sIsThreadProvisioned = ConnectivityMgr ().IsThreadProvisioned ();
200
- sIsThreadEnabled = ConnectivityMgr ().IsThreadEnabled ();
201
- sHaveBLEConnections = (ConnectivityMgr ().NumBLEConnections () != 0 );
202
- PlatformMgr ().UnlockChipStack ();
203
- }
204
-
205
- // Update the status LED if factory reset has not been initiated.
206
- //
207
- // If system has "full connectivity", keep the LED On constantly.
208
- //
209
- // If thread and service provisioned, but not attached to the thread network
210
- // yet OR no connectivity to the service OR subscriptions are not fully
211
- // established THEN blink the LED Off for a short period of time.
212
- //
213
- // If the system has ble connection(s) uptill the stage above, THEN blink
214
- // the LEDs at an even rate of 100ms.
215
- //
216
- // Otherwise, blink the LED ON for a very short time.
217
- if (sAppTask .mFunction != kFunction_FactoryReset )
218
- {
219
- if (sIsThreadProvisioned && sIsThreadEnabled )
220
- {
221
- qvIO_LedBlink (SYSTEM_STATE_LED, 950 , 50 );
222
- }
223
- else if (sHaveBLEConnections )
224
- {
225
- qvIO_LedBlink (SYSTEM_STATE_LED, 100 , 100 );
226
- }
227
- else
228
- {
229
- qvIO_LedBlink (SYSTEM_STATE_LED, 50 , 950 );
230
- }
231
- }
232
187
}
233
188
}
234
189
@@ -556,3 +511,62 @@ void AppTask::UpdateClusterState(void)
556
511
ChipLogError (NotSpecified, " ERR: updating DoorLock %x" , status);
557
512
}
558
513
}
514
+
515
+ void AppTask::UpdateLEDs (void )
516
+ {
517
+ // If system has "full connectivity", keep the LED On constantly.
518
+ //
519
+ // If thread and service provisioned, but not attached to the thread network
520
+ // yet OR no connectivity to the service OR subscriptions are not fully
521
+ // established THEN blink the LED Off for a short period of time.
522
+ //
523
+ // If the system has ble connection(s) uptill the stage above, THEN blink
524
+ // the LEDs at an even rate of 100ms.
525
+ //
526
+ // Otherwise, blink the LED ON for a very short time.
527
+ if (sIsThreadProvisioned && sIsThreadEnabled )
528
+ {
529
+ qvIO_LedBlink (SYSTEM_STATE_LED, 950 , 50 );
530
+ }
531
+ else if (sHaveBLEConnections )
532
+ {
533
+ qvIO_LedBlink (SYSTEM_STATE_LED, 100 , 100 );
534
+ }
535
+ else
536
+ {
537
+ qvIO_LedBlink (SYSTEM_STATE_LED, 50 , 950 );
538
+ }
539
+ }
540
+
541
+ void AppTask::MatterEventHandler (const ChipDeviceEvent * event, intptr_t )
542
+ {
543
+ switch (event->Type )
544
+ {
545
+ case DeviceEventType::kServiceProvisioningChange : {
546
+ sIsThreadProvisioned = event->ServiceProvisioningChange .IsServiceProvisioned ;
547
+ UpdateLEDs ();
548
+ break ;
549
+ }
550
+
551
+ case DeviceEventType::kThreadConnectivityChange : {
552
+ sIsThreadEnabled = (event->ThreadConnectivityChange .Result == kConnectivity_Established );
553
+ UpdateLEDs ();
554
+ break ;
555
+ }
556
+
557
+ case DeviceEventType::kCHIPoBLEConnectionEstablished : {
558
+ sHaveBLEConnections = true ;
559
+ UpdateLEDs ();
560
+ break ;
561
+ }
562
+
563
+ case DeviceEventType::kCHIPoBLEConnectionClosed : {
564
+ sHaveBLEConnections = false ;
565
+ UpdateLEDs ();
566
+ break ;
567
+ }
568
+
569
+ default :
570
+ break ;
571
+ }
572
+ }
0 commit comments