Skip to content

Commit

Permalink
Merge pull request #4 from mengzhuo/master
Browse files Browse the repository at this point in the history
make ctrl exportable
  • Loading branch information
zserge authored Nov 8, 2017
2 parents 8ac6f75 + 36829f5 commit 110d13e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 9 additions & 1 deletion hid.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package hid

import "time"
import (
"io/ioutil"
"log"
"time"
)

//
// General information about the HID device
Expand Down Expand Up @@ -28,4 +32,8 @@ type Device interface {
GetReport(int) ([]byte, error)
Read(size int, ms time.Duration) ([]byte, error)
Write(data []byte, ms time.Duration) (int, error)
Ctrl(rtype, req, val, index int, data []byte, t int) (int, error)
}

// Default Logger setting
var Logger = log.NewLogger(ioutil.Discard, log.LstdFlags)
11 changes: 7 additions & 4 deletions usb_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"errors"
"io/ioutil"
"log"
"os"
"path/filepath"
"syscall"
Expand Down Expand Up @@ -68,7 +67,7 @@ func (hid *usbDevice) claim() error {
IoctlCode: USBDEVFS_DISCONNECT,
Data: 0,
}); r == -1 {
log.Println("driver disconnect failed:", r, errno)
Logger.Println("driver disconnect failed:", r, errno)
}

if r, errno := hid.ioctl(USBDEVFS_CLAIM, &ifno); r == -1 {
Expand All @@ -90,11 +89,15 @@ func (hid *usbDevice) release() error {
IoctlCode: USBDEVFS_CONNECT,
Data: 0,
}); r == -1 {
log.Println("driver connect failed:", r, errno)
Logger.Println("driver connect failed:", r, errno)
}
return nil
}

func (hid *usbDevice) Ctrl(rtype, req, val, index int, data []byte, t int) (int, error) {
return hid.ctrl(rtype, req, val, index, data, t)
}

func (hid *usbDevice) ctrl(rtype, req, val, index int, data []byte, t int) (int, error) {
s := usbfsCtrl{
ReqType: uint8(rtype),
Expand Down Expand Up @@ -288,7 +291,7 @@ func UsbWalk(cb func(Device)) {
return nil
}
if err := walker(f, cb); err != nil {
log.Println("UsbWalk: ", err)
Logger.Println("UsbWalk: ", err)
}
return nil
})
Expand Down

0 comments on commit 110d13e

Please sign in to comment.