Skip to content

Instantly share code, notes, and snippets.

@sago35
Created January 18, 2023 00:36
Show Gist options
  • Save sago35/6f7b0123a5b7ba2acedfa22a32ade1df to your computer and use it in GitHub Desktop.
Save sago35/6f7b0123a5b7ba2acedfa22a32ade1df to your computer and use it in GitHub Desktop.
USB HID Interrupt Out
package main
import (
"fmt"
"log"
"time"
"github.com/DarkMetalMouse/hid"
)
func main() {
log.SetFlags(log.Lshortfile | log.Lmicroseconds)
di := <-hid.FastFindDevices(0x239a, 0x80cd)
if di == nil {
log.Panic("not found target device")
}
fmt.Printf("%04x:%04x %#v\n\n", di.VendorId, di.ProductId, di)
dev, err := di.Open()
if err != nil {
log.Panic(err)
}
defer dev.Close()
log.Println(dev)
go func() {
for {
b, err := dev.Read()
if err != nil {
time.Sleep(10 * time.Millisecond)
continue
}
log.Printf("% X\n", b)
}
}()
for {
time.Sleep(100 * time.Millisecond)
if err := dev.Write([]byte{0x0d, 0x02}); err != nil {
log.Print(err)
continue
}
log.Print("complete")
}
}
@sago35
Copy link
Author

sago35 commented Jan 18, 2023

Windows で動作した。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment