more comments
This commit is contained in:
@@ -44,7 +44,7 @@ func (t *usbTransfer) submit() error {
|
|||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
defer t.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
if t.submitted {
|
if t.submitted {
|
||||||
return errors.New("transfer was already submitted and is not finished yet.")
|
return errors.New("transfer was already submitted and is not finished yet")
|
||||||
}
|
}
|
||||||
t.done = make(chan struct{})
|
t.done = make(chan struct{})
|
||||||
if err := libusb.submit(t.xfer, t.done); err != nil {
|
if err := libusb.submit(t.xfer, t.done); err != nil {
|
||||||
|
@@ -16,15 +16,18 @@
|
|||||||
// Package usb provides a wrapper around libusb-1.0.
|
// Package usb provides a wrapper around libusb-1.0.
|
||||||
package usb
|
package usb
|
||||||
|
|
||||||
|
// Context is the libusb context instance.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
ctx *libusbContext
|
ctx *libusbContext
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug changes the libusb debug level.
|
||||||
func (c *Context) Debug(level int) {
|
func (c *Context) Debug(level int) {
|
||||||
libusb.setDebug(c.ctx, level)
|
libusb.setDebug(c.ctx, level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewContext initializes libusb and returns a new context instance.
|
||||||
func NewContext() *Context {
|
func NewContext() *Context {
|
||||||
c, err := libusb.init()
|
c, err := libusb.init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -97,6 +100,7 @@ func (c *Context) OpenDeviceWithVidPid(vid, pid int) (*Device, error) {
|
|||||||
return devs[0], nil
|
return devs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close releases the libusb context.
|
||||||
func (c *Context) Close() error {
|
func (c *Context) Close() error {
|
||||||
c.done <- struct{}{}
|
c.done <- struct{}{}
|
||||||
if c.ctx != nil {
|
if c.ctx != nil {
|
||||||
|
Reference in New Issue
Block a user