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

Commit a14f777

Browse files
hlovdaladiazulay
authored andcommitted
Make upload and uploadUsingProgrammer identical
1 parent 76c74cf commit a14f777

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/arduino/arduino.ts

+37-13
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ export class ArduinoApp {
101101

102102
/**
103103
* Upload code to selected board
104+
* @param {BuildMode} buildMode Build mode.
105+
* * BuildMode.Upload: Compile and upload
106+
* * BuildMode.UploadProgrammer: Compile and upload using the user
107+
* selectable programmer
104108
* @param {bool} [compile=true] - Indicates whether to compile the code when using the CLI to upload
105-
* @param {bool} [useProgrammer=false] - Indicate whether a specific programmer should be used
106109
*/
107-
public async upload(buildMode: BuildMode, compile: boolean = true, useProgrammer: boolean = false) {
110+
public async upload(buildMode: BuildMode, compile: boolean = true) {
108111
const dc = DeviceContext.getInstance();
109112
const args: string[] = [];
110113
let restoreSerialMonitor: boolean = false;
@@ -134,11 +137,6 @@ export class ArduinoApp {
134137
}
135138
}
136139

137-
const selectProgrammer = useProgrammer ? this.getProgrammerString() : null;
138-
if (useProgrammer && !selectProgrammer) {
139-
return;
140-
}
141-
142140
if (buildMode === BuildMode.Upload) {
143141
if ((!dc.configuration || !/upload_method=[^=,]*st[^,]*link/i.test(dc.configuration)) && !dc.port) {
144142
await selectSerial();
@@ -162,17 +160,43 @@ export class ArduinoApp {
162160
args.push("-b", boardDescriptor);
163161
}
164162

165-
if (useProgrammer) {
166-
if (this.useArduinoCli()) {
167-
args.push("--programmer", selectProgrammer)
163+
if (dc.port) {
164+
args.push("--port", dc.port);
165+
}
166+
} else if (buildMode === BuildMode.UploadProgrammer) {
167+
const programmer = this.getProgrammerString();
168+
if (!programmer) {
169+
return;
170+
}
171+
if (!dc.port) {
172+
await selectSerial();
173+
return;
174+
}
175+
176+
if (!compile && !this.useArduinoCli()) {
177+
arduinoChannel.error("This command is only available when using the Arduino CLI");
178+
return;
179+
}
180+
181+
if (!this.useArduinoCli()) {
182+
args.push("--upload");
183+
} else {
184+
// TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
185+
if (compile) {
186+
args.push("compile", "--upload");
168187
} else {
169-
args.push("--useprogrammer", "--pref", "programmer=arduino:" + selectProgrammer)
188+
args.push("upload");
170189
}
190+
args.push("-b", boardDescriptor);
171191
}
172192

173-
if (dc.port) {
174-
args.push("--port", dc.port);
193+
if (this.useArduinoCli()) {
194+
args.push("--programmer", programmer)
195+
} else {
196+
args.push("--useprogrammer", "--pref", "programmer=arduino:" + programmer)
175197
}
198+
199+
args.push("--port", dc.port);
176200
}
177201

178202
const verbose = VscodeSettings.getInstance().logLevel === "verbose";

src/extension.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export async function activate(context: vscode.ExtensionContext) {
198198
if (!status.compile) {
199199
status.compile = "upload";
200200
try {
201-
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, true, true);
201+
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, true);
202202
} catch (ex) {
203203
}
204204
delete status.compile;
@@ -211,7 +211,7 @@ export async function activate(context: vscode.ExtensionContext) {
211211
if (!status.compile) {
212212
status.compile = "cliUpload";
213213
try {
214-
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, false, true);
214+
await arduinoContextModule.default.arduinoApp.upload(BuildMode.UploadProgrammer, false);
215215
} catch (ex) {
216216
}
217217
delete status.compile;

0 commit comments

Comments
 (0)