Skip to content

Commit e22b2a1

Browse files
committed
Added port settings in sketch profile
1 parent 53b6c88 commit e22b2a1

File tree

6 files changed

+341
-267
lines changed

6 files changed

+341
-267
lines changed

internal/arduino/sketch/profiles.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ import (
3434

3535
// projectRaw is a support struct used only to unmarshal the yaml
3636
type projectRaw struct {
37-
ProfilesRaw yaml.Node `yaml:"profiles"`
38-
DefaultProfile string `yaml:"default_profile"`
39-
DefaultFqbn string `yaml:"default_fqbn"`
40-
DefaultPort string `yaml:"default_port,omitempty"`
41-
DefaultProtocol string `yaml:"default_protocol,omitempty"`
42-
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
37+
ProfilesRaw yaml.Node `yaml:"profiles"`
38+
DefaultProfile string `yaml:"default_profile"`
39+
DefaultFqbn string `yaml:"default_fqbn"`
40+
DefaultPort string `yaml:"default_port,omitempty"`
41+
DefaultPortConfig map[string]string `yaml:"default_port_config,omitempty"`
42+
DefaultProtocol string `yaml:"default_protocol,omitempty"`
43+
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
4344
}
4445

4546
// Project represents the sketch project file
@@ -48,6 +49,7 @@ type Project struct {
4849
DefaultProfile string
4950
DefaultFqbn string
5051
DefaultPort string
52+
DefaultPortConfig map[string]string
5153
DefaultProtocol string
5254
DefaultProgrammer string
5355
}
@@ -70,6 +72,12 @@ func (p *Project) AsYaml() string {
7072
if p.DefaultPort != "" {
7173
res += fmt.Sprintf("default_port: %s\n", p.DefaultPort)
7274
}
75+
if len(p.DefaultPortConfig) > 0 {
76+
res += "default_port_config:\n"
77+
for k, v := range p.DefaultPortConfig {
78+
res += fmt.Sprintf(" %s: %s\n", k, v)
79+
}
80+
}
7381
if p.DefaultProtocol != "" {
7482
res += fmt.Sprintf("default_protocol: %s\n", p.DefaultProtocol)
7583
}
@@ -104,6 +112,7 @@ type Profile struct {
104112
Notes string `yaml:"notes"`
105113
FQBN string `yaml:"fqbn"`
106114
Port string `yaml:"port"`
115+
PortConfig map[string]string `yaml:"port_config"`
107116
Protocol string `yaml:"protocol"`
108117
Programmer string `yaml:"programmer"`
109118
Platforms ProfileRequiredPlatforms `yaml:"platforms"`
@@ -112,11 +121,22 @@ type Profile struct {
112121

113122
// ToRpc converts this Profile to an rpc.SketchProfile
114123
func (p *Profile) ToRpc() *rpc.SketchProfile {
124+
var portConfig *rpc.MonitorPortConfiguration
125+
if len(p.PortConfig) > 0 {
126+
portConfig = &rpc.MonitorPortConfiguration{}
127+
for k, v := range p.PortConfig {
128+
portConfig.Settings = append(portConfig.Settings, &rpc.MonitorPortSetting{
129+
SettingId: k,
130+
Value: v,
131+
})
132+
}
133+
}
115134
return &rpc.SketchProfile{
116135
Name: p.Name,
117136
Fqbn: p.FQBN,
118137
Programmer: p.Programmer,
119138
Port: p.Port,
139+
PortConfig: portConfig,
120140
Protocol: p.Protocol,
121141
}
122142
}
@@ -137,6 +157,12 @@ func (p *Profile) AsYaml() string {
137157
if p.Protocol != "" {
138158
res += fmt.Sprintf(" protocol: %s\n", p.Protocol)
139159
}
160+
if len(p.PortConfig) > 0 {
161+
res += " port_config:\n"
162+
for k, v := range p.PortConfig {
163+
res += fmt.Sprintf(" %s: %s\n", k, v)
164+
}
165+
}
140166
res += p.Platforms.AsYaml()
141167
res += p.Libraries.AsYaml()
142168
return res
@@ -301,6 +327,7 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
301327
DefaultProfile: raw.DefaultProfile,
302328
DefaultFqbn: raw.DefaultFqbn,
303329
DefaultPort: raw.DefaultPort,
330+
DefaultPortConfig: raw.DefaultPortConfig,
304331
DefaultProtocol: raw.DefaultProtocol,
305332
DefaultProgrammer: raw.DefaultProgrammer,
306333
}, nil

internal/arduino/sketch/sketch.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ func (s *Sketch) Hash() string {
289289
// ToRpc converts this Sketch into a rpc.LoadSketchResponse
290290
func (s *Sketch) ToRpc() *rpc.Sketch {
291291
defaultPort, defaultProtocol := s.GetDefaultPortAddressAndProtocol()
292+
var defaultPortConfig *rpc.MonitorPortConfiguration
293+
if len(s.Project.DefaultPortConfig) > 0 {
294+
defaultPortConfig = &rpc.MonitorPortConfiguration{}
295+
for k, v := range s.Project.DefaultPortConfig {
296+
defaultPortConfig.Settings = append(defaultPortConfig.Settings, &rpc.MonitorPortSetting{
297+
SettingId: k,
298+
Value: v,
299+
})
300+
}
301+
}
292302
res := &rpc.Sketch{
293303
MainFile: s.MainFile.String(),
294304
LocationPath: s.FullPath.String(),
@@ -297,6 +307,7 @@ func (s *Sketch) ToRpc() *rpc.Sketch {
297307
RootFolderFiles: s.RootFolderFiles.AsStrings(),
298308
DefaultFqbn: s.GetDefaultFQBN(),
299309
DefaultPort: defaultPort,
310+
DefaultPortConfig: defaultPortConfig,
300311
DefaultProtocol: defaultProtocol,
301312
DefaultProgrammer: s.GetDefaultProgrammer(),
302313
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),

0 commit comments

Comments
 (0)