Started work with hidapi to discover USB devices
This commit is contained in:
parent
c9bfbb9c7b
commit
3ee963267b
34
cmd/root.go
34
cmd/root.go
@ -5,16 +5,38 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/sstallion/go-hid"
|
||||||
|
|
||||||
|
"git.metaunix.net/metaunix/fantastic/devices"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "hugo",
|
Use: "fantastic",
|
||||||
Short: "Hugo is a very fast static site generator",
|
Short: "Fantastic is a CLI app to manage ",
|
||||||
Long: `A Fast and Flexible Static Site Generator built with
|
Long: `A fast and lightweight CLI tool to manage your Glorious peripherals.`,
|
||||||
love by spf13 and friends in Go.
|
|
||||||
Complete documentation is available at https://gohugo.io/documentation/`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println("Test.")
|
count := 0
|
||||||
|
|
||||||
|
hid.Enumerate(0, 0, func(info *hid.DeviceInfo) error {
|
||||||
|
if info.VendorID == devices.VID {
|
||||||
|
count += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%s: ID %04x:%04x %s %s\n",
|
||||||
|
info.Path, info.VendorID, info.ProductID, info.MfrStr, info.ProductStr)
|
||||||
|
fmt.Println("Device Information:")
|
||||||
|
fmt.Printf("\tPath %s\n", info.Path)
|
||||||
|
fmt.Printf("\tVendorID %#04x\n", info.VendorID)
|
||||||
|
fmt.Printf("\tProductID %#04x\n", info.ProductID)
|
||||||
|
fmt.Printf("\tUsagePage %#04x\n", info.UsagePage)
|
||||||
|
fmt.Printf("\tUsage %#04x\n", info.Usage)
|
||||||
|
fmt.Printf("\tInterfaceNbr %d\n", info.InterfaceNbr)
|
||||||
|
fmt.Printf("\tBusType %s\n", info.BusType)
|
||||||
|
fmt.Println()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Printf("Found %d Glorious devices.\n", count)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
devices/init.go
Normal file
9
devices/init.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package devices
|
||||||
|
|
||||||
|
var (
|
||||||
|
VID uint16 = uint16(9610)
|
||||||
|
PID_MODEL_O uint16 = uint16(0)
|
||||||
|
PID_MODEL_D uint16 = uint16(0)
|
||||||
|
PID_MODEL_O_WIRELESS []uint16 = []uint16{uint16(8209), uint16(8226)}
|
||||||
|
PID_MODEL_D_WIRELESS []uint16 = []uint16{uint16(8210), uint16(8227)}
|
||||||
|
)
|
1
go.mod
1
go.mod
@ -6,4 +6,5 @@ require (
|
|||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/spf13/cobra v1.7.0 // indirect
|
github.com/spf13/cobra v1.7.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/sstallion/go-hid v0.13.3 // indirect
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -6,5 +6,7 @@ github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
|||||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/sstallion/go-hid v0.13.3 h1:u1AIMIFz18tyU0mYN2tSqCXd6RfcV7woZ0aSZ09ePEg=
|
||||||
|
github.com/sstallion/go-hid v0.13.3/go.mod h1:u5TnL2p4LK+neYxizE0roefazZHMN8yMy6Iurd1a+6o=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
Loading…
Reference in New Issue
Block a user