@@ -24,10 +24,12 @@ import (
24
24
25
25
// Board represents a board loaded from an installed platform
26
26
type 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
31
33
}
32
34
33
35
// HasUsbID returns true if the board match the usb vid and pid parameters
@@ -64,29 +66,41 @@ func (b *Board) String() string {
64
66
return b .FQBN ()
65
67
}
66
68
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
+
67
91
// GetConfigOptions returns an OrderedMap of configuration options for this board.
68
92
// The returned map will have key and value as option id and option name, respectively.
69
93
func (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
76
96
}
77
97
78
98
// GetConfigOptionValues returns an OrderedMap of possible values for a specific configuratio options
79
99
// for this board. The returned map will have key and value as option value and option value name,
80
100
// respectively.
81
101
func (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 ]
90
104
}
91
105
92
106
// GetBuildProperties returns the build properties and the build
0 commit comments