Skip to content

Commit fedcb23

Browse files
Ben BlumerBen Blumer
authored andcommitted
Consolidate opening the two interfaces
1 parent 2571032 commit fedcb23

File tree

1 file changed

+7
-49
lines changed

1 file changed

+7
-49
lines changed

AirAPI_Windows.cpp

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -213,49 +213,7 @@ process_accel(const int32_t in_accel[3], float out_vec[])
213213

214214
}
215215

216-
217-
static hid_device*
218-
open_device()
219-
{
220-
struct hid_device_info* devs = NULL;
221-
struct hid_device_info* devs_1 = hid_enumerate(AIR_VID, AIR_PID);
222-
struct hid_device_info* devs_2 = hid_enumerate(AIR_VID, AIR_2_PID);
223-
struct hid_device_info* devs_2_pro = hid_enumerate(AIR_VID, AIR_2_PRO_PID);
224-
225-
struct hid_device_info* cur_dev = NULL;
226-
227-
if (devs_1 != NULL) {
228-
cur_dev = devs_1;
229-
devs = devs_1;
230-
}
231-
else if (devs_2 != NULL) {
232-
cur_dev = devs_2;
233-
devs = devs_2;
234-
235-
}
236-
else if (devs_2_pro != NULL) {
237-
cur_dev = devs_2_pro;
238-
devs = devs_2_pro;
239-
}
240-
241-
hid_device* device = NULL;
242-
243-
while (devs) {
244-
if (cur_dev->interface_number == 3) {
245-
device = hid_open_path(cur_dev->path);
246-
std::cout << "Interface 3 bound" << std::endl;
247-
break;
248-
}
249-
250-
cur_dev = cur_dev->next;
251-
}
252-
253-
hid_free_enumeration(devs);
254-
return device;
255-
}
256-
257-
static hid_device*
258-
open_device4()
216+
static hid_device* open_device_by_interface(int interface_number)
259217
{
260218
struct hid_device_info* devs = NULL;
261219
struct hid_device_info* devs_1 = hid_enumerate(AIR_VID, AIR_PID);
@@ -271,18 +229,18 @@ open_device4()
271229
else if (devs_2 != NULL) {
272230
cur_dev = devs_2;
273231
devs = devs_2;
274-
275232
}
276233
else if (devs_2_pro != NULL) {
277234
cur_dev = devs_2_pro;
278235
devs = devs_2_pro;
279236
}
237+
280238
hid_device* device = NULL;
281239

282240
while (devs) {
283-
if (cur_dev->interface_number == 4) {
241+
if (cur_dev->interface_number == interface_number) {
284242
device = hid_open_path(cur_dev->path);
285-
std::cout << "Interface 4 bound" << std::endl;
243+
std::cout << "Interface " << interface_number << " bound" << std::endl;
286244
break;
287245
}
288246

@@ -449,9 +407,9 @@ int StartConnection()
449407
}
450408
else {
451409
std::cout << "Opening Device" << std::endl;
452-
// open device
453-
device = open_device();
454-
device4 = open_device4();
410+
// open devices
411+
device = open_device_by_interface(3); // for interface 3
412+
device4 = open_device_by_interface(4); // for interface 4
455413
if (!device || !device4) {
456414
std::cout << "Unable to open device" << std::endl;
457415
return 1;

0 commit comments

Comments
 (0)