From fc9eb2d8986d70a3c906a421d4d93ac422174242 Mon Sep 17 00:00:00 2001 From: wheaney <42350981+wheaney@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:28:41 -0700 Subject: [PATCH] Support differing HID interface IDs between products --- interface_lib/include/hid_ids.h | 5 ++++- interface_lib/src/device_imu.c | 5 +++-- interface_lib/src/device_mcu.c | 5 +++-- interface_lib/src/hid_ids.c | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/interface_lib/include/hid_ids.h b/interface_lib/include/hid_ids.h index cea7cd6..c1c8fbd 100644 --- a/interface_lib/include/hid_ids.h +++ b/interface_lib/include/hid_ids.h @@ -40,10 +40,13 @@ extern "C" { #endif 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); +int xreal_imu_interface_id(uint16_t product_id); +int xreal_mcu_interface_id(uint16_t product_id); + #ifdef __cplusplus } // extern "C" #endif diff --git a/interface_lib/src/device_imu.c b/interface_lib/src/device_imu.c index 613b17f..e788078 100644 --- a/interface_lib/src/device_imu.c +++ b/interface_lib/src/device_imu.c @@ -216,9 +216,10 @@ device_imu_error_type device_imu_open(device_imu_type* device, device_imu_event_ struct hid_device_info* it = info; 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 - 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 device->product_id = it->product_id; device->handle = hid_open_path(it->path); diff --git a/interface_lib/src/device_mcu.c b/interface_lib/src/device_mcu.c index 7184da3..9e76f0a 100644 --- a/interface_lib/src/device_mcu.c +++ b/interface_lib/src/device_mcu.c @@ -195,9 +195,10 @@ device_mcu_error_type device_mcu_open(device_mcu_type* device, device_mcu_event_ struct hid_device_info* it = info; 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 - 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 device->product_id = it->product_id; device->handle = hid_open_path(it->path); diff --git a/interface_lib/src/hid_ids.c b/interface_lib/src/hid_ids.c index 958d4f3..c7d992e 100644 --- a/interface_lib/src/hid_ids.c +++ b/interface_lib/src/hid_ids.c @@ -42,6 +42,20 @@ const uint16_t xreal_product_ids[NUM_SUPPORTED_PRODUCTS] = { 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) { for (int i = 0; i < NUM_SUPPORTED_PRODUCTS; i++) { if (xreal_product_ids[i] == product_id) { @@ -50,3 +64,23 @@ bool is_xreal_product_id(uint16_t product_id) { } 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; +}