|
|
@ -41,6 +41,7 @@ package hid |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
import "C" |
|
|
|
import "C" |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
@ -57,11 +58,6 @@ import ( |
|
|
|
// > "subsequent calls will cause the hid manager to release previously enumerated devices"
|
|
|
|
// > "subsequent calls will cause the hid manager to release previously enumerated devices"
|
|
|
|
var enumerateLock sync.Mutex |
|
|
|
var enumerateLock sync.Mutex |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
|
|
|
// Initialize the HIDAPI library
|
|
|
|
|
|
|
|
C.hid_init() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Supported returns whether this platform is supported by the HID library or not.
|
|
|
|
// Supported returns whether this platform is supported by the HID library or not.
|
|
|
|
// The goal of this method is to allow programatically handling platforms that do
|
|
|
|
// The goal of this method is to allow programatically handling platforms that do
|
|
|
|
// not support USB HID and not having to fall back to build constraints.
|
|
|
|
// not support USB HID and not having to fall back to build constraints.
|
|
|
@ -113,6 +109,9 @@ func Enumerate(vendorID uint16, productID uint16) []DeviceInfo { |
|
|
|
|
|
|
|
|
|
|
|
// Open connects to an HID device by its path name.
|
|
|
|
// Open connects to an HID device by its path name.
|
|
|
|
func (info DeviceInfo) Open() (*Device, error) { |
|
|
|
func (info DeviceInfo) Open() (*Device, error) { |
|
|
|
|
|
|
|
enumerateLock.Lock() |
|
|
|
|
|
|
|
defer enumerateLock.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
path := C.CString(info.Path) |
|
|
|
path := C.CString(info.Path) |
|
|
|
defer C.free(unsafe.Pointer(path)) |
|
|
|
defer C.free(unsafe.Pointer(path)) |
|
|
|
|
|
|
|
|
|
|
@ -135,7 +134,7 @@ type Device struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Close releases the HID USB device handle.
|
|
|
|
// Close releases the HID USB device handle.
|
|
|
|
func (dev *Device) Close() { |
|
|
|
func (dev *Device) Close() error { |
|
|
|
dev.lock.Lock() |
|
|
|
dev.lock.Lock() |
|
|
|
defer dev.lock.Unlock() |
|
|
|
defer dev.lock.Unlock() |
|
|
|
|
|
|
|
|
|
|
@ -143,6 +142,7 @@ func (dev *Device) Close() { |
|
|
|
C.hid_close(dev.device) |
|
|
|
C.hid_close(dev.device) |
|
|
|
dev.device = nil |
|
|
|
dev.device = nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Write sends an output report to a HID device.
|
|
|
|
// Write sends an output report to a HID device.
|
|
|
|