Skip to content

Commit cdb6d3e

Browse files
committed
Board identification: always check vid.1/pid.1
Even if vid.0/pid.0 is missing. Fix #456
1 parent 44d0f4d commit cdb6d3e

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Diff for: arduino/cores/packagemanager/identify.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (pm *PackageManager) IdentifyBoard(idProps *properties.Map) []*cores.Board
5555
if found {
5656
foundBoards = append(foundBoards, board)
5757
}
58-
if !again {
58+
if !again && id > 0 { // Always check id 0 and 1 (https://github.com/arduino/arduino-cli/issues/456)
5959
break
6060
}
6161
id++

Diff for: arduino/cores/packagemanager/package_manager_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package packagemanager_test
1919

2020
import (
21+
"fmt"
2122
"net/url"
2223
"testing"
2324

@@ -170,3 +171,23 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
170171
}
171172
require.Equal(t, bossac18.InstallDir.String(), uploadProperties.Get("runtime.tools.bossac.path"))
172173
}
174+
175+
func TestIdentifyBoard(t *testing.T) {
176+
pm := packagemanager.NewPackageManager(customHardware, customHardware, customHardware, customHardware)
177+
pm.LoadHardwareFromDirectory(customHardware)
178+
179+
identify := func(vid, pid string) []*cores.Board {
180+
return pm.IdentifyBoard(properties.NewFromHashmap(map[string]string{
181+
"vid": vid, "pid": pid,
182+
}))
183+
}
184+
require.Equal(t, "[arduino:avr:uno]", fmt.Sprintf("%v", identify("0x2341", "0x0001")))
185+
186+
// Check indexed vid/pid format (vid.0/pid.0)
187+
require.Equal(t, "[test:avr:a]", fmt.Sprintf("%v", identify("0x9999", "0x0001")))
188+
require.Equal(t, "[test:avr:b]", fmt.Sprintf("%v", identify("0x9999", "0x0002")))
189+
require.Equal(t, "[test:avr:c]", fmt.Sprintf("%v", identify("0x9999", "0x0003")))
190+
require.Equal(t, "[test:avr:c]", fmt.Sprintf("%v", identify("0x9999", "0x0004")))
191+
// https://github.com/arduino/arduino-cli/issues/456
192+
require.Equal(t, "[test:avr:d]", fmt.Sprintf("%v", identify("0x9999", "0x0005")))
193+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
a.name=Board A
2+
a.vid=0x9999
3+
a.pid=0x0001
4+
5+
b.name=Board B
6+
b.vid.0=0x9999
7+
b.pid.0=0x0002
8+
9+
c.name=Board C
10+
c.vid.0=0x9999
11+
c.pid.0=0x0003
12+
c.vid.1=0x9999
13+
c.pid.1=0x0004
14+
15+
d.name=Board d
16+
d.vid.1=0x9999
17+
d.pid.1=0x0005

0 commit comments

Comments
 (0)