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

Commit 1fd6b84

Browse files
committed
Improved handling of programmer selection
- Selected programmer is now saved to and loaded from the arduino.json file - Arduino.json is monitored for changes, and changing file will update selected programmer & ui - Programmer selection UI now shows both the friendly name of the programmer, as well as the arduino name - Minor fix to deviceContexts to fire change events after all states are modified - Layed groundwork to support querying list of programmers for the current board from arduino toolchain
1 parent 8cf786d commit 1fd6b84

File tree

2 files changed

+55
-80
lines changed

2 files changed

+55
-80
lines changed

src/arduino/programmerManager.ts

+52-77
Original file line numberDiff line numberDiff line change
@@ -4,103 +4,78 @@ import { DeviceContext } from "../deviceContext";
44
import { ArduinoApp } from "./arduino";
55
import { IArduinoSettings } from "./arduinoSettings";
66

7-
export enum ProgrammerList {
8-
"AVR ISP",
9-
"AVRISP mkII",
10-
"USBtinyISP",
11-
"ArduinoISP",
12-
"ArduinoISP.org",
13-
"USBasp",
14-
"Parallel Programmer",
15-
"Arduino as ISP",
16-
"Arduino Gemma",
17-
"BusPirate as ISP",
18-
"Atmel STK500 development board",
19-
"Atmel JTAGICE3 (ISP mode)",
20-
"Atmel JTAGICE3 (JTAG mode)",
21-
"Atmel-ICE (AVR)",
22-
}
23-
247
export class ProgrammerManager {
25-
26-
private static _programmerManager: ProgrammerManager = null;
27-
28-
private _currentprogrammer: ProgrammerList;
29-
308
private _programmervalue: string;
319

3210
private _programmerStatusBar: vscode.StatusBarItem;
3311

34-
constructor(private _settings: IArduinoSettings, private _arduinoApp: ArduinoApp) {
35-
this._programmerStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.PROGRAMMER);
12+
// Static list of 'available' programmers. This should be repopulated by the currently selected board type.
13+
private _availableProgrammers = {
14+
"arduino:avrisp": "AVR ISP",
15+
"arduino:avrispmkii": "AVRISP mkII",
16+
"arduino:usbtinyisp": "USBtinyISP",
17+
"arduino:arduinoisp": "ArduinoISP",
18+
"arduino:usbasp": "USBasp",
19+
"arduino:parallel": "Parallel Programmer",
20+
"arduino:arduinoasisp": "Arduino as ISP",
21+
"arduino:usbGemma": "Arduino Gemma",
22+
"arduino:buspirate": "BusPirate as ISP",
23+
"arduino:stk500": "Atmel STK500 development board",
24+
"arduino:jtag3isp": "Atmel JTAGICE3 (ISP mode)",
25+
"arduino:jtag3": "Atmel JTAGICE3 (JTAG mode)",
26+
"arduino:atmel_ice": "Atmel-ICE (AVR)",
27+
};
28+
29+
constructor(
30+
private _settings: IArduinoSettings,
31+
private _arduinoApp: ArduinoApp
32+
) {
33+
this._programmerStatusBar = vscode.window.createStatusBarItem(
34+
vscode.StatusBarAlignment.Right,
35+
constants.statusBarPriority.PROGRAMMER
36+
);
3637
this._programmerStatusBar.command = "arduino.selectProgrammer";
3738
this._programmerStatusBar.tooltip = "Select Programmer";
38-
this._programmerStatusBar.text = "<Select Programmer>";
39+
this.setProgrammerValue(DeviceContext.getInstance().programmer);
3940
this._programmerStatusBar.show();
41+
DeviceContext.getInstance().onDidChange(() => {
42+
this.setProgrammerValue(DeviceContext.getInstance().programmer);
43+
});
4044
}
4145

4246
public get currentProgrammer(): string {
4347
return this._programmervalue;
4448
}
4549

4650
public async selectProgrammer() {
47-
const chosen: string | undefined = await vscode.window.showQuickPick(Object.keys(ProgrammerList)
48-
.filter((key) => {
49-
return !isNaN(Number(ProgrammerList[key]));
50-
}), { placeHolder: "Select programmer" });
51+
const selectionItems = Object.keys(this._availableProgrammers).map(
52+
(programmer) => ({
53+
label: this.getFriendlyName(programmer),
54+
description: programmer,
55+
programmer,
56+
})
57+
);
58+
const chosen = await vscode.window.showQuickPick(selectionItems, {
59+
placeHolder: "Select programmer",
60+
});
5161
if (!chosen) {
5262
return;
5363
}
54-
this._currentprogrammer = ProgrammerList[chosen];
55-
this.getProgrammer(this._currentprogrammer);
56-
this._programmerStatusBar.text = chosen;
64+
65+
this.setProgrammerValue(chosen.programmer);
5766
const dc = DeviceContext.getInstance();
58-
dc.programmer = chosen;
67+
dc.programmer = chosen.programmer;
5968
}
6069

61-
public getProgrammer(newProgrammer: ProgrammerList) {
62-
switch (newProgrammer) {
63-
case ProgrammerList["AVR ISP"]:
64-
this._programmervalue = "arduino:avrisp";
65-
break;
66-
case ProgrammerList["AVRISP mkII"]:
67-
this._programmervalue = "arduino:avrispmkii";
68-
break;
69-
case ProgrammerList.USBtinyISP:
70-
this._programmervalue = "arduino:usbtinyisp";
71-
break;
72-
case ProgrammerList.ArduinoISP:
73-
this._programmervalue = "arduino:arduinoisp";
74-
break;
75-
case ProgrammerList.USBasp:
76-
this._programmervalue = "arduino:usbasp";
77-
break;
78-
case ProgrammerList["Parallel Programmer"]:
79-
this._programmervalue = "arduino:parallel";
80-
break;
81-
case ProgrammerList["Arduino as ISP"]:
82-
this._programmervalue = "arduino:arduinoasisp";
83-
break;
84-
case ProgrammerList["Arduino Gemma"]:
85-
this._programmervalue = "arduino:usbGemma";
86-
break;
87-
case ProgrammerList["BusPirate as ISP"]:
88-
this._programmervalue = "arduino:buspirate";
89-
break;
90-
case ProgrammerList["Atmel STK500 development board"]:
91-
this._programmervalue = "arduino:stk500";
92-
break;
93-
case ProgrammerList["Atmel JTAGICE3 (ISP mode)"]:
94-
this._programmervalue = "arduino:jtag3isp";
95-
break;
96-
case ProgrammerList["Atmel JTAGICE3 (JTAG mode)"]:
97-
this._programmervalue = "arduino:jtag3";
98-
break;
99-
case ProgrammerList["Atmel-ICE (AVR)"]:
100-
this._programmervalue = "arduino:atmel_ice";
101-
break;
102-
default:
103-
break;
104-
}
70+
private setProgrammerValue(programmer: string | null) {
71+
this._programmervalue = programmer;
72+
this._programmerStatusBar.text = this._programmervalue
73+
? this.getFriendlyName(this._programmervalue)
74+
: "<Select Programmer>";
75+
}
76+
77+
private getFriendlyName(programmer: string): string {
78+
const friendlyName = this._availableProgrammers[programmer];
79+
return friendlyName ? friendlyName : programmer;
10580
}
10681
}

src/deviceContext.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
151151
this._configuration = deviceConfigJson.configuration;
152152
this._output = deviceConfigJson.output;
153153
this._debugger = deviceConfigJson["debugger"];
154-
this._onDidChange.fire();
155154
this._prebuild = deviceConfigJson.prebuild;
156155
this._programmer = deviceConfigJson.programmer;
156+
this._onDidChange.fire();
157157
} else {
158158
Logger.notifyUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
159159
}
@@ -164,9 +164,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
164164
this._configuration = null;
165165
this._output = null;
166166
this._debugger = null;
167-
this._onDidChange.fire();
168167
this._prebuild = null;
169168
this._programmer = null;
169+
this._onDidChange.fire();
170170
}
171171
return this;
172172
}, (reason) => {
@@ -182,9 +182,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
182182
this._configuration = null;
183183
this._output = null;
184184
this._debugger = null;
185-
this._onDidChange.fire();
186185
this._prebuild = null;
187186
this._programmer = null;
187+
this._onDidChange.fire();
188188

189189
return this;
190190
});

0 commit comments

Comments
 (0)