Support differing HID interface IDs between products

This commit is contained in:
wheaney 2024-07-30 10:28:41 -07:00
parent a2c8e49856
commit fde721b97f
4 changed files with 36 additions and 8 deletions

View file

@ -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);
int xreal_imu_interface_id(uint16_t product_id);
int xreal_mcu_interface_id(uint16_t product_id);

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;
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);

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;
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);

View file

@ -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;
}