26
26
#include < app/ConcreteAttributePath.h>
27
27
#include < app/EventLogging.h>
28
28
#include < app/reporting/reporting.h>
29
+ #include < app/server/Server.h>
29
30
#include < app/util/af-types.h>
30
31
#include < app/util/attribute-storage.h>
31
32
#include < app/util/endpoint-config-api.h>
39
40
#include < setup_payload/QRCodeSetupPayloadGenerator.h>
40
41
#include < setup_payload/SetupPayload.h>
41
42
42
- #include < pthread.h>
43
- #include < sys/ioctl.h>
44
-
45
43
#include " CommissionableInit.h"
46
44
#include " Device.h"
47
- #include < app/server/Server.h>
48
45
49
46
#include < cassert>
50
47
#include < iostream>
51
48
#include < string>
49
+ #include < sys/ioctl.h>
50
+ #include < thread>
52
51
53
52
using namespace chip ;
54
53
using namespace chip ::app;
@@ -58,12 +57,41 @@ using namespace chip::Transport;
58
57
using namespace chip ::DeviceLayer;
59
58
using namespace chip ::app::Clusters;
60
59
60
+ #define POLL_INTERVAL_MS (100 )
61
+
61
62
namespace {
62
63
63
64
EndpointId gCurrentEndpointId ;
64
65
EndpointId gFirstDynamicEndpointId ;
65
66
Device * gDevices [CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1 ];
66
67
68
+ bool KeyboardHit ()
69
+ {
70
+ int bytesWaiting;
71
+ ioctl (0 , FIONREAD, &bytesWaiting);
72
+ return bytesWaiting > 0 ;
73
+ }
74
+
75
+ void BridgePollingThread ()
76
+ {
77
+ while (true )
78
+ {
79
+ if (KeyboardHit ())
80
+ {
81
+ int ch = getchar ();
82
+ if (ch == ' e' )
83
+ {
84
+ ChipLogProgress (DeviceLayer, " Exiting....." );
85
+ exit (0 );
86
+ }
87
+ continue ;
88
+ }
89
+
90
+ // Sleep to avoid tight loop reading commands
91
+ usleep (POLL_INTERVAL_MS * 1000 );
92
+ }
93
+ }
94
+
67
95
} // namespace
68
96
69
97
// REVISION DEFINITIONS:
@@ -245,42 +273,6 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
245
273
return ret;
246
274
}
247
275
248
- #define POLL_INTERVAL_MS (100 )
249
- uint8_t poll_prescale = 0 ;
250
-
251
- bool kbhit ()
252
- {
253
- int byteswaiting;
254
- ioctl (0 , FIONREAD, &byteswaiting);
255
- return byteswaiting > 0 ;
256
- }
257
-
258
- const int16_t oneDegree = 100 ;
259
-
260
- void * bridge_polling_thread (void * context)
261
- {
262
- while (true )
263
- {
264
- if (kbhit ())
265
- {
266
- int ch = getchar ();
267
-
268
- // Commands used for the actions bridge test plan.
269
- if (ch == ' e' )
270
- {
271
- ChipLogProgress (DeviceLayer, " Exiting....." );
272
- exit (0 );
273
- }
274
- continue ;
275
- }
276
-
277
- // Sleep to avoid tight loop reading commands
278
- usleep (POLL_INTERVAL_MS * 1000 );
279
- }
280
-
281
- return nullptr ;
282
- }
283
-
284
276
void ApplicationInit ()
285
277
{
286
278
// Clear out the device database
@@ -292,15 +284,9 @@ void ApplicationInit()
292
284
static_cast <int >(emberAfEndpointFromIndex (static_cast <uint16_t >(emberAfFixedEndpointCount () - 1 ))) + 1 );
293
285
gCurrentEndpointId = gFirstDynamicEndpointId ;
294
286
295
- {
296
- pthread_t poll_thread;
297
- int res = pthread_create (&poll_thread, nullptr , bridge_polling_thread, nullptr );
298
- if (res)
299
- {
300
- printf (" Error creating polling thread: %d\n " , res);
301
- exit (1 );
302
- }
303
- }
287
+ // Start a thread for bridge polling
288
+ std::thread pollingThread (BridgePollingThread);
289
+ pollingThread.detach ();
304
290
}
305
291
306
292
void ApplicationShutdown () {}
0 commit comments