hid

package
v0.0.0-...-f2919f2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: MIT Imports: 9 Imported by: 0

README

device.go: Basic functionality of finding, opening and getting information of deviecs io.go: reading and writing of reports util.go: behind the scenes complexity

Documentation

Index

Constants

View Source
const (
	IOCTL_HID_SET_FEATURE      = 0xb0191
	IOCTL_HID_GET_FEATURE      = 0xb0192
	IOCTL_HID_GET_INPUT_REPORT = 0xb01a2
)

Variables

View Source
var (
	ErrAlreadyOpen = fmt.Errorf("device already open")
)

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device holds a single HID device, exposing the necessary functionality to read and write available input, output and feature reports.

func Devices

func Devices(vendorId, productId, usagePage, usage uint16) (devices []*Device)

Devices returns slice containing all HID devices, allowing filtering further by vendor ID, product ID, usage page and usage. Passing `0` to any of the parameters skips checking of that parameter value.

Only filters based on the top-level collections usage.

func (*Device) Blocking

func (dev *Device) Blocking(blocking bool)

Blocking sets the default of the device I/O functions to be either blocking or non-blocking.

func (*Device) Capabilities

func (dev *Device) Capabilities() HIDP_CAPS

Capabilities returns a struct containing information about device usage and maximum report sizes.

func (*Device) Close

func (dev *Device) Close()

Close frees the device and resources that might have been reserved when the device was opened.

func (*Device) Events

func (dev *Device) Events() <-chan []byte

Events returns a channel that streams input events as they come in. Data in the slice is only valid until the next message from the channel is read.

Manual calls to Read() should be avoided if Events() is being used.

func (*Device) GetFeatureReport

func (dev *Device) GetFeatureReport(data []byte) (n int, err error)

GetFeatureReport reads feature report identified by the first byte in the data buffer into that same buffer.

TODO: Should we always just return reportsize slice instead of caller deciding? NOTE: HidD_GetFeature() doesn't return amount of bytes read so using IOCTL instead

func (*Device) GetInputReport

func (dev *Device) GetInputReport(data []byte) (n int, err error)

GetInputReport reads inout report identified by the first byte in the data buffer into that same buffer.

In most cases with devices that have only single input report with ID `0` reading with `Read()` function is preferred.

NOTE: HidD_GetInputReport() doesn't return amount of bytes read so using IOCTL instead

func (*Device) InterfaceId

func (dev *Device) InterfaceId() (mi uint16)

InterfaceId returns the interface number of the device.

func (*Device) Open

func (dev *Device) Open() (err error)

Open prepares the device for I/O

func (*Device) Opened

func (dev *Device) Opened() bool

Opened returns information if the device has been opened.

func (*Device) PreparsedData

func (dev *Device) PreparsedData() (pp PreparsedData, err error)

PreparsedData Data must be freed afterwards.

func (*Device) ProductId

func (dev *Device) ProductId() (pid uint16)

ProductId returns the product ID of the device.

func (*Device) Read

func (dev *Device) Read(p []byte) (n int, err error)

Read reads input report from the device.

If device is set to blocking (default) the read blocks until a value is received, if non-blocking the read returns even if there is nothing to read.

func (*Device) ReadTimeout

func (dev *Device) ReadTimeout(data []byte, milliseconds int) (n int, err error)

ReadTimeout reads from the device using a custom timeout.

-1: blocking

0: non-blocking

>0: with timeout of this many milliseconds

func (*Device) SendFeatureReport

func (dev *Device) SendFeatureReport(data []byte) (n int, err error)

SendFeatureReport passes the data to the report identified by the first byte of the data buffer.

func (*Device) Strings

func (dev *Device) Strings() (manufacturer, product, serial string)

Strings gets manufacturer name, product name and serial number of the device.

func (*Device) VendorId

func (dev *Device) VendorId() (vid uint16)

VendorId returns the vendor ID of the device.

func (*Device) WindowsHandle

func (dev *Device) WindowsHandle() windows.Handle

WindowsHandle provides access to the underlying raw windows.Handle

func (*Device) Write

func (dev *Device) Write(p []byte) (n int, err error)

Write writes output report to the device

type Interface

type Interface interface {
	VendorId() uint16
	ProductId() uint16

	Open() error
	Close()

	Write(p []byte) (n int, err error)
	Read(p []byte) (n int, err error)
	SendFeatureReport(data []byte) (n int, err error)
	GetFeatureReport(data []byte) (n int, err error)
}

Interface that this library is providing. Should make it easier for code using this library to add cross-platform support by making sure the interface is implemented on each platform.

type PreparsedData

type PreparsedData uintptr

func (PreparsedData) Arrays

func (pp PreparsedData) Arrays(capabilities HIDP_CAPS) (buttonCaps [3][]HIDP_BUTTON_CAPS, valueCaps [3][]HIDP_VALUE_CAPS, err error)

func (PreparsedData) Capabilities

func (pp PreparsedData) Capabilities() (capabilities HIDP_CAPS, err error)

func (PreparsedData) CollectionNodes

func (pp PreparsedData) CollectionNodes(capabilities HIDP_CAPS) (nodes []HIDP_LINK_COLLECTION_NODE, err error)

func (PreparsedData) Free

func (pp PreparsedData) Free()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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