hid

package module
v0.0.0-...-96a4b2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2015 License: MIT Imports: 7 Imported by: 1

README

HID

A GO package to access Human Interface Devices. The platform specific parts of this package are heavily based on Signal 11 - HIDAPI.

Supported operating systems

The following operating systems are supported targets (as used by $GOOS environment variable)

  • darwin (uses native IOKit framework)
  • linux (uses libusb 1.0+)
  • windows (uses native Windows HID library)
Known quirks for building on Windows 64bit

For building this HID package, you need to have a gcc.exe in your %PATH% environment variable. There are two tested GCC toolchains: tdm-gcc and mingw-w64. At the moment (March 2015), both toolchains are missing some declarations in header files, which will result in the following error message, when running the go build:

D:\projects.go\src\github.com\boombuler\hid> go build -v -work
WORK=C:\Users\xxx\AppData\Local\Temp\go-build011586055
github.com/boombuler/hid
# github.com/boombuler/hid
could not determine kind of name for C.HidD_FreePreparsedData
could not determine kind of name for C.HidD_GetPreparsedData

The solutions is simple: just add these four lines to your gcc toolchain header file hidsdi.h

/* http://msdn.microsoft.com/en-us/library/windows/hardware/ff538893(v=vs.85).aspx */
HIDAPI BOOLEAN NTAPI HidD_FreePreparsedData(PHIDP_PREPARSED_DATA PreparsedData);

/* http://msdn.microsoft.com/en-us/library/windows/hardware/ff539679(v=vs.85).aspx */
HIDAPI BOOLEAN NTAPI HidD_GetPreparsedData(HANDLE HidDeviceObject, PHIDP_PREPARSED_DATA *PreparsedData);

Depending on your gcc toolchain installation folder, the files are located in

C:\TDM-GCC-64\x86_64-w64-mingw32\include\hidsdi.h

or

c:\mingw-w64\x86_64-4.9.2-win32-seh-rt_v3-rev1\mingw64\x86_64-w64-mingw32\include\hidsdi.h

After patching the header file, this package will compile. Future releases of the gcc toolchains will surely fix this issue.

License

Documentation

Overview

HID package 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

View Source
const (
	SUCCESS             usbError = C.LIBUSB_SUCCESS
	ERROR_IO            usbError = C.LIBUSB_ERROR_IO
	ERROR_INVALID_PARAM usbError = C.LIBUSB_ERROR_INVALID_PARAM
	ERROR_ACCESS        usbError = C.LIBUSB_ERROR_ACCESS
	ERROR_NO_DEVICE     usbError = C.LIBUSB_ERROR_NO_DEVICE
	ERROR_NOT_FOUND     usbError = C.LIBUSB_ERROR_NOT_FOUND
	ERROR_BUSY          usbError = C.LIBUSB_ERROR_BUSY
	ERROR_TIMEOUT       usbError = C.LIBUSB_ERROR_TIMEOUT
	ERROR_OVERFLOW      usbError = C.LIBUSB_ERROR_OVERFLOW
	ERROR_PIPE          usbError = C.LIBUSB_ERROR_PIPE
	ERROR_INTERRUPTED   usbError = C.LIBUSB_ERROR_INTERRUPTED
	ERROR_NO_MEM        usbError = C.LIBUSB_ERROR_NO_MEM
	ERROR_NOT_SUPPORTED usbError = C.LIBUSB_ERROR_NOT_SUPPORTED
	ERROR_OTHER         usbError = C.LIBUSB_ERROR_OTHER

	// Request types to use in ControlTransfer().
	REQUEST_TYPE_STANDARD = (0x00 << 5)
	REQUEST_TYPE_CLASS    = (0x01 << 5)
	REQUEST_TYPE_VENDOR   = (0x02 << 5)
	REQUEST_TYPE_RESERVED = (0x03 << 5)

	// Recipient bits for the reqType of ControlTransfer(). Values 4 - 31
	// are reserved.
	RECIPIENT_DEVICE    = 0x00
	RECIPIENT_INTERFACE = 0x01
	RECIPIENT_ENDPOINT  = 0x02
	RECIPIENT_OTHER     = 0x03

	// in: device-to-host
	ENDPOINT_IN = 0x80

	// out: host-to-device
	ENDPOINT_OUT = 0x00

	// Descriptor types as defined by the USB specification.
	DT_DEVICE    = 0x01
	DT_CONFIG    = 0x02
	DT_STRING    = 0x03
	DT_INTERFACE = 0x04
	DT_ENDPOINT  = 0x05
	DT_HID       = 0x21
	DT_REPORT    = 0x22
	DT_PHYSICAL  = 0x23
	DT_HUB       = 0x29

	// Standard request types, as defined in table 9-3 of the USB2 specifications
	REQUEST_GET_STATUS    = 0x00
	REQUEST_CLEAR_FEATURE = 0x01

	// Set or enable a specific feature
	REQUEST_SET_FEATURE = 0x03

	// Set device address for all future accesses
	REQUEST_SET_ADDRESS = 0x05

	// Get the specified descriptor
	REQUEST_GET_DESCRIPTOR = 0x06

	// Used to update existing descriptors or add new descriptors
	REQUEST_SET_DESCRIPTOR = 0x07

	// Get the current device configuration value
	REQUEST_GET_CONFIGURATION = 0x08

	// Set device configuration
	REQUEST_SET_CONFIGURATION = 0x09

	// Return the selected alternate setting for the specified interface.
	REQUEST_GET_INTERFACE = 0x0A

	// Select an alternate interface for the specified interface
	REQUEST_SET_INTERFACE = 0x0B

	// Set then report an endpoint's synchronization frame
	REQUEST_SYNCH_FRAME = 0x0C

	HID_GET_REPORT          = 0x01
	HID_GET_IDLE            = 0x02
	HID_GET_PROTOCOL        = 0x03
	HID_SET_REPORT          = 0x09
	HID_SET_IDLE            = 0x0A
	HID_SET_PROTOCOL        = 0x0B
	HID_REPORT_TYPE_INPUT   = 0x01
	HID_REPORT_TYPE_OUTPUT  = 0x02
	HID_REPORT_TYPE_FEATURE = 0x03
)

Variables

This section is empty.

Functions

func Devices

func Devices() <-chan *DeviceInfo

func FindDevices

func FindDevices(vendor uint16, product uint16) <-chan *DeviceInfo

FindDevices iterates through all devices with a given vendor and product id

Types

type Device

type Device interface {
	// Close closes the device and release all keept resources.
	Close()
	// Write to the device
	// (technically a HID report with type 'output' is send to the device)
	Write([]byte) error
	// Write to the device
	// (technically a HID report with type 'feature' is send to the device)
	WriteFeature([]byte) error
	// Preform an interrupt transfer to the device
	WriteInterrupt(byte, []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

	InputReportLength   uint16
	OutputReportLength  uint16
	FeatureReportLength uint16
}

DeviceInfo provides general information about a device

func ByPath

func ByPath(path string) (*DeviceInfo, error)

func (*DeviceInfo) Open

func (di *DeviceInfo) Open() (Device, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL