XREAL Air 2 vendor/product IDs

This commit is contained in:
wheaney 2023-11-09 22:20:25 -08:00
parent b074ab72fc
commit 115610aac2
5 changed files with 59 additions and 7 deletions

View file

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

View file

@ -0,0 +1,15 @@
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifndef __cplusplus
#include <stdint.h>
#else
#include <cstdint>
#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);

View file

@ -34,6 +34,7 @@
#include <hidapi/hidapi.h>
#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;
}

View file

@ -34,6 +34,7 @@
#include <hidapi/hidapi.h>
#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()) {
@ -188,7 +189,11 @@ device4_error_type device4_open(device4_type* device, device4_event_callback cal
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;
}

View file

@ -0,0 +1,26 @@
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifndef __cplusplus
#include <stdint.h>
#else
#include <cstdint>
#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;
}