10000 feature: Detect board port change after upload by cmaglie · Pull Request #2253 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

feature: Detect board port change after upload #2253

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 18 commits into from
Aug 18, 2023
Merged
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
Do not infer upload port if 'upload.wait_for_upload_port' is false
  • Loading branch information
cmaglie committed Aug 9, 2023
commit 33126273d94b852e411ddb2a2c2d5e6ad7171c22
34 changes: 19 additions & 15 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func runProgramAction(pme *packagemanager.Explorer,
outStream, errStream io.Writer,
dryRun bool, userFields map[string]string) (*rpc.Port, error) {

// Ensure watcher events consumption in case of exit on error
defer func() {
// On exit, discard all events until the watcher is closed
go f.DiscardCh(watch)
}()

Expand All @@ -218,20 +218,6 @@ func runProgramAction(pme *packagemanager.Explorer,
}
logrus.WithField("port", port).Tracef("Upload port")

// Default newPort
uploadCompleted := func() *rpc.Port { return nil }
if watch != nil {
// Run port detector
uploadCompletedCtx, cancel := context.WithCancel(context.Background())
newUploadPort := f.NewFuture[*rpc.Port]()
go detectUploadPort(port, watch, uploadCompletedCtx, newUploadPort)
uploadCompleted = func() *rpc.Port {
cancel()
return newUploadPort.Await()
}
defer uploadCompleted() // defer in case of exit on error (ensures goroutine completion)
}

if burnBootloader && programmerID == "" {
return nil, &arduino.MissingProgrammerError{}
}
Expand Down Expand Up @@ -404,6 +390,24 @@ func runProgramAction(pme *packagemanager.Explorer,
uploadProperties.Set("build.project_name", sketchName)
}

// By default do not return any new port...
uploadCompleted := func() *rpc.Port { return nil }
// ...but if there is an expected port change then run the detector...
if uploadProperties.GetBoolean("upload.wait_for_upload_port") && watch != nil {
uploadCompletedCtx, cancel := context.WithCancel(context.Background())
newUploadPort := f.NewFuture[*rpc.Port]()
go detectUploadPort(port, watch, uploadCompletedCtx, newUploadPort)
uploadCompleted = func() *rpc.Port {
cancel()
return newUploadPort.Await()
}

// Ensures goroutines completion in case of exit on error
defer uploadCompleted()
} else {
go f.DiscardCh(watch)
}

// Force port wait to make easier to unbrick boards like the Arduino Leonardo, or similar with native USB,
// when a sketch causes a crash and the native USB serial port is lost.
// See https://github.com/arduino/arduino-cli/issues/1943 for the details.
Expand Down
0