Skip to content

Commit 422a954

Browse files
authored
[skip changelog] Small cleanups (#688)
* Added FQBN.StringWithoutConfig() method * Removed useless local variables * Use fqbn.StringWithoutConfig() specific function * Added some more verbosity on upload
1 parent a0c5b7f commit 422a954

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Diff for: arduino/cores/fqbn.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
6565
}
6666

6767
func (fqbn *FQBN) String() string {
68-
res := fmt.Sprintf("%s:%s:%s", fqbn.Package, fqbn.PlatformArch, fqbn.BoardID)
68+
res := fqbn.StringWithoutConfig()
6969
if fqbn.Configs.Size() > 0 {
7070
sep := ":"
7171
for _, k := range fqbn.Configs.Keys() {
@@ -75,3 +75,8 @@ func (fqbn *FQBN) String() string {
7575
}
7676
return res
7777
}
78+
79+
// StringWithoutConfig returns the FQBN without the Config part
80+
func (fqbn *FQBN) StringWithoutConfig() string {
81+
return fqbn.Package + ":" + fqbn.PlatformArch + ":" + fqbn.BoardID
82+
}

Diff for: commands/compile/compile.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
206206

207207
// FIXME: Make a function to produce a better name...
208208
// Make the filename without the FQBN configs part
209-
fqbn.Configs = properties.NewMap()
210-
fqbnSuffix := strings.Replace(fqbn.String(), ":", ".", -1)
209+
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
211210

212211
var exportPath *paths.Path
213212
var exportFile string

Diff for: commands/upload/upload.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
130130
}
131131

132132
// Set properties for verbose upload
133-
Verbose := req.GetVerbose()
134-
if Verbose {
133+
if req.GetVerbose() {
135134
if v, ok := uploadProperties.GetOk("upload.params.verbose"); ok {
136135
uploadProperties.Set("upload.verbose", v)
137136
}
@@ -142,8 +141,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
142141
}
143142

144143
// Set properties for verify
145-
Verify := req.GetVerify()
146-
if Verify {
144+
if req.GetVerify() {
147145
uploadProperties.Set("upload.verify", uploadProperties.Get("upload.params.verify"))
148146
} else {
149147
uploadProperties.Set("upload.verify", uploadProperties.Get("upload.params.noverify"))
@@ -191,6 +189,10 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
191189
return nil, fmt.Errorf("cannot get serial port list: %s", err)
192190
}
193191
for _, p := range ports {
192+
if req.GetVerbose() {
193+
outStream.Write([]byte(fmt.Sprintf("Performing 1200-bps touch reset on serial port %s", p)))
194+
outStream.Write([]byte(fmt.Sprintln()))
195+
}
194196
if p == port {
195197
if err := touchSerialPortAt1200bps(p); err != nil {
196198
return nil, fmt.Errorf("cannot perform reset: %s", err)
@@ -209,6 +211,9 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
209211
// Wait for upload port if requested
210212
actualPort := port // default
211213
if uploadProperties.GetBoolean("upload.wait_for_upload_port") {
214+
if req.GetVerbose() {
215+
outStream.Write([]byte(fmt.Sprintln("Waiting for upload port...")))
216+
}
212217
if p, err := waitForNewSerialPort(); err != nil {
213218
return nil, fmt.Errorf("cannot detect serial ports: %s", err)
214219
} else if p == "" {
@@ -240,6 +245,9 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
240245
}
241246

242247
// Run Tool
248+
if req.GetVerbose() {
249+
outStream.Write([]byte(fmt.Sprintln(cmdLine)))
250+
}
243251
cmd, err := executils.Command(cmdArgs)
244252
if err != nil {
245253
return nil, fmt.Errorf("cannot execute upload tool: %s", err)

0 commit comments

Comments
 (0)