8000 Add configure and upload step when uploading to board requiring user … · arduino/arduino-ide@276bf31 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 276bf31

Browse files
committed
Add configure and upload step when uploading to board requiring user fields
1 parent e9dd2fe commit 276bf31

File tree

3 files changed

+92
-4
lines changed

3 files changed

+92
-4
lines changed

arduino-ide-extension/src/browser/contributions/upload-sketch.ts

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { inject, injectable } from 'inversify';
1+
import { inject, injectable, postConstruct } from 'inversify';
22
import { Emitter } from '@theia/core/lib/common/event';
3-
import { CoreService } from '../../common/protocol';
3+
import { BoardUserField, CoreService } from '../../common/protocol';
44
import { ArduinoMenus } from '../menu/arduino-menus';
55
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
66
import { BoardsDataStore } from '../boards/boards-data-store';
@@ -14,6 +14,7 @@ import {
1414
KeybindingRegistry,
1515
TabBarToolbarRegistry,
1616
} from './contribution';
17+
import { UserFieldsDialog } from '../dialogs/user-fields/user-fields-dialog';
1718

1819
@injectable()
1920
export class UploadSketch extends SketchContribution {
@@ -29,16 +30,79 @@ export class UploadSketch extends SketchContribution {
2930
@inject(BoardsServiceProvider)
3031
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
3132

33+
@inject(UserFieldsDialog)
34+
protected readonly userFieldsDialog: UserFieldsDialog;
35+
36+
protected cachedUserFields: Map<string, BoardUserField[]> = new Map();
37+
3238
protected readonly onDidChangeEmitter = new Emitter<Readonly<void>>();
3339
readonly onDidChange = this.onDidChangeEmitter.event;
3440

3541
protected uploadInProgress = false;
42+
protected boardRequiresUserFields = false;
43+
44+
@postConstruct()
45+
protected init(): void {
46+
this.boardsServiceClientImpl.onBoardsConfigChanged(async () => {
47+
const userFields = await this.boardsServiceClientImpl.selectedBoardUserFields();
48+
this.boardRequiresUserFields = userFields.length > 0;
49+
})
50+
}
51+
52+
private selectedFqbnAddress(): string {
53+
const { boardsConfig } = this.boardsServiceClientImpl;
54+
const fqbn = boardsConfig.selectedBoard?.fqbn;
55+
if (!fqbn) {
56+
return "";
57+
}
58+
const address = boardsConfig.selectedBoard?.port?.address
59+
if (!address) {
60+
return "";
61+
}
62+
return fqbn + "|" + address;
63+
}
3664

3765
registerCommands(registry: CommandRegistry): void {
3866
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH, {
39-
execute: () => this.uploadSketch(),
67+
execute: async () => {
68+
const key = this.selectedFqbnAddress();
69+
if (!key) {
70+
return;
71+
}
72+
if (this.boardRequiresUserFields && !this.cachedUserFields.has(key)) {
73+
this.userFieldsDialog.value = await this.boardsServiceClientImpl.selectedBoardUserFields();
74+
const result = await this.userFieldsDialog.open();
75+
if (!result) {
76+
return;
77+
}
78+
this.cachedUserFields.set(key, result);
79+
}
80+
this.uploadSketch();
81+
},
4082
isEnabled: () => !this.uploadInProgress,
4183
});
84+
registry.registerCommand(
85+
UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION,
86+
{
87+
execute: async () => {
88+
const key = this.selectedFqbnAddress();
89+
if (!key) {
90+
return;
91+
}
92+
93+
const cached = this.cachedUserFields.get(key);
94+
this.userFieldsDialog.value = cached ?? await this.boardsServiceClientImpl.selectedBoardUserFields();
95+
96+
const result = await this.userFieldsDialog.open()
97+
if (!result) {
98+
return;
99+
}
100+
this.cachedUserFields.set(key, result);
101+
this.uploadSketch();
102+
},
103+
isEnabled: () => !this.uploadInProgress && this.boardRequiresUserFields,
104+
}
105+
);
42106
registry.registerCommand(
43107
UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER,
44108
{
@@ -62,10 +126,15 @@ export class UploadSketch extends SketchContribution {
62126
label: 'Upload',
63127
order: '1',
64128
});
129+
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
130+
commandId: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.id,
131+
label: UploadSketch.Commands.UPLOAD_WITH_CONFIGURATION.label,
132+
order: '2',
133+
});
65134
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
66135
commandId: UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER.id,
67136
label: 'Upload Using Programmer',
68-
order: '2',
137+
order: '3',
69138
});
70139
}
71140

@@ -131,6 +200,11 @@ export class UploadSketch extends SketchContribution {
131200
const optimizeForDebug = this.editorMode.compileForDebug;
132201
const { selectedPort } = boardsConfig;
133202
const port = selectedPort;
203+
const userFields = this.cachedUserFields.get(this.selectedFqbnAddress());
204+
if (!userFields) {
205+
this.messageService.error("Can't find user fields for connected board");
206+
return;
207+
}
134208

135209
if (usingProgrammer) {
136210
const programmer = selectedProgrammer;
@@ -143,6 +217,7 @@ export class UploadSketch extends SketchContribution {
143217
verbose,
144218
verify,
145219
sourceOverride,
220+
userFields,
146221
};
147222
} else {
148223
options = {
@@ -153,6 +228,7 @@ export class UploadSketch extends SketchContribution {
153228
verbose,
154229
verify,
155230
sourceOverride,
231+
userFields,
156232
};
157233
}
158234
this.outputChannelManager.getChannel('Arduino').clear();
@@ -196,6 +272,11 @@ export namespace UploadSketch {
196272
export const UPLOAD_SKETCH: Command = {
197273
id: 'arduino-upload-sketch',
198274
};
275+
export const UPLOAD_WITH_CONFIGURATION: Command = {
276+
id: 'arduino-upload-with-configuration-sketch',
277+
label: 'Configure And Upload',
278+
category: 'Arduino',
279+
}
199280
export const UPLOAD_SKETCH_USING_PROGRAMMER: Command = {
200281
id: 'arduino-upload-sketch-using-programmer',
201282
};

arduino-ide-extension/src/common/protocol/core-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BoardUserField } from '.';
12
import { Port } from '../../common/protocol/boards-service';
23
import { Programmer } from './boards-service';
34

@@ -43,6 +44,7 @@ export namespace CoreService {
4344
readonly port?: Port | undefined;
4445
readonly programmer?: Programmer | undefined;
4546
readonly verify: boolean;
47+
readonly userFields: BoardUserField[];
4648
}
4749
}
4850

arduino-ide-extension/src/node/core-service-impl.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
146146
}
147147
req.setVerbose(options.verbose);
148148
req.setVerify(options.verify);
149+
150+
options.userFields.forEach(e => {
151+
req.getUserFieldsMap().set(e.name, e.value);
152+
});
153+
149154
const result = responseHandler(client, req);
150155

151156
try {

0 commit comments

Comments
 (0)
0