-
Notifications
You must be signed in to change notification settings - Fork 15
/
util.go
48 lines (43 loc) · 803 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package joycon
import (
"fmt"
"github.com/flynn/hid"
)
type DeviceType int
const (
JoyConL DeviceType = 0x2006
JoyConR DeviceType = 0x2007
ProCon DeviceType = 0x2009
)
// Search ...
func Search(dts ...DeviceType) ([]*hid.DeviceInfo, error) {
res := []*hid.DeviceInfo{}
devices, err := hid.Devices()
if err != nil {
return nil, err
}
for _, device := range devices {
if device.VendorID != 0x057e {
continue
}
switch device.ProductID {
default:
continue
case 0x2006, 0x2007, 0x2009:
if len(dts) == 0 {
res = append(res, device)
continue
}
dt := DeviceType(device.ProductID)
for _, t := range dts {
if dt == t {
res = append(res, device)
}
}
}
}
if len(res) == 0 {
return nil, fmt.Errorf("not found device")
}
return res, nil
}