From fde721b97f295768046200a04a74f8799fe7cbc5 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 | 3 ++- interface_lib/src/device_imu.c | 5 +++-- interface_lib/src/device_mcu.c | 5 +++-- interface_lib/src/hid_ids.c | 31 ++++++++++++++++++++++++++++--- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/interface_lib/include/hid_ids.h b/interface_lib/include/hid_ids.h index 82f9e4c..2b6dfbc 100644 --- a/interface_lib/include/hid_ids.h +++ b/interface_lib/include/hid_ids.h @@ -12,4 +12,5 @@ extern const uint16_t xreal_vendor_id; extern const uint16_t xreal_product_ids[NUM_SUPPORTED_PRODUCTS]; -bool is_xreal_product_id(uint16_t product_id); \ No newline at end of file +int xreal_imu_interface_id(uint16_t product_id); +int xreal_mcu_interface_id(uint16_t product_id); \ No newline at end of file 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 48fac2c..4958227 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 1766074..cff80af 100644 --- a/interface_lib/src/hid_ids.c +++ b/interface_lib/src/hid_ids.c @@ -18,11 +18,36 @@ const uint16_t xreal_product_ids[NUM_SUPPORTED_PRODUCTS] = { 0x0426 // XREAL Air 2 Ultra }; -bool is_xreal_product_id(uint16_t product_id) { +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 +}; + +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 true; + return xreal_imu_interface_ids[i]; } } - return false; + + 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; } \ No newline at end of file