Documentation ¶
Overview ¶
Package gid provides a platform independent interface to access Human Interface Devices. The platform specific parts of this package are heavily based on Signal 11 - HIDAPI (https://github.com/signal11/hidapi).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Devices ¶
func Devices() <-chan *DeviceInfo
Devices returns a channel that will receive a DeviceInfo struct for each HID device.
func FindDevices ¶
func FindDevices(vendor uint16, product uint16) <-chan *DeviceInfo
FindDevices creates a channel to emit all devices with a given vendor and product id. It returns a channel which is closed when all devices have been enumerated.
func FindDevicesByProduct ¶
func FindDevicesByProduct(product string) <-chan *DeviceInfo
FindDevicesByProduct creates a channel to emit device information where the device's product name contains the given string. The channel is closed after all devices have been processed.
Types ¶
type Device ¶
type Device interface { // Close closes the device and release all kept resources. Close() // Write to the device (technically a HID report with type 'output' is sent to the device) Write([]byte) error // WriteFeature to the device (technically a HID report with type 'feature' is sent to the device) WriteFeature([]byte) error // Read from the device Read([]byte) (int, error) // ReadFeature from the device ReadFeature([]byte) (int, error) }
Device interface for an opened HID USB device
type DeviceInfo ¶
type DeviceInfo struct { // Path contains a Platform-specific device path which is used to identify the device Path string // VendorID contains the USB Vendor ID of the device VendorID uint16 // ProductID contains the USB Product ID of the device ProductID uint16 // VersionNumber contains the Version / Release Number of the device VersionNumber uint16 // Manufacturer of the USB device Manufacturer string // Product contains the product name of the device Product string // SerialNumber contains the serial number of the device SerialNumber string InputReportLength uint16 OutputReportLength uint16 FeatureReportLength uint16 }
DeviceInfo provides general information about a device
func ListAllDevices ¶
func ListAllDevices(cond func(*DeviceInfo) bool) []*DeviceInfo
ListAllDevices returns all devices of which the cond function returns true.
func ListFirstDevice ¶
func ListFirstDevice(cond func(*DeviceInfo) bool) *DeviceInfo
ListFirstDevice returns the first device of which the cond function returns true. If no device is found, nil is returned.
func (*DeviceInfo) Open ¶
func (di *DeviceInfo) Open() (Device, error)
Open connects to an HID device by its path name.