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

Commit d6459d0

Browse files
maddogjtrobotdadadiazulaygiuliofgiuliof
authored
Improved handling of programmer selection (#1118)
* 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 * fix dtr on serial open * fix dtr on serial open * fix linting * pre release v0.3.4 * Add RTS signal on serial open, Add baudrates up to 2000000 (#1142) * add buad rates up to 2M * add rts signal on serial open and buad rate change * add missing space in baud rate array * Quick fix for Intellisense (#1144) * add hardware tool path * intellisense quick fix * add hardware tool path * intellisense quick fix * fix typo * pre release v0.3.4-rc2 * bump to v0.3.4 * Option to use arduino-cli instead of Arduino IDE (#1017) * Hardcoded Arduino-CLI commands for build and upload * Added menu checkbox for Arduino CLI - Upload with programmer is still not supported - Must be created an arduino symlink pointing to arduino-cli * If Arduino-CLI, check for arduino-cli instead of arduino. Not yet supported on Windows or MacOS * Typo * Fixed CI requests * Fixed CI requests * Update src/common/sys/darwin.ts MacOS patch for arduino-cli Co-authored-by: Marc Lage-Vianna <[email protected]> * Update src/common/sys/win32.ts Windows patch for arduino-cli Co-authored-by: Marc Lage-Vianna <[email protected]> * Trigger * add cli option in commandPath for win32 * add cli support to board and lib managers * rename isArduinoCli to useArduinoCli * adds support for uploading using programmer * simplify getProgrammer * add CLI upload * Update src/arduino/arduino.ts Co-authored-by: Jason Tranchida <[email protected]> * refactor uploadUsingProgrammer * fix output path for CLI upload * Update package.json * update cli option text, thanks @maddogjt * update tests Co-authored-by: giuliof <[email protected]> Co-authored-by: Marc Lage-Vianna <[email protected]> Co-authored-by: Adi Azulay <[email protected]> Co-authored-by: Adi Azulay <[email protected]> Co-authored-by: Jason Tranchida <[email protected]> * 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 * add cli suppport for programmers * add documentation Co-authored-by: Marc Goodner <[email protected]> Co-authored-by: Adi Azulay <[email protected]> Co-authored-by: Giulio <[email protected]> Co-authored-by: giuliof <[email protected]> Co-authored-by: Marc Lage-Vianna <[email protected]> Co-authored-by: Adi Azulay <[email protected]>
1 parent ae0ebd4 commit d6459d0

File tree

4 files changed

+56
-89
lines changed

4 files changed

+56
-89
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/arduino/arduino.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class ArduinoApp {
165165
if (this.useArduinoCli()) {
166166
args.push("--programmer", selectProgrammer)
167167
} else {
168-
args.push("--useprogrammer", "--pref", "programmer=" + selectProgrammer)
168+
args.push("--useprogrammer", "--pref", "programmer=arduino:" + selectProgrammer)
169169
}
170170
}
171171

src/arduino/programmerManager.ts

+51-84
Original file line numberDiff line numberDiff line change
@@ -4,111 +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

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

4243
public get currentProgrammer(): string {
4344
return this._programmervalue;
4445
}
4546

47+
/**
48+
* Select a programmer from the list of available programmers
49+
* Set the programmer value in device context
50+
* List format: programmer_name:friendly_name
51+
*/
4652
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" });
53+
const selectionItems = Object.keys(this._availableProgrammers).map(
54+
(programmer) => ({
55+
label: this.getFriendlyName(programmer),
56+
description: programmer,
57+
programmer }));
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-
/**
62-
* Gets a specific programmer from the programmers list.
63-
* If using the Arduino IDE, adds prefix "adruino:"
64-
* @param {ProgrammerList} newProgrammer - a list of the available programmers
65-
*/
66-
public getProgrammer(newProgrammer: ProgrammerList) {
67-
let prefix = "";
68-
if (!this._settings.useArduinoCli) {
69-
prefix = "arduino:"};
70-
switch (newProgrammer) {
71-
case ProgrammerList["AVR ISP"]:
72-
this._programmervalue = prefix + "avrisp";
73-
break;
74-
case ProgrammerList["AVRISP mkII"]:
75-
this._programmervalue = prefix + "avrispmkii";
76-
break;
77-
case ProgrammerList.USBtinyISP:
78-
this._programmervalue = prefix + "usbtinyisp";
79-
break;
80-
case ProgrammerList.ArduinoISP:
81-
this._programmervalue = prefix + "arduinoisp";
82-
break;
83-
case ProgrammerList.USBasp:
84-
this._programmervalue = prefix + "usbasp";
85-
break;
86-
case ProgrammerList["Parallel Programmer"]:
87-
this._programmervalue = prefix + "parallel";
88-
break;
89-
case ProgrammerList["Arduino as ISP"]:
90-
this._programmervalue = prefix + "arduinoasisp";
91-
break;
92-
case ProgrammerList["Arduino Gemma"]:
93-
this._programmervalue = prefix + "usbGemma";
94-
break;
95-
case ProgrammerList["BusPirate as ISP"]:
96-
this._programmervalue = prefix + "buspirate";
97-
break;
98-
case ProgrammerList["Atmel STK500 development board"]:
99-
this._programmervalue = prefix + "stk500";
100-
break;
101-
case ProgrammerList["Atmel JTAGICE3 (ISP mode)"]:
102-
this._programmervalue = prefix + "jtag3isp";
103-
break;
104-
case ProgrammerList["Atmel JTAGICE3 (JTAG mode)"]:
105-
this._programmervalue = prefix + "jtag3";
106-
break;
107-
case ProgrammerList["Atmel-ICE (AVR)"]:
108-
this._programmervalue = prefix + "atmel_ice";
109-
break;
110-
default:
111-
break;
112-
}
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;
11380
}
11481
}

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)