Skip to content

Commit 2d2e36d

Browse files
committed
Address device connection issues with RayNeo and VITURE, v2.0.10
1 parent caca100 commit 2d2e36d

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.16)
2-
project(xrDriver VERSION 2.0.9 LANGUAGES C)
2+
project(xrDriver VERSION 2.0.10 LANGUAGES C)
33

44
configure_file(include/version.h.in version.h)
55
include_directories(${PROJECT_BINARY_DIR})

docker-build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# docker run --rm -t -v ./:/source -v --platform linux/amd64 "xr-driver:amd64"
44
# docker run --rm -t -v ./:/source -v --platform linux/arm64 "xr-driver:arm64"
55

6-
FROM --platform=$TARGETPLATFORM debian:latest
6+
FROM --platform=$TARGETPLATFORM debian:stable-20250428-slim
77

88
ARG TARGETPLATFORM
99
RUN echo "Target platform: $TARGETPLATFORM"

src/devices/rayneo.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
135136
bool 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

161164
void 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

180185
device_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

245250
const device_driver_type rayneo_driver = {

src/devices/viture.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,20 @@ device_properties_type* viture_supported_device(uint16_t vendor_id, uint16_t pro
152152
return NULL;
153153
};
154154

155+
static pthread_mutex_t viture_connection_mutex = PTHREAD_MUTEX_INITIALIZER;
155156
static void disconnect(bool soft) {
157+
pthread_mutex_lock(&viture_connection_mutex);
156158
if (connected) {
157159
set_imu(false);
158-
159-
// VITURE SDK freezes if we attempt deinit() while it's still physically connected, so only do this if the device is no longer present
160-
if (!soft || !device_present()) {
161-
deinit();
162-
initialized = false;
163-
}
164160
connected = false;
165161
}
162+
163+
// VITURE SDK freezes if we attempt deinit() while it's still physically connected, so only do this if the device is no longer present
164+
if (initialized && (!soft || !device_present())) {
165+
deinit();
166+
initialized = false;
167+
}
168+
pthread_mutex_unlock(&viture_connection_mutex);
166169
}
167170

168171
bool viture_device_connect() {
@@ -216,7 +219,7 @@ void viture_block_on_device() {
216219
imu_state = get_imu_state();
217220
}
218221
}
219-
disconnect(false);
222+
disconnect(true);
220223
device_checkin(device);
221224
};
222225

src/driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ void update_config_from_file(FILE *fp) {
311311

312312
update_config(config(), new_config);
313313

314-
if (driver_newly_disabled && is_driver_connected()) {
315-
if (new_config->debug_device) log_debug("update_config_from_file, device_driver->disconnect_func(true)\n");
314+
if (config()->disabled && is_driver_connected()) {
315+
if (config()->debug_device) log_debug("update_config_from_file, device_driver->disconnect_func(true)\n");
316316
device_driver->disconnect_func(true);
317317
}
318318

src/plugins/smooth_follow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void smooth_follow_set_config_func(void* config) {
211211

212212
if (temp_config->sideview_enabled &&
213213
sf_config->sideview_follow_enabled != temp_config->sideview_follow_enabled ||
214-
sf_config->sideview_enabled != temp_config->sideview_enabled)
214+
sf_config->sideview_enabled != temp_config->sideview_enabled && temp_config->sideview_follow_enabled)
215215
log_message("Sideview follow has been %s\n", temp_config->sideview_follow_enabled ? "enabled" : "disabled");
216216

217217
if (temp_config->sideview_follow_threshold != sf_config->sideview_follow_threshold)

0 commit comments

Comments
 (0)