Created
January 18, 2023 00:36
-
-
Save sago35/6f7b0123a5b7ba2acedfa22a32ade1df to your computer and use it in GitHub Desktop.
USB HID Interrupt Out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windows で動作した。