Skip to content

Commit 9643f5a

Browse files
authored
Merge pull request #14 from kawaharas/dev-air2-ultra
added Air 2 Ultra support
2 parents 0d617c5 + 53c3c15 commit 9643f5a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

AirAPI_Windows.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define AIR_PID 0x0424
1313
#define AIR_2_PID 0x0428
1414
#define AIR_2_PRO_PID 0x0432
15+
#define AIR_2_ULTRA_PID 0x0426
1516

1617
//Is Tracking
1718
bool g_isTracking = false;
@@ -213,29 +214,34 @@ process_accel(const int32_t in_accel[3], float out_vec[])
213214

214215
}
215216

216-
static hid_device* open_device_by_interface(int interface_number)
217+
static hid_device_info* open_device()
217218
{
218219
struct hid_device_info* devs = NULL;
219220
struct hid_device_info* devs_1 = hid_enumerate(AIR_VID, AIR_PID);
220221
struct hid_device_info* devs_2 = hid_enumerate(AIR_VID, AIR_2_PID);
221222
struct hid_device_info* devs_2_pro = hid_enumerate(AIR_VID, AIR_2_PRO_PID);
222-
223-
struct hid_device_info* cur_dev = NULL;
223+
struct hid_device_info* devs_2_ultra = hid_enumerate(AIR_VID, AIR_2_ULTRA_PID);
224224

225225
if (devs_1 != NULL) {
226-
cur_dev = devs_1;
227226
devs = devs_1;
228227
}
229228
else if (devs_2 != NULL) {
230-
cur_dev = devs_2;
231229
devs = devs_2;
232230
}
233231
else if (devs_2_pro != NULL) {
234-
cur_dev = devs_2_pro;
235232
devs = devs_2_pro;
236233
}
234+
else if (devs_2_ultra != NULL) {
235+
devs = devs_2_ultra;
236+
}
237+
238+
return devs;
239+
}
237240

241+
static hid_device* open_device_by_interface(struct hid_device_info* devs, int interface_number)
242+
{
238243
hid_device* device = NULL;
244+
struct hid_device_info* cur_dev = devs;
239245

240246
while (devs) {
241247
if (cur_dev->interface_number == interface_number) {
@@ -247,7 +253,6 @@ static hid_device* open_device_by_interface(int interface_number)
247253
cur_dev = cur_dev->next;
248254
}
249255

250-
hid_free_enumeration(devs);
251256
return device;
252257
}
253258

@@ -408,8 +413,17 @@ int StartConnection()
408413
else {
409414
std::cout << "Opening Device" << std::endl;
410415
// open devices
411-
device = open_device_by_interface(3); // for interface 3
412-
device4 = open_device_by_interface(4); // for interface 4
416+
struct hid_device_info* devs = open_device();
417+
if (devs->product_id == AIR_2_ULTRA_PID) {
418+
device = open_device_by_interface(devs, 2); // for interface 3
419+
device4 = open_device_by_interface(devs, 8); // for interface 4
420+
}
421+
else {
422+
// for Air, Air2, and Air2 Pro
423+
device = open_device_by_interface(devs, 3); // for interface 3
424+
device4 = open_device_by_interface(devs, 4); // for interface 4
425+
}
426+
hid_free_enumeration(devs);
413427
if (!device || !device4) {
414428
std::cout << "Unable to open device" << std::endl;
415429
return 1;

0 commit comments

Comments
 (0)