Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bearsh committed Nov 13, 2023
2 parents adffbb8 + 0ab1e45 commit 7fe79d8
Show file tree
Hide file tree
Showing 63 changed files with 6,197 additions and 2,495 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.17

Expand All @@ -40,7 +40,11 @@ jobs:
- name: Build hidraw
run: go build -tags hidraw -v ./...
if: startsWith(matrix.os,'ubuntu')

- name: Test hidraw
run: go test -tags hidraw -v ./...
if: startsWith(matrix.os,'ubuntu')

- name: Cross compile to win (hid disabled)
run: GOOS=windows go build -v ./...
if: startsWith(matrix.os,'ubuntu')
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ environment:

install:
- rmdir C:\go /s /q
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.15.5.windows-%GOARCH%.zip
- 7z x go1.15.5.windows-%GOARCH%.zip -y -oC:\ > NUL
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.17.11.windows-%GOARCH%.zip
- 7z x go1.17.11.windows-%GOARCH%.zip -y -oC:\ > NUL
- go version
- gcc --version

Expand Down
6 changes: 3 additions & 3 deletions c_deps.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// +build dummy
//go:build dummy

// This file is part of a workaround for `go mod vendor` which won't vendor
// C files if there's no Go file in the same directory.
// This would prevent the bundled c-libs from beeing removed when vendored.
// This would prevent the bundled c-libs from being removed when vendored.
//
// This Go file imports the c directory and subdirectories where there is
// another go (named after the direcory) file which is the second part
// another go (named after the directory) file which is the second part
// of this workaround.
//
// These files combined make it so `go mod vendor` behaves correctly.
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/bearsh/hid

go 1.14
go 1.17

require golang.org/x/sys v0.6.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33 changes: 31 additions & 2 deletions hid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ var ErrDeviceClosed = errors.New("hid: device closed")
// operating system is not supported by the library.
var ErrUnsupportedPlatform = errors.New("hid: unsupported platform")

const (
BusUnknown = 0x00
BusUSB = 0x01
BusBluetooth = 0x02
BusI2C = 0x03
BusSPI = 0x04
)

type BusType int

func (t BusType) String() string {
switch t {
case BusUSB:
return "usb"
case BusBluetooth:
return "bluetooth"
case BusI2C:
return "i2c"
case BusSPI:
return "spi"
case BusUnknown:
fallthrough
default:
return "unknown"
}
}

// DeviceInfo is a hidapi info structure.
type DeviceInfo struct {
Path string // Platform-specific device path
Expand All @@ -26,12 +53,14 @@ type DeviceInfo struct {
Serial string // Serial Number
Manufacturer string // Manufacturer String
Product string // Product string
UsagePage uint16 // Usage Page for this Device/Interface (Windows/Mac only)
Usage uint16 // Usage for this Device/Interface (Windows/Mac only)
UsagePage uint16 // Usage Page for this Device/Interface (Windows/Mac/hidraw only)
Usage uint16 // Usage for this Device/Interface (Windows/Mac/hidraw only)

// The USB interface which this logical device
// represents. Valid on both Linux implementations
// in all cases, and valid on the Windows implementation
// only if the device contains more than one interface.
Interface int

BusType BusType // Underlying bus type
}
20 changes: 18 additions & 2 deletions hid_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// This file is released under the 3-clause BSD license. Note however that Linux
// support depends on libusb, released under GNU LGPL 2.1 or later.

// +build !linux,!darwin,!windows ios !cgo
//go:build (!linux && !darwin && !windows) || ios || !cgo

package hid

// Supported returns whether this platform is supported by the HID library or not.
// The goal of this method is to allow programatically handling platforms that do
// The goal of this method is to allow programmatically handling platforms that do
// not support USB HID and not having to fall back to build constraints.
func Supported() bool {
return false
Expand All @@ -28,6 +28,12 @@ type Device struct {
DeviceInfo // Embed the infos for easier access
}

// OpenByPath connects to an HID device by the given path name. On platforms that this file
// implements the method just returns an error.
func OpenByPath(p string) (*Device, error) {
return nil, ErrUnsupportedPlatform
}

// Open connects to an HID device by its path name. On platforms that this file
// implements the method just returns an error.
func (info DeviceInfo) Open() (*Device, error) {
Expand Down Expand Up @@ -98,3 +104,13 @@ func (dev *Device) GetInputReport(b []byte) (int, error) {
func (dev *Device) SetNonblocking(b bool) error {
return ErrUnsupportedPlatform
}

// GetDeviceInfo gets the DeviceInfo from a HID device.
func (dev *Device) GetDeviceInfo() (*DeviceInfo, error) {
return nil, ErrUnsupportedPlatform
}

// GetDeviceInfo gets a report descriptor from a HID device.
func (dev *Device) GetReportDescriptor() ([]byte, error) {
return nil, ErrUnsupportedPlatform
}
Loading

0 comments on commit 7fe79d8

Please sign in to comment.