Support differing HID interface IDs between products

This commit is contained in:
wheaney 2024-07-30 10:28:41 -07:00 committed by Jacki
parent 28eb02d94d
commit fc9eb2d898
No known key found for this signature in database
GPG key ID: B404184796354C5E
4 changed files with 44 additions and 5 deletions

View file

@ -40,10 +40,13 @@ extern "C" {
#endif #endif
extern const uint16_t xreal_vendor_id; extern const uint16_t xreal_vendor_id;
extern const uint16_t xreal_product_ids[NUM_SUPPORTED_PRODUCTS]; extern const uint16_t xreal_product_ids [NUM_SUPPORTED_PRODUCTS];
bool is_xreal_product_id(uint16_t product_id); bool is_xreal_product_id(uint16_t product_id);
int xreal_imu_interface_id(uint16_t product_id);
int xreal_mcu_interface_id(uint16_t product_id);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif

View file

@ -216,9 +216,10 @@ device_imu_error_type device_imu_open(device_imu_type* device, device_imu_event_
struct hid_device_info* it = info; struct hid_device_info* it = info;
while (it) { while (it) {
if (is_xreal_product_id(it->product_id) && it->interface_number == 3) { int interface_id = xreal_imu_interface_id(it->product_id);
if (interface_id != -1 && it->interface_number == interface_id) {
#ifndef NDEBUG #ifndef NDEBUG
printf("Found device with product_id: 0x%x\n", it->product_id); printf("Found IMU device with product_id 0x%x on interface %d\n", it->product_id, interface_id);
#endif #endif
device->product_id = it->product_id; device->product_id = it->product_id;
device->handle = hid_open_path(it->path); device->handle = hid_open_path(it->path);

View file

@ -195,9 +195,10 @@ device_mcu_error_type device_mcu_open(device_mcu_type* device, device_mcu_event_
struct hid_device_info* it = info; struct hid_device_info* it = info;
while (it) { while (it) {
if (is_xreal_product_id(it->product_id) && it->interface_number == 4) { int interface_id = xreal_mcu_interface_id(it->product_id);
if (interface_id != -1 && it->interface_number == interface_id) {
#ifndef NDEBUG #ifndef NDEBUG
printf("Found device with product_id: 0x%x\n", it->product_id); printf("Found MCU device with product_id 0x%x on interface %d\n", it->product_id, interface_id);
#endif #endif
device->product_id = it->product_id; device->product_id = it->product_id;
device->handle = hid_open_path(it->path); device->handle = hid_open_path(it->path);

View file

@ -42,6 +42,20 @@ const uint16_t xreal_product_ids[NUM_SUPPORTED_PRODUCTS] = {
0x0426 // XREAL Air 2 Ultra 0x0426 // XREAL Air 2 Ultra
}; };
const int xreal_imu_interface_ids[NUM_SUPPORTED_PRODUCTS] = {
3, // XREAL Air
3, // XREAL Air 2
3, // XREAL Air 2 Pro
2 // XREAL Air 2 Ultra
};
const int xreal_mcu_interface_ids[NUM_SUPPORTED_PRODUCTS] = {
4, // XREAL Air
4, // XREAL Air 2
4, // XREAL Air 2 Pro
-1 // TODO - XREAL Air 2 Ultra MCU support via interface 0
};
bool is_xreal_product_id(uint16_t product_id) { bool is_xreal_product_id(uint16_t product_id) {
for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) { for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) {
if (xreal_product_ids[i] == product_id) { if (xreal_product_ids[i] == product_id) {
@ -50,3 +64,23 @@ bool is_xreal_product_id(uint16_t product_id) {
} }
return false; return false;
} }
int xreal_imu_interface_id(uint16_t product_id) {
for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) {
if (xreal_product_ids[i] == product_id) {
return xreal_imu_interface_ids[i];
}
}
return -1;
}
int xreal_mcu_interface_id(uint16_t product_id) {
for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) {
if (xreal_product_ids[i] == product_id) {
return xreal_mcu_interface_ids[i];
}
}
return -1;
}