Skip to content

Commit ef9062a

Browse files
committed
Merge remote-tracking branch 'origin/win-hid-fix' into ble_support
2 parents 72d0d2e + 7bc8a2f commit ef9062a

File tree

7 files changed

+26
-40
lines changed

7 files changed

+26
-40
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "unor4wifi-reboot/hid"]
2+
path = unor4wifi-reboot/hid
3+
url = https://github.com/pennam/hid.git

unor4wifi-reboot/compile_darwin.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CGO_ENABLED=1 CC=x86_64-apple-darwin19-clang GOOS=darwin go build

unor4wifi-reboot/compile_win.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows go build

unor4wifi-reboot/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/arduino/unor4wifi-reboot
22

33
go 1.20
44

5-
require github.com/sstallion/go-hid v0.13.3
5+
require github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8

unor4wifi-reboot/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/sstallion/go-hid v0.13.3 h1:u1AIMIFz18tyU0mYN2tSqCXd6RfcV7woZ0aSZ09ePEg=
2-
github.com/sstallion/go-hid v0.13.3/go.mod h1:u5TnL2p4LK+neYxizE0roefazZHMN8yMy6Iurd1a+6o=
1+
github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8 h1:AP5krei6PpUCFOp20TSmxUS4YLoLvASBcArJqM/V+DY=
2+
github.com/karalabe/hid v1.0.1-0.20190806082151-9c14560f9ee8/go.mod h1:Vr51f8rUOLYrfrWDFlV12GGQgM5AT8sVh+2fY4MPeu8=

unor4wifi-reboot/hid

Submodule hid added at 931f677

unor4wifi-reboot/main.go

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,34 @@
2424
package main
2525

2626
import (
27+
"errors"
2728
"fmt"
2829
"os"
2930

30-
"github.com/sstallion/go-hid"
31+
"github.com/karalabe/hid"
3132
)
3233

3334
// The following example was adapted from the HIDAPI documentation to
3435
// demonstrate use of the hid package to communicate with a simple device.
3536
func reboot_unor4() error {
3637
b := make([]byte, 65)
3738

38-
// Initialize the hid package.
39-
if err := hid.Init(); err != nil {
40-
return err
41-
}
42-
4339
// Open the device using the VID and PID.
44-
d, err := hid.OpenFirst(0x2341, 0x1002)
45-
if err != nil {
46-
return err
47-
}
40+
info := hid.Enumerate(0x2341, 0x1002)
4841

49-
// Read the Manufacturer String.
50-
s, err := d.GetMfrStr()
51-
if err != nil {
52-
return err
53-
}
54-
fmt.Printf("Manufacturer String: %s\n", s)
42+
var d *hid.Device
43+
var err error
5544

56-
// Read the Product String.
57-
s, err = d.GetProductStr()
58-
if err != nil {
59-
return err
60-
}
61-
fmt.Printf("Product String: %s\n", s)
62-
63-
// Read the Serial Number String.
64-
s, err = d.GetSerialNbr()
65-
if err != nil {
66-
return err
67-
}
68-
fmt.Printf("Serial Number String: %s\n", s)
69-
70-
// get version
71-
g := make([]byte, 65)
72-
if _, err := d.GetFeatureReport(g); err != nil {
73-
return err
45+
if len(info) == 0 {
46+
fmt.Printf("Cannot enumerate, try direct open\n")
47+
d, err = hid.Open(0x2341, 0x1002)
48+
if err != nil {
49+
fmt.Printf("No board connected\n")
50+
return errors.New("No board connected")
51+
}
52+
} else {
53+
d, _ = info[0].Open()
7454
}
75-
fmt.Printf("FW version: %d.%d.%d\n", g[1], g[2], g[3])
7655

7756
// Reboot
7857
b[0] = 0
@@ -81,10 +60,11 @@ func reboot_unor4() error {
8160
return err
8261
}
8362

84-
// Finalize the hid package.
85-
if err := hid.Exit(); err != nil {
63+
err = d.Close()
64+
if err != nil {
8665
return err
8766
}
67+
8868
return nil
8969
}
9070

0 commit comments

Comments
 (0)