Add Device.Manufacturer(), .Product() and .SerialNumber() (#14)
This commit is contained in:

committed by
zagrodzki

parent
1aaa100bdb
commit
757722bf8e
@@ -21,11 +21,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type fakeDevice struct {
|
||||
desc *DeviceDesc
|
||||
alt uint8
|
||||
}
|
||||
|
||||
type fakeTransfer struct {
|
||||
// done is the channel that needs to be closed when the transfer has finished.
|
||||
done chan struct{}
|
||||
@@ -75,7 +70,7 @@ func (f *fakeLibusb) setDebug(*libusbContext, int) {}
|
||||
func (f *fakeLibusb) dereference(d *libusbDevice) {}
|
||||
func (f *fakeLibusb) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
if dev, ok := f.fakeDevices[d]; ok {
|
||||
return dev.desc, nil
|
||||
return dev.devDesc, nil
|
||||
}
|
||||
return nil, fmt.Errorf("invalid USB device %p", d)
|
||||
}
|
||||
@@ -109,8 +104,16 @@ func (f *fakeLibusb) setConfig(d *libusbDevHandle, cfg uint8) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (f *fakeLibusb) getStringDesc(*libusbDevHandle, int) (string, error) {
|
||||
return "", errors.New("not implemented")
|
||||
func (f *fakeLibusb) getStringDesc(d *libusbDevHandle, index int) (string, error) {
|
||||
dev, ok := f.fakeDevices[f.handles[d]]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid USB device %p", d)
|
||||
}
|
||||
str, ok := dev.strDesc[index]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("invalid string descriptor index %d", index)
|
||||
}
|
||||
return str, nil
|
||||
}
|
||||
func (f *fakeLibusb) setAutoDetach(*libusbDevHandle, int) error { return nil }
|
||||
|
||||
@@ -202,10 +205,9 @@ func newFakeLibusb() (*fakeLibusb, func() error) {
|
||||
// without using the full USB stack. Since the fake library uses the
|
||||
// libusbDevice only as an identifier, use an arbitrary unique pointer.
|
||||
// The contents of these pointers is never accessed.
|
||||
fl.fakeDevices[newDevicePointer()] = &fakeDevice{
|
||||
desc: d,
|
||||
alt: 0,
|
||||
}
|
||||
fd := new(fakeDevice)
|
||||
*fd = d
|
||||
fl.fakeDevices[newDevicePointer()] = fd
|
||||
}
|
||||
libusb = fl
|
||||
return fl, func() error {
|
||||
|
Reference in New Issue
Block a user