Skip to content

Commit

Permalink
Added USB id in boards manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jun 20, 2018
1 parent fc5cfcc commit 3fe34f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
22 changes: 21 additions & 1 deletion arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package cores

import (
"fmt"
"strings"

"github.com/arduino/go-paths-helper"

Expand Down Expand Up @@ -67,7 +68,26 @@ type PlatformRelease struct {
// BoardManifest contains information about a board. These metadata are usually
// provided by the package_index.json
type BoardManifest struct {
Name string `json:"-"`
Name string `json:"-"`
ID []*BoardManifestID `json:"-"`
}

// BoardManifestID contains information on how to identify a board. These metadata
// are usually provided by the package_index.json
type BoardManifestID struct {
USB string `json:"-"`
}

// HasUsbID returns true if the BoardManifes contains the specified USB id as
// identification for this board. usbID should be in the format "0000:0000"
func (bm *BoardManifest) HasUsbID(vid, pid string) bool {
usbID := strings.ToLower(vid + ":" + pid)
for _, id := range bm.ID {
if usbID == strings.ToLower(id.USB) {
return true
}
}
return false
}

// ToolDependencies is a set of tool dependency
Expand Down
15 changes: 13 additions & 2 deletions arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ type indexToolReleaseFlavour struct {

// indexBoard represents a single Board as written in package_index.json file.
type indexBoard struct {
Name string `json:"name"`
Name string `json:"name"`
ID []indexBoardID `json:"id"`
}

type indexBoardID struct {
USB string `json:"usb"`
}

type indexHelp struct {
Expand Down Expand Up @@ -158,7 +163,13 @@ func (inPlatformRelease indexPlatformRelease) extractDeps() cores.ToolDependenci
func (inPlatformRelease indexPlatformRelease) extractBoardsManifest() []*cores.BoardManifest {
boards := make([]*cores.BoardManifest, len(inPlatformRelease.Boards))
for i, board := range inPlatformRelease.Boards {
boards[i] = &cores.BoardManifest{Name: board.Name}
manifest := &cores.BoardManifest{Name: board.Name}
for _, id := range board.ID {
if id.USB != "" {
manifest.ID = append(manifest.ID, &cores.BoardManifestID{USB: id.USB})
}
}
boards[i] = manifest
}
return boards
}
Expand Down

0 comments on commit 3fe34f5

Please sign in to comment.