Documentation ¶
Index ¶
- Constants
- Variables
- type Device
- func (dev *Device) Blocking(blocking bool)
- func (dev *Device) Capabilities() HIDP_CAPS
- func (dev *Device) Close()
- func (dev *Device) Events() <-chan []byte
- func (dev *Device) GetFeatureReport(data []byte) (n int, err error)
- func (dev *Device) GetInputReport(data []byte) (n int, err error)
- func (dev *Device) InterfaceId() (mi uint16)
- func (dev *Device) Open() (err error)
- func (dev *Device) Opened() bool
- func (dev *Device) PreparsedData() (pp PreparsedData, err error)
- func (dev *Device) ProductId() (pid uint16)
- func (dev *Device) Read(p []byte) (n int, err error)
- func (dev *Device) ReadTimeout(data []byte, milliseconds int) (n int, err error)
- func (dev *Device) SendFeatureReport(data []byte) (n int, err error)
- func (dev *Device) Strings() (manufacturer, product, serial string)
- func (dev *Device) VendorId() (vid uint16)
- func (dev *Device) WindowsHandle() windows.Handle
- func (dev *Device) Write(p []byte) (n int, err error)
- type Interface
- type PreparsedData
- func (pp PreparsedData) Arrays(capabilities HIDP_CAPS) (buttonCaps [3][]HIDP_BUTTON_CAPS, valueCaps [3][]HIDP_VALUE_CAPS, err error)
- func (pp PreparsedData) Capabilities() (capabilities HIDP_CAPS, err error)
- func (pp PreparsedData) CollectionNodes(capabilities HIDP_CAPS) (nodes []HIDP_LINK_COLLECTION_NODE, err error)
- func (pp PreparsedData) Free()
Constants ¶
const ( IOCTL_HID_SET_FEATURE = 0xb0191 IOCTL_HID_GET_FEATURE = 0xb0192 IOCTL_HID_GET_INPUT_REPORT = 0xb01a2 )
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
InterfaceId returns the interface number of the device.
func (*Device) PreparsedData ¶
func (dev *Device) PreparsedData() (pp PreparsedData, err error)
PreparsedData Data must be freed afterwards.
func (*Device) Read ¶
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 ¶
ReadTimeout reads from the device using a custom timeout.
-1: blocking
0: non-blocking
>0: with timeout of this many milliseconds
func (*Device) SendFeatureReport ¶
SendFeatureReport passes the data to the report identified by the first byte of the data buffer.
func (*Device) Strings ¶
Strings gets manufacturer name, product name and serial number of the device.
func (*Device) WindowsHandle ¶
WindowsHandle provides access to the underlying raw windows.Handle
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()