@@ -132,7 +132,9 @@ static void rayneo_mcu_callback(uint32_t state, uint64_t timestamp, size_t lengt
132132 }
133133}
134134
135+ static pthread_mutex_t device_connection_mutex = PTHREAD_MUTEX_INITIALIZER ;
135136bool rayneo_device_connect () {
137+ pthread_mutex_lock (& device_connection_mutex );
136138 if (!soft_connected ) {
137139 if (!hard_connected ) {
138140 RegisterIMUEventCallback (rayneo_imu_callback );
@@ -145,20 +147,22 @@ bool rayneo_device_connect() {
145147 if (hard_connected ) {
146148 StartXR ();
147149 OpenIMU ();
150+
151+ soft_connected = true;
148152
149153 // this will trigger the STATE_EVENT_DEVICE_INFO event
150154 AcquireDeviceInfo ();
151-
152- soft_connected = true;
153155 } else {
154156 log_message ("RayNeo driver, failed to establish a connection\n" );
155157 }
156158 }
159+ pthread_mutex_unlock (& device_connection_mutex );
157160
158161 return soft_connected ;
159162};
160163
161164void rayneo_device_disconnect (bool soft , bool is_device_present ) {
165+ pthread_mutex_lock (& device_connection_mutex );
162166 if (soft_connected ) {
163167 CloseIMU ();
164168 StopXR ();
@@ -175,6 +179,7 @@ void rayneo_device_disconnect(bool soft, bool is_device_present) {
175179 free_and_clear (& device_model );
176180 hard_connected = false;
177181 }
182+ pthread_mutex_unlock (& device_connection_mutex );
178183};
179184
180185device_properties_type * rayneo_supported_device (uint16_t vendor_id , uint16_t product_id , uint8_t usb_bus , uint8_t usb_address ) {
@@ -215,7 +220,7 @@ void rayneo_block_on_device() {
215220 sleep (1 );
216221 }
217222
218- if ( soft_connected ) rayneo_device_disconnect (false , device != NULL );
223+ rayneo_device_disconnect (true , device != NULL );
219224 device_checkin (device );
220225};
221226
@@ -238,8 +243,8 @@ bool rayneo_is_connected() {
238243 return soft_connected ;
239244};
240245
241- void rayneo_disconnect (bool forced ) {
242- rayneo_device_disconnect (forced , device_present ());
246+ void rayneo_disconnect (bool soft ) {
247+ rayneo_device_disconnect (soft , device_present ());
243248};
244249
245250const device_driver_type rayneo_driver = {
0 commit comments