Skip to content

Commit 45ebf21

Browse files
committed
[draft] ensure libusb is initialized
1 parent a797c19 commit 45ebf21

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ func (d *DFUDiscovery) Stop() error {
8585
}
8686

8787
// StartSync is the handler for the pluggable-discovery START_SYNC command
88-
func (d *DFUDiscovery) libusbSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
89-
if cErr := C.libusbOpen(); cErr != nil {
90-
return fmt.Errorf("can't open libusb: %s", C.GoString(cErr))
88+
func (d *DFUDiscovery) StartSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
89+
if err := d.libusbOpen(); err != nil {
90+
return err
9191
}
92+
return d.sync(eventCB, errorCB)
93+
}
94+
95+
func (d *DFUDiscovery) libusbSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
9296
if err := C.libusbHotplugRegisterCallback(); err != nil {
9397
return errors.New(C.GoString(err))
9498
}

sync_unix.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
2525
)
2626

27-
// StartSync is the handler for the pluggable-discovery START_SYNC command
28-
func (d *DFUDiscovery) StartSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
27+
func (d *DFUDiscovery) sync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
2928
return d.libusbSync(eventCB, errorCB)
3029
}

sync_windows.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import (
2626
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
2727
)
2828

29-
// StartSync is the handler for the pluggable-discovery START_SYNC command
30-
func (d *DFUDiscovery) StartSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
29+
func (d *DFUDiscovery) sync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
3130
ctx, cancel := context.WithCancel(context.Background())
3231
d.close = cancel
3332

0 commit comments

Comments
 (0)