From 115610aac2bb4a8676724caefcc4b51d5b6b1683 Mon Sep 17 00:00:00 2001 From: wheaney <42350981+wheaney@users.noreply.github.com> Date: Thu, 9 Nov 2023 22:20:25 -0800 Subject: [PATCH] XREAL Air 2 vendor/product IDs --- interface_lib/CMakeLists.txt | 1 + interface_lib/include/hid_ids.h | 15 +++++++++++++++ interface_lib/src/device3.c | 11 ++++++++--- interface_lib/src/device4.c | 13 +++++++++---- interface_lib/src/hid_ids.c | 26 ++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 interface_lib/include/hid_ids.h create mode 100644 interface_lib/src/hid_ids.c diff --git a/interface_lib/CMakeLists.txt b/interface_lib/CMakeLists.txt index 9692475..a57a905 100644 --- a/interface_lib/CMakeLists.txt +++ b/interface_lib/CMakeLists.txt @@ -13,6 +13,7 @@ add_library( src/crc32.c src/device3.c src/device4.c + src/hid_ids.c ) target_compile_options(nrealAirLibrary PRIVATE -fPIC) diff --git a/interface_lib/include/hid_ids.h b/interface_lib/include/hid_ids.h new file mode 100644 index 0000000..2730b5e --- /dev/null +++ b/interface_lib/include/hid_ids.h @@ -0,0 +1,15 @@ +#ifndef __cplusplus +#include +#endif + +#ifndef __cplusplus +#include +#else +#include +#endif + +#define NUM_SUPPORTED_PRODUCTS 2 + +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 diff --git a/interface_lib/src/device3.c b/interface_lib/src/device3.c index 6f6c709..834de03 100644 --- a/interface_lib/src/device3.c +++ b/interface_lib/src/device3.c @@ -34,6 +34,7 @@ #include #include "crc32.h" +#include "hid_ids.h" #ifndef NDEBUG #define device3_error(msg) fprintf(stderr, "ERROR: %s\n", msg) @@ -188,8 +189,8 @@ device3_error_type device3_open(device3_type* device, device3_event_callback cal } memset(device, 0, sizeof(device3_type)); - device->vendor_id = 0x3318; - device->product_id = 0x0424; + device->vendor_id = xreal_vendor_id; + device->product_id = 0; device->callback = callback; if (0 != hid_init()) { @@ -204,7 +205,11 @@ device3_error_type device3_open(device3_type* device, device3_event_callback cal struct hid_device_info* it = info; while (it) { - if (it->interface_number == 3) { + if (is_xreal_product_id(it->product_id) && it->interface_number == 3) { +#ifndef NDEBUG + printf("Found device with product_id: 0x%x\n", it->product_id); +#endif + device->product_id = it->product_id; device->handle = hid_open_path(it->path); break; } diff --git a/interface_lib/src/device4.c b/interface_lib/src/device4.c index aa57d56..efa6d6c 100644 --- a/interface_lib/src/device4.c +++ b/interface_lib/src/device4.c @@ -34,6 +34,7 @@ #include #include "crc32.h" +#include "hid_ids.h" #ifndef NDEBUG #define device4_error(msg) fprintf(stderr, "ERROR: %s\n", msg) @@ -172,8 +173,8 @@ device4_error_type device4_open(device4_type* device, device4_event_callback cal } memset(device, 0, sizeof(device4_type)); - device->vendor_id = 0x3318; - device->product_id = 0x0424; + device->vendor_id = xreal_vendor_id; + device->product_id = 0; device->callback = callback; if (0 != hid_init()) { @@ -182,13 +183,17 @@ device4_error_type device4_open(device4_type* device, device4_event_callback cal } struct hid_device_info* info = hid_enumerate( - device->vendor_id, + device->vendor_id, device->product_id ); struct hid_device_info* it = info; while (it) { - if (it->interface_number == 4) { + if (is_xreal_product_id(it->product_id) && it->interface_number == 4) { +#ifndef NDEBUG + printf("Found device with product_id: 0x%x\n", it->product_id); +#endif + device->product_id = it->product_id; device->handle = hid_open_path(it->path); break; } diff --git a/interface_lib/src/hid_ids.c b/interface_lib/src/hid_ids.c new file mode 100644 index 0000000..46e55ed --- /dev/null +++ b/interface_lib/src/hid_ids.c @@ -0,0 +1,26 @@ +#ifndef __cplusplus +#include +#endif + +#ifndef __cplusplus +#include +#else +#include +#endif + +#include "hid_ids.h" + +const uint16_t xreal_vendor_id = 0x3318; +const uint16_t xreal_product_ids[NUM_SUPPORTED_PRODUCTS] = { + 0x0424, // XREAL Air + 0x0428 // XREAL Air 2 +}; + +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) { + return true; + } + } + return false; +} \ No newline at end of file