Tweaks and renames
This commit is contained in:
@@ -17,14 +17,14 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// Only one context should be needed for an application. It should always be closed.
|
||||
ctx = usb.NewContext()
|
||||
ctx := usb.NewContext()
|
||||
defer ctx.Close()
|
||||
|
||||
// Debugging can be turned on; this shows some of the inner workings of the libusb package.
|
||||
ctx.Debug(*debug)
|
||||
|
||||
// ListDevices is used to find the devices to open.
|
||||
devs, err := ctx.ListDevices(func(bus, addr int, desc *usb.Descriptor) bool {
|
||||
devs, err := ctx.ListDevices(func(bus, addr int, desc *usb.Descriptor) bool {
|
||||
// After inspecting the descriptor, return true or false depending on whether
|
||||
// the device is "interesting" or not. Any descriptor for which true is returned
|
||||
// generates a DeviceInfo which is retuned in a slice.
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Endpoint struct {
|
||||
type EndpointInfo struct {
|
||||
Type DescriptorType
|
||||
Address uint8
|
||||
Attributes uint8
|
||||
@@ -21,15 +21,15 @@ type Endpoint struct {
|
||||
SynchAddress uint8
|
||||
}
|
||||
|
||||
func (e Endpoint) Number() int {
|
||||
func (e EndpointInfo) Number() int {
|
||||
return int(e.Address) & ENDPOINT_NUM_MASK
|
||||
}
|
||||
|
||||
func (e Endpoint) Direction() EndpointDirection {
|
||||
func (e EndpointInfo) Direction() EndpointDirection {
|
||||
return EndpointDirection(e.Address) & ENDPOINT_DIR_MASK
|
||||
}
|
||||
|
||||
func (e Endpoint) String() string {
|
||||
func (e EndpointInfo) String() string {
|
||||
return fmt.Sprintf("Endpoint %d %-3s %s - %s %s",
|
||||
e.Number(), e.Direction(),
|
||||
TransferType(e.Attributes)&TRANSFER_TYPE_MASK,
|
||||
@@ -38,17 +38,17 @@ func (e Endpoint) String() string {
|
||||
)
|
||||
}
|
||||
|
||||
type Interface struct {
|
||||
type InterfaceInfo struct {
|
||||
Type DescriptorType
|
||||
Number uint8
|
||||
Alternate uint8
|
||||
IfClass uint8
|
||||
IfSubClass uint8
|
||||
IfProtocol uint8
|
||||
Endpoints []*Endpoint
|
||||
Endpoints []*EndpointInfo
|
||||
}
|
||||
|
||||
func (i Interface) String() string {
|
||||
func (i InterfaceInfo) String() string {
|
||||
return fmt.Sprintf("Interface %02x (config %02x)", i.Number, i.Alternate)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ type Config struct {
|
||||
Config uint8
|
||||
Attributes uint8
|
||||
MaxPower uint8
|
||||
Interfaces [][]*Interface
|
||||
Interfaces [][]*InterfaceInfo
|
||||
}
|
||||
|
||||
func (c Config) String() string {
|
||||
@@ -81,7 +81,7 @@ func newConfig(cfg *C.struct_libusb_config_descriptor) *Config {
|
||||
Len: int(cfg.bNumInterfaces),
|
||||
Cap: int(cfg.bNumInterfaces),
|
||||
}
|
||||
c.Interfaces = make([][]*Interface, 0, len(ifaces))
|
||||
c.Interfaces = make([][]*InterfaceInfo, 0, len(ifaces))
|
||||
for _, iface := range ifaces {
|
||||
var alts []C.struct_libusb_interface_descriptor
|
||||
*(*reflect.SliceHeader)(unsafe.Pointer(&alts)) = reflect.SliceHeader{
|
||||
@@ -89,9 +89,9 @@ func newConfig(cfg *C.struct_libusb_config_descriptor) *Config {
|
||||
Len: int(iface.num_altsetting),
|
||||
Cap: int(iface.num_altsetting),
|
||||
}
|
||||
descs := make([]*Interface, 0, len(alts))
|
||||
descs := make([]*InterfaceInfo, 0, len(alts))
|
||||
for _, alt := range alts {
|
||||
i := &Interface{
|
||||
i := &InterfaceInfo{
|
||||
Type: DescriptorType(alt.bDescriptorType),
|
||||
Number: uint8(alt.bInterfaceNumber),
|
||||
Alternate: uint8(alt.bAlternateSetting),
|
||||
@@ -105,9 +105,9 @@ func newConfig(cfg *C.struct_libusb_config_descriptor) *Config {
|
||||
Len: int(alt.bNumEndpoints),
|
||||
Cap: int(alt.bNumEndpoints),
|
||||
}
|
||||
i.Endpoints = make([]*Endpoint, 0, len(ends))
|
||||
i.Endpoints = make([]*EndpointInfo, 0, len(ends))
|
||||
for _, end := range ends {
|
||||
i.Endpoints = append(i.Endpoints, &Endpoint{
|
||||
i.Endpoints = append(i.Endpoints, &EndpointInfo{
|
||||
Type: DescriptorType(end.bDescriptorType),
|
||||
Address: uint8(end.bEndpointAddress),
|
||||
Attributes: uint8(end.bmAttributes),
|
||||
|
@@ -39,13 +39,13 @@ func Describe(val interface{}) string {
|
||||
//
|
||||
// The given val must be one of the following:
|
||||
// - *usb.Descriptor "Class (SubClass) Protocol"
|
||||
// - *usb.Interface "IfClass (IfSubClass) IfProtocol"
|
||||
// - *usb.InterfaceInfo "IfClass (IfSubClass) IfProtocol"
|
||||
func Classify(val interface{}) string {
|
||||
var class, sub, proto uint8
|
||||
switch val := val.(type) {
|
||||
case *usb.Descriptor:
|
||||
class, sub, proto = val.Class, val.SubClass, val.Protocol
|
||||
case *usb.Interface:
|
||||
case *usb.InterfaceInfo:
|
||||
class, sub, proto = val.IfClass, val.IfSubClass, val.IfProtocol
|
||||
default:
|
||||
return fmt.Sprintf("Unknown (%T)", val)
|
||||
|
Reference in New Issue
Block a user