Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Make upload and uploadUsingProgrammer identical
Browse files Browse the repository at this point in the history
  • Loading branch information
hlovdal authored and adiazulay committed Jan 19, 2021
1 parent 76c74cf commit a14f777
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
50 changes: 37 additions & 13 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ export class ArduinoApp {

/**
* Upload code to selected board
* @param {BuildMode} buildMode Build mode.
* * BuildMode.Upload: Compile and upload
* * BuildMode.UploadProgrammer: Compile and upload using the user
* selectable programmer
* @param {bool} [compile=true] - Indicates whether to compile the code when using the CLI to upload
* @param {bool} [useProgrammer=false] - Indicate whether a specific programmer should be used
*/
public async upload(buildMode: BuildMode, compile: boolean = true, useProgrammer: boolean = false) {
public async upload(buildMode: BuildMode, compile: boolean = true) {
const dc = DeviceContext.getInstance();
const args: string[] = [];
let restoreSerialMonitor: boolean = false;
Expand Down Expand Up @@ -134,11 +137,6 @@ export class ArduinoApp {
}
}

const selectProgrammer = useProgrammer ? this.getProgrammerString() : null;
if (useProgrammer && !selectProgrammer) {
return;
}

if (buildMode === BuildMode.Upload) {
if ((!dc.configuration || !/upload_method=[^=,]*st[^,]*link/i.test(dc.configuration)) && !dc.port) {
await selectSerial();
Expand All @@ -162,17 +160,43 @@ export class ArduinoApp {
args.push("-b", boardDescriptor);
}

if (useProgrammer) {
if (this.useArduinoCli()) {
args.push("--programmer", selectProgrammer)
if (dc.port) {
args.push("--port", dc.port);
}
} else if (buildMode === BuildMode.UploadProgrammer) {
const programmer = this.getProgrammerString();
if (!programmer) {
return;
}
if (!dc.port) {
await selectSerial();
return;
}

if (!compile && !this.useArduinoCli()) {
arduinoChannel.error("This command is only available when using the Arduino CLI");
return;
}

if (!this.useArduinoCli()) {
args.push("--upload");
} else {
// TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
if (compile) {
args.push("compile", "--upload");
} else {
args.push("--useprogrammer", "--pref", "programmer=arduino:" + selectProgrammer)
args.push("upload");
}
args.push("-b", boardDescriptor);
}

if (dc.port) {
args.push("--port", dc.port);
if (this.useArduinoCli()) {
args.push("--programmer", programmer)
} else {
args.push("--useprogrammer", "--pref", "programmer=arduino:" + programmer)
}

args.push("--port", dc.port);
}

const verbose = VscodeSettings.getInstance().logLevel === "verbose";
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export async function activate(context: vscode.ExtensionContext) {
if (!status.compile) {
status.compile = "upload";
try {
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, true, true);
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, true);
} catch (ex) {
}
delete status.compile;
Expand All @@ -211,7 +211,7 @@ export async function activate(context: vscode.ExtensionContext) {
if (!status.compile) {
status.compile = "cliUpload";
try {
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, false, true);
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, false);
} catch (ex) {
}
delete status.compile;
Expand Down

0 comments on commit a14f777

Please sign in to comment.