Started work with hidapi to discover USB devices

This commit is contained in:
2023-05-25 16:56:26 -04:00
parent c9bfbb9c7b
commit 3ee963267b
5 changed files with 40 additions and 6 deletions

View File

@ -5,16 +5,38 @@ import (
"os"
"github.com/spf13/cobra"
"github.com/sstallion/go-hid"
"git.metaunix.net/metaunix/fantastic/devices"
)
var rootCmd = &cobra.Command{
Use: "hugo",
Short: "Hugo is a very fast static site generator",
Long: `A Fast and Flexible Static Site Generator built with
love by spf13 and friends in Go.
Complete documentation is available at https://gohugo.io/documentation/`,
Use: "fantastic",
Short: "Fantastic is a CLI app to manage ",
Long: `A fast and lightweight CLI tool to manage your Glorious peripherals.`,
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)
},
}