8000 Allow port, protocol and port settings to be specified in profiles. by cmaglie · Pull Request #2717 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Allow port, protocol and port settings to be specified in profiles. #2717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added port settings in sketch profile
  • Loading branch information
cmaglie committed Oct 3, 2024
commit e22b2a1b0251b0499ae17d687ffa3c2e09f8e593
39 changes: 33 additions & 6 deletions internal/arduino/sketch/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ import (

// projectRaw is a support struct used only to unmarshal the yaml
type projectRaw struct {
ProfilesRaw yaml.Node `yaml:"profiles"`
DefaultProfile string `yaml:"default_profile"`
DefaultFqbn string `yaml:"default_fqbn"`
DefaultPort string `yaml:"default_port,omitempty"`
DefaultProtocol string `yaml:"default_protocol,omitempty"`
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
ProfilesRaw yaml.Node `yaml:"profiles"`
DefaultProfile string `yaml:"default_profile"`
DefaultFqbn string `yaml:"default_fqbn"`
DefaultPort string `yaml:"default_port,omitempty"`
DefaultPortConfig map[string]string `yaml:"default_port_config,omitempty"`
DefaultProtocol string `yaml:"default_protocol,omitempty"`
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
}

// Project represents the sketch project file
Expand All @@ -48,6 +49,7 @@ type Project struct {
DefaultProfile string
DefaultFqbn string
DefaultPort string
DefaultPortConfig map[string]string
DefaultProtocol string
DefaultProgrammer string
}
Expand All @@ -70,6 +72,12 @@ func (p *Project) AsYaml() string {
if p.DefaultPort != "" {
res += fmt.Sprintf("default_port: %s\n", p.DefaultPort)
}
if len(p.DefaultPortConfig) > 0 {
res += "default_port_config:\n"
for k, v := range p.DefaultPortConfig {
res += fmt.Sprintf(" %s: %s\n", k, v)
}
}
if p.DefaultProtocol != "" {
res += fmt.Sprintf("default_protocol: %s\n", p.DefaultProtocol)
}
Expand Down Expand Up @@ -104,6 +112,7 @@ type Profile struct {
Notes string `yaml:"notes"`
FQBN string `yaml:"fqbn"`
Port string `yaml:"port"`
PortConfig map[string]string `yaml:"port_config"`
Protocol string `yaml:"protocol"`
Programmer string `yaml:"programmer"`
Platforms ProfileRequiredPlatforms `yaml:"platforms"`
Expand All @@ -112,11 +121,22 @@ type Profile struct {

// ToRpc converts this Profile to an rpc.SketchProfile
func (p *Profile) ToRpc() *rpc.SketchProfile {
var portConfig *rpc.MonitorPortConfiguration
if len(p.PortConfig) > 0 {
portConfig = &rpc.MonitorPortConfiguration{}
for k, v := range p.PortConfig {
portConfig.Settings = append(portConfig.Settings, &rpc.MonitorPortSetting{
SettingId: k,
Value: v,
})
}
}
return &rpc.SketchProfile{
Name: p.Name,
Fqbn: p.FQBN,
Programmer: p.Programmer,
Port: p.Port,
PortConfig: portConfig,
Protocol: p.Protocol,
}
}
Expand All @@ -137,6 +157,12 @@ func (p *Profile) AsYaml() string {
if p.Protocol != "" {
res += fmt.Sprintf(" protocol: %s\n", p.Protocol)
}
if len(p.PortConfig) > 0 {
res += " port_config:\n"
for k, v := range p.PortConfig {
res += fmt.Sprintf(" %s: %s\n", k, v)
}
}
res += p.Platforms.AsYaml()
res += p.Libraries.AsYaml()
return res
Expand Down Expand Up @@ -301,6 +327,7 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
DefaultProfile: raw.DefaultProfile,
DefaultFqbn: raw.DefaultFqbn,
DefaultPort: raw.DefaultPort,
DefaultPortConfig: raw.DefaultPortConfig,
DefaultProtocol: raw.DefaultProtocol,
DefaultProgrammer: raw.DefaultProgrammer,
}, nil
Expand Down
11 changes: 11 additions & 0 deletions internal/arduino/sketch/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ func (s *Sketch) Hash() string {
// ToRpc converts this Sketch into a rpc.LoadSketchResponse
func (s *Sketch) ToRpc() *rpc.Sketch {
defaultPort, defaultProtocol := s.GetDefaultPortAddressAndProtocol()
var defaultPortConfig *rpc.MonitorPortConfiguration
if len(s.Project.DefaultPortConfig) > 0 {
defaultPortConfig = &rpc.MonitorPortConfiguration{}
for k, v := range s.Project.DefaultPortConfig {
defaultPortConfig.Settings = append(defaultPortConfig.Settings, &rpc.MonitorPortSetting{
SettingId: k,
Value: v,
})
}
}
res := &rpc.Sketch{
MainFile: s.MainFile.String(),
LocationPath: s.FullPath.String(),
Expand All @@ -297,6 +307,7 @@ func (s *Sketch) ToRpc() *rpc.Sketch {
RootFolderFiles: s.RootFolderFiles.AsStrings(),
DefaultFqbn: s.GetDefaultFQBN(),
DefaultPort: defaultPort,
DefaultPortConfig: defaultPortConfig,
DefaultProtocol: defaultProtocol,
DefaultProgrammer: s.GetDefaultProgrammer(),
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),
Expand Down
Loading
0