f77: Add jackhill's layout
[jackhill/qmk/firmware.git] / keyboards / xwhatsit / util / util / communication.cpp
CommitLineData
95520199
PA
1/* Copyright 2020 Purdea Andrei
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
1c506c79
PA
17#include "communication.h"
18#include <stdio.h>
19#include <stdlib.h>
20#include <iostream>
21#include "../../util_comm.h"
22#include <wchar.h>
23
24Communication::Communication()
25{
26 if (hid_init() != 0)
27 {
28 std::cerr << "Error: Unable to run hid_init()" << std::endl;
29 exit(-1);
30 };
31}
32
33Communication::~Communication()
34{
35 hid_exit();
36}
37
38std::vector<std::string> Communication::scan()
39{
40 QMutexLocker locker(&mutex);
41 std::vector<std::string> ret;
42 //printf("Scanning\n");
43 hid_device_info *enu = hid_enumerate(0x0481, 0x0002);
44 hid_device_info *devinfo = enu;
45 while (devinfo != NULL)
46 {
47 if ((NULL != devinfo->manufacturer_string) &&
48 (NULL != devinfo->product_string) &&
49 (0==wcscmp(devinfo->manufacturer_string, L"Tom Wong-Cornall")) &&
50 (0==wcscmp(devinfo->product_string, L"ibm-capsense-usb")))
51 {
52 if (devinfo->interface_number == 1)
53 {
54 ret.push_back(std::string(devinfo->path) + XWHATSIT_ENDING_STRING);
55 }
56 } else {
57 if (devinfo->interface_number == 1)
58 {
59 ret.push_back(devinfo->path);
60 }
61 }
62 devinfo = devinfo->next;
63 }
64 hid_free_enumeration(enu);
65 return ret;
66}
67
372aff5f 68Device *Communication::open(std::string path)
1c506c79 69{
372aff5f 70 return new Device(path, mutex);
1c506c79 71}