@@ -24,10 +24,12 @@ import (
2424
2525// Board represents a board loaded from an installed platform
2626type Board struct {
27- BoardID string
28- Properties * properties.Map `json:"-"`
29- PlatformRelease * PlatformRelease `json:"-"`
30- identificationProperties []* properties.Map
27+ BoardID string
28+ Properties * properties.Map `json:"-"`
29+ PlatformRelease * PlatformRelease `json:"-"`
30+ configOptions * properties.Map
31+ configOptionValues map [string ]* properties.Map
32+ identificationProperties []* properties.Map
3133}
3234
3335// HasUsbID returns true if the board match the usb vid and pid parameters
@@ -64,29 +66,41 @@ func (b *Board) String() string {
6466 return b .FQBN ()
6567}
6668
69+ func (b * Board ) buildConfigOptionsStructures () {
70+ if b .configOptions != nil {
71+ return
72+ }
73+
74+ b .configOptions = properties .NewMap ()
75+ allConfigs := b .Properties .SubTree ("menu" )
76+ for _ , option := range allConfigs .FirstLevelKeys () {
77+ b .configOptions .Set (option , b .PlatformRelease .Menus .Get (option ))
78+ }
79+
80+ b .configOptionValues = map [string ]* properties.Map {}
81+ for configName , options := range allConfigs .FirstLevelOf () {
82+ b .configOptionValues [configName ] = properties .NewMap ()
83+ for _ , value := range options .FirstLevelKeys () {
84+ if label , ok := options .GetOk (value ); ok {
85+ b .configOptionValues [configName ].Set (value , label )
86+ }
87+ }
88+ }
89+ }
90+
6791// GetConfigOptions returns an OrderedMap of configuration options for this board.
6892// The returned map will have key and value as option id and option name, respectively.
6993func (b * Board ) GetConfigOptions () * properties.Map {
70- res := properties .NewMap ()
71- menu := b .Properties .SubTree ("menu" )
72- for _ , option := range menu .FirstLevelKeys () {
73- res .Set (option , b .PlatformRelease .Menus .Get (option ))
74- }
75- return res
94+ b .buildConfigOptionsStructures ()
95+ return b .configOptions
7696}
7797
7898// GetConfigOptionValues returns an OrderedMap of possible values for a specific configuratio options
7999// for this board. The returned map will have key and value as option value and option value name,
80100// respectively.
81101func (b * Board ) GetConfigOptionValues (option string ) * properties.Map {
82- res := properties .NewMap ()
83- menu := b .Properties .SubTree ("menu" ).SubTree (option )
84- for _ , value := range menu .FirstLevelKeys () {
85- if label , ok := menu .GetOk (value ); ok {
86- res .Set (value , label )
87- }
88- }
89- return res
102+ b .buildConfigOptionsStructures ()
103+ return b .configOptionValues [option ]
90104}
91105
92106// GetBuildProperties returns the build properties and the build
0 commit comments