Skip to content
Open
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
50 changes: 49 additions & 1 deletion cmd/hidread/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"runtime/debug"
"strings"
"time"

"github.com/sstallion/go-hid"
)
Expand Down Expand Up @@ -38,6 +39,10 @@ func main() {
path := flag.String("f", "", "File path to device")
size := flag.Int("s", 64, "Size of Input Reports to read")
versionOnly := flag.Bool("v", false, "Output version information.")
enumerate := flag.Bool("e", false, "Enumerate devices.")
vid := flag.Uint("vid", 0, "VID for device to open.")
pid := flag.Uint("pid", 0, "PID for device to open.")
continue_search := flag.Bool("c", false, "Continue scanning for device with specified VID and PID, open when it appears.")

flag.Parse()

Expand All @@ -50,11 +55,54 @@ func main() {
os.Exit(0)
}

if *help || *path == "" {
if *help {
flag.Usage()
os.Exit(0)
}

if *enumerate {
hid.Enumerate(hid.VendorIDAny, hid.ProductIDAny, func(info *hid.DeviceInfo) error {
fmt.Printf("%s: ID %04x:%04x %s %s\n",
info.Path,
info.VendorID,
info.ProductID,
info.MfrStr,
info.ProductStr)
return nil
})
os.Exit(0)
}

var hid_dev hid.DeviceInfo
if *vid != 0 && *pid != 0 {
for {
hid.Enumerate(uint16(*vid), uint16(*pid), func(info *hid.DeviceInfo) error {
fmt.Printf("%s: ID %04x:%04x %s %s\n",
info.Path,
info.VendorID,
info.ProductID,
info.MfrStr,
info.ProductStr)
hid_dev = *info

return nil
})

*path = hid_dev.Path

if *path != "" || !*continue_search {
break
}
time.Sleep(1 * time.Second)
fmt.Printf("Searching..\n")
}
}

if *path == "" {
fmt.Printf("Path empty\n")
os.Exit(0)
}

dev, err := hid.OpenPath(*path)
if err != nil {
fmt.Printf("%v\n", err)
Expand Down