mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
vendor: update github.com/karalabe/hid
This commit is contained in:
parent
f983a239a1
commit
8847b15438
6 changed files with 74 additions and 20 deletions
4
vendor/github.com/karalabe/hid/LICENSE.md
generated
vendored
4
vendor/github.com/karalabe/hid/LICENSE.md
generated
vendored
|
|
@ -1,8 +1,8 @@
|
|||
The components of `hid` are licensed as such:
|
||||
|
||||
* `hidapi` is released under the [3-clause BSD](https://github.com/signal11/hidapi/blob/master/LICENSE-bsd.txt) license.
|
||||
* `libusb` is released under the [GNU GPL 2.1](https://github.com/libusb/libusb/blob/master/COPYING)license.
|
||||
* `libusb` is released under the [GNU LGPL 2.1](https://github.com/libusb/libusb/blob/master/COPYING)license.
|
||||
* `go.hid` is released under the [2-clause BSD](https://github.com/GeertJohan/go.hid/blob/master/LICENSE) license.
|
||||
* `gowchar` is released under the [3-clause BSD](https://github.com/orofarne/gowchar/blob/master/LICENSE) license.
|
||||
|
||||
Given the above, `hid` is licensed under GNU GPL 2.1 or later on Linux and 3-clause BSD on other platforms.
|
||||
Given the above, `hid` is licensed under GNU LGPL 2.1 or later on Linux and 3-clause BSD on other platforms.
|
||||
|
|
|
|||
20
vendor/github.com/karalabe/hid/README.md
generated
vendored
20
vendor/github.com/karalabe/hid/README.md
generated
vendored
|
|
@ -1,7 +1,13 @@
|
|||
[![Travis][travisimg]][travisurl]
|
||||
[![AppVeyor][appveyorimg]][appveyorurl]
|
||||
[![GoDoc][docimg]][docurl]
|
||||
|
||||
[docimg]: https://godoc.org/github.com/karalabe/hid?status.svg
|
||||
[docurl]: https://godoc.org/github.com/karalabe/hid
|
||||
[travisimg]: https://travis-ci.org/karalabe/hid.svg?branch=master
|
||||
[travisurl]: https://travis-ci.org/karalabe/hid
|
||||
[appveyorimg]: https://ci.appveyor.com/api/projects/status/plroy54odykb0ch3/branch/master?svg=true
|
||||
[appveyorurl]: https://ci.appveyor.com/project/karalabe/hid
|
||||
[docimg]: https://godoc.org/github.com/karalabe/hid?status.svg
|
||||
[docurl]: https://godoc.org/github.com/karalabe/hid
|
||||
|
||||
# Gopher Interface Devices (USB HID)
|
||||
|
||||
|
|
@ -18,6 +24,12 @@ and go-gettable.
|
|||
Supported platforms at the moment are Linux, macOS and Windows (exclude constraints are also specified
|
||||
for Android and iOS to allow smoother vendoring into cross platform projects).
|
||||
|
||||
## Cross-compiling
|
||||
|
||||
Using `go get` the embedded C library is compiled into the binary format of your host OS. Cross compiling to a different platform or architecture entails disabling CGO by default in Go, causing device enumeration `hid.Enumerate()` to yield no results.
|
||||
|
||||
To cross compile a functional version of this library, you'll need to enable CGO during cross compilation via `CGO_ENABLED=1` and you'll need to install and set a cross compilation enabled C toolkit via `CC=your-cross-gcc`.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
Although the `hid` package is an implementation from scratch, it was heavily inspired by the existing
|
||||
|
|
@ -34,8 +46,8 @@ such, `gowchar` was also vendored in inline (copyright headers and origins prese
|
|||
The components of `hid` are licensed as such:
|
||||
|
||||
* `hidapi` is released under the [3-clause BSD](https://github.com/signal11/hidapi/blob/master/LICENSE-bsd.txt) license.
|
||||
* `libusb` is released under the [GNU GPL 2.1](https://github.com/libusb/libusb/blob/master/COPYING)license.
|
||||
* `libusb` is released under the [GNU LGPL 2.1](https://github.com/libusb/libusb/blob/master/COPYING)license.
|
||||
* `go.hid` is released under the [2-clause BSD](https://github.com/GeertJohan/go.hid/blob/master/LICENSE) license.
|
||||
* `gowchar` is released under the [3-clause BSD](https://github.com/orofarne/gowchar/blob/master/LICENSE) license.
|
||||
|
||||
Given the above, `hid` is licensed under GNU GPL 2.1 or later on Linux and 3-clause BSD on other platforms.
|
||||
Given the above, `hid` is licensed under GNU LGPL 2.1 or later on Linux and 3-clause BSD on other platforms.
|
||||
|
|
|
|||
32
vendor/github.com/karalabe/hid/appveyor.yml
generated
vendored
Normal file
32
vendor/github.com/karalabe/hid/appveyor.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
os: Visual Studio 2015
|
||||
|
||||
# Clone directly into GOPATH.
|
||||
clone_folder: C:\gopath\src\github.com\karalabe\hid
|
||||
clone_depth: 1
|
||||
version: "{branch}.{build}"
|
||||
environment:
|
||||
global:
|
||||
GOPATH: C:\gopath
|
||||
CC: gcc.exe
|
||||
matrix:
|
||||
- GOARCH: amd64
|
||||
MSYS2_ARCH: x86_64
|
||||
MSYS2_BITS: 64
|
||||
MSYSTEM: MINGW64
|
||||
PATH: C:\msys64\mingw64\bin\;%PATH%
|
||||
- GOARCH: 386
|
||||
MSYS2_ARCH: i686
|
||||
MSYS2_BITS: 32
|
||||
MSYSTEM: MINGW32
|
||||
PATH: C:\msys64\mingw32\bin\;%PATH%
|
||||
|
||||
install:
|
||||
- rmdir C:\go /s /q
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.10.1.windows-%GOARCH%.zip
|
||||
- 7z x go1.10.1.windows-%GOARCH%.zip -y -oC:\ > NUL
|
||||
- go version
|
||||
- gcc --version
|
||||
|
||||
build_script:
|
||||
- go install ./...
|
||||
- go test -v ./...
|
||||
2
vendor/github.com/karalabe/hid/hid.go
generated
vendored
2
vendor/github.com/karalabe/hid/hid.go
generated
vendored
|
|
@ -2,7 +2,7 @@
|
|||
// Copyright (c) 2017 Péter Szilágyi. All rights reserved.
|
||||
//
|
||||
// This file is released under the 3-clause BSD license. Note however that Linux
|
||||
// support depends on libusb, released under GNU GPL 2.1 or later.
|
||||
// support depends on libusb, released under GNU LGPL 2.1 or later.
|
||||
|
||||
// Package hid provides an interface for USB HID devices.
|
||||
package hid
|
||||
|
|
|
|||
8
vendor/github.com/karalabe/hid/hid_disabled.go
generated
vendored
8
vendor/github.com/karalabe/hid/hid_disabled.go
generated
vendored
|
|
@ -2,11 +2,9 @@
|
|||
// Copyright (c) 2017 Péter Szilágyi. All rights reserved.
|
||||
//
|
||||
// This file is released under the 3-clause BSD license. Note however that Linux
|
||||
// support depends on libusb, released under GNU GPL 2.1 or later.
|
||||
// support depends on libusb, released under GNU LGPL 2.1 or later.
|
||||
|
||||
// +build !linux
|
||||
// +build !darwin ios
|
||||
// +build !windows
|
||||
// +build !linux,!darwin,!windows ios !cgo
|
||||
|
||||
package hid
|
||||
|
||||
|
|
@ -38,7 +36,7 @@ func (info DeviceInfo) Open() (*Device, error) {
|
|||
|
||||
// Close releases the HID USB device handle. On platforms that this file implements
|
||||
// the method is just a noop.
|
||||
func (dev *Device) Close() {}
|
||||
func (dev *Device) Close() error { return nil }
|
||||
|
||||
// Write sends an output report to a HID device. On platforms that this file
|
||||
// implements the method just returns an error.
|
||||
|
|
|
|||
28
vendor/github.com/karalabe/hid/hid_enabled.go
generated
vendored
28
vendor/github.com/karalabe/hid/hid_enabled.go
generated
vendored
|
|
@ -2,10 +2,9 @@
|
|||
// Copyright (c) 2017 Péter Szilágyi. All rights reserved.
|
||||
//
|
||||
// This file is released under the 3-clause BSD license. Note however that Linux
|
||||
// support depends on libusb, released under GNU GPL 2.1 or later.
|
||||
// support depends on libusb, released under LGNU GPL 2.1 or later.
|
||||
|
||||
// +build !ios
|
||||
// +build linux darwin windows
|
||||
// +build linux,cgo darwin,!ios,cgo windows,cgo
|
||||
|
||||
package hid
|
||||
|
||||
|
|
@ -13,6 +12,7 @@ package hid
|
|||
#cgo CFLAGS: -I./hidapi/hidapi
|
||||
|
||||
#cgo linux CFLAGS: -I./libusb/libusb -DDEFAULT_VISIBILITY="" -DOS_LINUX -D_GNU_SOURCE -DPOLL_NFDS_TYPE=int
|
||||
#cgo linux,!android LDFLAGS: -lrt
|
||||
#cgo darwin CFLAGS: -DOS_DARWIN
|
||||
#cgo darwin LDFLAGS: -framework CoreFoundation -framework IOKit
|
||||
#cgo windows CFLAGS: -DOS_WINDOWS
|
||||
|
|
@ -41,6 +41,7 @@ package hid
|
|||
#endif
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
|
|
@ -48,10 +49,14 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Initialize the HIDAPI library
|
||||
C.hid_init()
|
||||
}
|
||||
// enumerateLock is a mutex serializing access to USB device enumeration needed
|
||||
// by the macOS USB HID system calls, which require 2 consecutive method calls
|
||||
// for enumeration, causing crashes if called concurrently.
|
||||
//
|
||||
// For more details, see:
|
||||
// https://developer.apple.com/documentation/iokit/1438371-iohidmanagersetdevicematching
|
||||
// > "subsequent calls will cause the hid manager to release previously enumerated devices"
|
||||
var enumerateLock sync.Mutex
|
||||
|
||||
// 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
|
||||
|
|
@ -66,6 +71,9 @@ func Supported() bool {
|
|||
// - If the product id is set to 0 then any product matches.
|
||||
// - If the vendor and product id are both 0, all HID devices are returned.
|
||||
func Enumerate(vendorID uint16, productID uint16) []DeviceInfo {
|
||||
enumerateLock.Lock()
|
||||
defer enumerateLock.Unlock()
|
||||
|
||||
// Gather all device infos and ensure they are freed before returning
|
||||
head := C.hid_enumerate(C.ushort(vendorID), C.ushort(productID))
|
||||
if head == nil {
|
||||
|
|
@ -101,6 +109,9 @@ func Enumerate(vendorID uint16, productID uint16) []DeviceInfo {
|
|||
|
||||
// Open connects to an HID device by its path name.
|
||||
func (info DeviceInfo) Open() (*Device, error) {
|
||||
enumerateLock.Lock()
|
||||
defer enumerateLock.Unlock()
|
||||
|
||||
path := C.CString(info.Path)
|
||||
defer C.free(unsafe.Pointer(path))
|
||||
|
||||
|
|
@ -123,7 +134,7 @@ type Device struct {
|
|||
}
|
||||
|
||||
// Close releases the HID USB device handle.
|
||||
func (dev *Device) Close() {
|
||||
func (dev *Device) Close() error {
|
||||
dev.lock.Lock()
|
||||
defer dev.lock.Unlock()
|
||||
|
||||
|
|
@ -131,6 +142,7 @@ func (dev *Device) Close() {
|
|||
C.hid_close(dev.device)
|
||||
dev.device = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write sends an output report to a HID device.
|
||||
|
|
|
|||
Loading…
Reference in a new issue