hid

package module
v0.0.0-...-80033a5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: MIT Imports: 8 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's HIDAPI.

Supported operating systems

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

  • darwin (uses native IOKit framework)
  • linux (uses hidraw)
  • windows (uses native Windows HID library)

Known quirks for building on Windows 64-bit

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

Package hid provides access to Human Interface Devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	// Close closes the device and associated resources.
	Close()

	// Write writes an output report to device. The first byte must be the
	// report number to write, zero if the device does not use numbered reports.
	Write([]byte) error

	// ReadCh returns a channel that will be sent input reports from the device.
	// If the device uses numbered reports, the first byte will be the report
	// number.
	ReadCh() <-chan []byte

	// ReadError returns the read error, if any after the channel returned from
	// ReadCh has been closed.
	ReadError() error
}

A Device provides access to a HID device.

type DeviceInfo

type DeviceInfo struct {
	// Path contains a platform-specific device path which is used to identify the device.
	Path string

	VendorID      uint16
	ProductID     uint16
	VersionNumber uint16
	Manufacturer  string
	Product       string

	UsagePage uint16
	Usage     uint16

	InputReportLength  uint16
	OutputReportLength uint16
}

DeviceInfo provides general information about a device.

func ByPath

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

func Devices

func Devices() ([]*DeviceInfo, error)

func (*DeviceInfo) Open

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

Jump to

Keyboard shortcuts

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