ATL-301: Made port optional when using programmer

When uploading using a programmer, the port is ignored by the CLI.
Also removed `programmer` from compile request [arduino/arduino-cli#861]

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-23 16:10:52 +02:00
parent 6661f661c7
commit 4a9a975dca
3 changed files with 38 additions and 25 deletions

View File

@ -86,29 +86,45 @@ export class UploadSketch extends SketchContribution {
if (!boardsConfig || !boardsConfig.selectedBoard) { if (!boardsConfig || !boardsConfig.selectedBoard) {
throw new Error('No boards selected. Please select a board.'); throw new Error('No boards selected. Please select a board.');
} }
if (!boardsConfig.selectedBoard.fqbn) {
throw new Error(`No core is installed for the '${boardsConfig.selectedBoard.name}' board. Please install the core.`);
}
const [fqbn, { selectedProgrammer }] = await Promise.all([
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn),
this.boardsDataStore.getData(boardsConfig.selectedBoard.fqbn)
]);
let options: CoreService.Upload.Options | undefined = undefined;
const sketchUri = uri;
const optimizeForDebug = this.editorMode.compileForDebug;
if (usingProgrammer) {
const programmer = selectedProgrammer;
if (!programmer) {
throw new Error('Programmer is not selected. Please select a programmer.');
}
options = {
sketchUri,
fqbn,
optimizeForDebug,
programmer
};
} else {
const { selectedPort } = boardsConfig; const { selectedPort } = boardsConfig;
if (!selectedPort) { if (!selectedPort) {
throw new Error('No ports selected. Please select a port.'); throw new Error('No ports selected. Please select a port.');
} }
if (!boardsConfig.selectedBoard.fqbn) { const port = selectedPort.address;
throw new Error(`No core is installed for the '${boardsConfig.selectedBoard.name}' board. Please install the core.`); options = {
} sketchUri,
const [fqbn, data] = await Promise.all([
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn),
this.boardsDataStore.getData(boardsConfig.selectedBoard.fqbn)
]);
this.outputChannelManager.getChannel('Arduino: upload').clear();
const programmer = usingProgrammer ? data.selectedProgrammer : undefined;
if (usingProgrammer && !programmer) {
this.messageService.warn('Programmer is not selected. Uploading without programmer.', { timeout: 2000 });
}
await this.coreService.upload({
sketchUri: uri,
fqbn, fqbn,
port: selectedPort.address, optimizeForDebug,
optimizeForDebug: this.editorMode.compileForDebug, port
programmer };
}); }
this.outputChannelManager.getChannel('Arduino: upload').clear();
await this.coreService.upload(options);
this.messageService.info('Done uploading.', { timeout: 1000 }); this.messageService.info('Done uploading.', { timeout: 1000 });
} catch (e) { } catch (e) {
this.messageService.error(e.toString()); this.messageService.error(e.toString());

View File

@ -20,14 +20,13 @@ export namespace CoreService {
readonly sketchUri: string; readonly sketchUri: string;
readonly fqbn: string; readonly fqbn: string;
readonly optimizeForDebug: boolean; readonly optimizeForDebug: boolean;
readonly programmer?: Programmer | undefined;
} }
} }
export namespace Upload { export namespace Upload {
export interface Options extends Compile.Options { export type Options =
readonly port: string; Compile.Options & Readonly<{ port: string }> |
} Compile.Options & Readonly<{ programmer: Programmer }>;
} }
} }

View File

@ -61,9 +61,6 @@ export class CoreServiceImpl implements CoreService {
compilerReq.setPreprocess(false); compilerReq.setPreprocess(false);
compilerReq.setVerbose(true); compilerReq.setVerbose(true);
compilerReq.setQuiet(false); compilerReq.setQuiet(false);
if (options.programmer) {
compilerReq.setProgrammer(options.programmer.id);
}
const result = client.compile(compilerReq); const result = client.compile(compilerReq);
try { try {
@ -106,8 +103,9 @@ export class CoreServiceImpl implements CoreService {
uploadReq.setInstance(instance); uploadReq.setInstance(instance);
uploadReq.setSketchPath(sketchpath); uploadReq.setSketchPath(sketchpath);
uploadReq.setFqbn(fqbn); uploadReq.setFqbn(fqbn);
if ('port' in options) {
uploadReq.setPort(options.port); uploadReq.setPort(options.port);
if (options.programmer) { } else {
uploadReq.setProgrammer(options.programmer.id); uploadReq.setProgrammer(options.programmer.id);
} }
const result = client.upload(uploadReq); const result = client.upload(uploadReq);