Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add input report read to windows #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 72 additions & 70 deletions hid.go
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
// 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)
package hid

import "strings"

// DeviceInfo provides general information about a device
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
}

// Device interface for an opened HID USB 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)
}

// FindDevices iterates through all devices with a given vendor and product id
func FindDevices(vendor uint16, product uint16) <-chan *DeviceInfo {
result := make(chan *DeviceInfo)
go func() {
for dev := range Devices() {
if dev.VendorId == vendor && dev.ProductId == product {
result <- dev
}
}
close(result)
}()
return result
}

// FindDevicesByProduct iterates through all devices with a given vendor and product id
func FindDevicesByProduct(product string) <-chan *DeviceInfo {
result := make(chan *DeviceInfo)

go func() {
for dev := range Devices() {
if strings.Contains(dev.Product, product) {
result <- dev
}
}
close(result)
}()

return result
}
// 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)
package hid

import "strings"

// DeviceInfo provides general information about a device
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
}

// Device interface for an opened HID USB 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
// Perform an interrupt transfer to the device
WriteInterrupt(byte, []byte) (int, error)
// Read Input Report from the device
Read() ([]byte, error)
}

// FindDevices iterates through all devices with a given vendor and product id
func FindDevices(vendor uint16, product uint16) <-chan *DeviceInfo {
result := make(chan *DeviceInfo)
go func() {
for dev := range Devices() {
if dev.VendorId == vendor && dev.ProductId == product {
result <- dev
}
}
close(result)
}()
return result
}

// FindDevicesByProduct iterates through all devices with a given vendor and product id
func FindDevicesByProduct(product string) <-chan *DeviceInfo {
result := make(chan *DeviceInfo)

go func() {
for dev := range Devices() {
if strings.Contains(dev.Product, product) {
result <- dev
}
}
close(result)
}()

return result
}
4 changes: 4 additions & 0 deletions hid_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func (dev *osxDevice) WriteFeature(data []byte) error {
return dev.setReport(C.kIOHIDReportTypeFeature, data)
}

func (d *osxDevice) Read() ([]byte, error) {
return nil, errors.New("Read is not implemented")
}

func (dev *osxDevice) Write(data []byte) error {
return dev.setReport(C.kIOHIDReportTypeOutput, data)
}
Expand Down
4 changes: 4 additions & 0 deletions hid_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func (dev *linuxDevice) WriteFeature(data []byte) error {
return dev.writeReport(HID_REPORT_TYPE_FEATURE, data)
}

func (d *linuxDevice) Read() ([]byte, error) {
return nil, errors.New("Read is not implemented")
}

func (dev *linuxDevice) Write(data []byte) error {
return dev.writeReport(HID_REPORT_TYPE_OUTPUT, data)
}
Expand Down
Loading