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

Commit

Permalink
Improved handling of programmer selection (#1118)
Browse files Browse the repository at this point in the history
* 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 <MarcLV@users.noreply.github.com>

* Update src/common/sys/win32.ts

Windows patch for arduino-cli

Co-authored-by: Marc Lage-Vianna <MarcLV@users.noreply.github.com>

* 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 <jtranchida@gmail.com>

* refactor uploadUsingProgrammer

* fix output path for CLI upload

* Update package.json

* update cli option text, thanks @maddogjt

* update tests

Co-authored-by: giuliof <giulio@marchtop.localdomain>
Co-authored-by: Marc Lage-Vianna <MarcLV@users.noreply.github.com>
Co-authored-by: Adi Azulay <adazulay@microsoft.com>
Co-authored-by: Adi Azulay <azulayadi@gmail.com>
Co-authored-by: Jason Tranchida <jtranchida@gmail.com>

* 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 <robotdad@users.noreply.github.com>
Co-authored-by: Adi Azulay <adazulay@microsoft.com>
Co-authored-by: Giulio <giulio@glgprograms.it>
Co-authored-by: giuliof <giulio@marchtop.localdomain>
Co-authored-by: Marc Lage-Vianna <MarcLV@users.noreply.github.com>
Co-authored-by: Adi Azulay <azulayadi@gmail.com>
  • Loading branch information
7 people authored Dec 8, 2020
1 parent ae0ebd4 commit d6459d0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 89 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class ArduinoApp {
if (this.useArduinoCli()) {
args.push("--programmer", selectProgrammer)
} else {
args.push("--useprogrammer", "--pref", "programmer=" + selectProgrammer)
args.push("--useprogrammer", "--pref", "programmer=arduino:" + selectProgrammer)
}
}

Expand Down
135 changes: 51 additions & 84 deletions src/arduino/programmerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,78 @@ import { DeviceContext } from "../deviceContext";
import { ArduinoApp } from "./arduino";
import { IArduinoSettings } from "./arduinoSettings";

export enum ProgrammerList {
"AVR ISP",
"AVRISP mkII",
"USBtinyISP",
"ArduinoISP",
"ArduinoISP.org",
"USBasp",
"Parallel Programmer",
"Arduino as ISP",
"Arduino Gemma",
"BusPirate as ISP",
"Atmel STK500 development board",
"Atmel JTAGICE3 (ISP mode)",
"Atmel JTAGICE3 (JTAG mode)",
"Atmel-ICE (AVR)",
}

export class ProgrammerManager {

private static _programmerManager: ProgrammerManager = null;

private _currentprogrammer: ProgrammerList;

private _programmervalue: string;

private _programmerStatusBar: vscode.StatusBarItem;

// Static list of 'available' programmers. This should be repopulated by the currently selected board type.
private _availableProgrammers = {
avrisp: "AVR ISP",
avrispmkii: "AVRISP mkII",
usbtinyisp: "USBtinyISP",
arduinoisp: "ArduinoISP",
usbasp: "USBasp",
parallel: "Parallel Programmer",
arduinoasisp: "Arduino as ISP",
usbGemma: "Arduino Gemma",
buspirate: "BusPirate as ISP",
stk500: "Atmel STK500 development board",
jtag3isp: "Atmel JTAGICE3 (ISP mode)",
jtag3: "Atmel JTAGICE3 (JTAG mode)",
atmel_ice: "Atmel-ICE (AVR)",
};

constructor(private _settings: IArduinoSettings, private _arduinoApp: ArduinoApp) {
this._programmerStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.PROGRAMMER);
this._programmerStatusBar = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
constants.statusBarPriority.PROGRAMMER,
);
this._programmerStatusBar.command = "arduino.selectProgrammer";
this._programmerStatusBar.tooltip = "Select Programmer";
this._programmerStatusBar.text = "<Select Programmer>";
this.setProgrammerValue(DeviceContext.getInstance().programmer);
this._programmerStatusBar.show();
DeviceContext.getInstance().onDidChange(() => {
this.setProgrammerValue(DeviceContext.getInstance().programmer);
});
}

public get currentProgrammer(): string {
return this._programmervalue;
}

/**
* Select a programmer from the list of available programmers
* Set the programmer value in device context
* List format: programmer_name:friendly_name
*/
public async selectProgrammer() {
const chosen: string | undefined = await vscode.window.showQuickPick(Object.keys(ProgrammerList)
.filter((key) => {
return !isNaN(Number(ProgrammerList[key]));
}), { placeHolder: "Select programmer" });
const selectionItems = Object.keys(this._availableProgrammers).map(
(programmer) => ({
label: this.getFriendlyName(programmer),
description: programmer,
programmer }));
const chosen = await vscode.window.showQuickPick(selectionItems, {
placeHolder: "Select programmer",
});
if (!chosen) {
return;
}
this._currentprogrammer = ProgrammerList[chosen];
this.getProgrammer(this._currentprogrammer);
this._programmerStatusBar.text = chosen;

this.setProgrammerValue(chosen.programmer);
const dc = DeviceContext.getInstance();
dc.programmer = chosen;
dc.programmer = chosen.programmer;
}

/**
* Gets a specific programmer from the programmers list.
* If using the Arduino IDE, adds prefix "adruino:"
* @param {ProgrammerList} newProgrammer - a list of the available programmers
*/
public getProgrammer(newProgrammer: ProgrammerList) {
let prefix = "";
if (!this._settings.useArduinoCli) {
prefix = "arduino:"};
switch (newProgrammer) {
case ProgrammerList["AVR ISP"]:
this._programmervalue = prefix + "avrisp";
break;
case ProgrammerList["AVRISP mkII"]:
this._programmervalue = prefix + "avrispmkii";
break;
case ProgrammerList.USBtinyISP:
this._programmervalue = prefix + "usbtinyisp";
break;
case ProgrammerList.ArduinoISP:
this._programmervalue = prefix + "arduinoisp";
break;
case ProgrammerList.USBasp:
this._programmervalue = prefix + "usbasp";
break;
case ProgrammerList["Parallel Programmer"]:
this._programmervalue = prefix + "parallel";
break;
case ProgrammerList["Arduino as ISP"]:
this._programmervalue = prefix + "arduinoasisp";
break;
case ProgrammerList["Arduino Gemma"]:
this._programmervalue = prefix + "usbGemma";
break;
case ProgrammerList["BusPirate as ISP"]:
this._programmervalue = prefix + "buspirate";
break;
case ProgrammerList["Atmel STK500 development board"]:
this._programmervalue = prefix + "stk500";
break;
case ProgrammerList["Atmel JTAGICE3 (ISP mode)"]:
this._programmervalue = prefix + "jtag3isp";
break;
case ProgrammerList["Atmel JTAGICE3 (JTAG mode)"]:
this._programmervalue = prefix + "jtag3";
break;
case ProgrammerList["Atmel-ICE (AVR)"]:
this._programmervalue = prefix + "atmel_ice";
break;
default:
break;
}
private setProgrammerValue(programmer: string | null) {
this._programmervalue = programmer;
this._programmerStatusBar.text = this._programmervalue
? this.getFriendlyName(this._programmervalue)
: "<Select Programmer>";
}

private getFriendlyName(programmer: string): string {
const friendlyName = this._availableProgrammers[programmer];
return friendlyName ? friendlyName : programmer;
}
}
6 changes: 3 additions & 3 deletions src/deviceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._configuration = deviceConfigJson.configuration;
this._output = deviceConfigJson.output;
this._debugger = deviceConfigJson["debugger"];
this._onDidChange.fire();
this._prebuild = deviceConfigJson.prebuild;
this._programmer = deviceConfigJson.programmer;
this._onDidChange.fire();
} else {
Logger.notifyUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
}
Expand All @@ -164,9 +164,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._configuration = null;
this._output = null;
this._debugger = null;
this._onDidChange.fire();
this._prebuild = null;
this._programmer = null;
this._onDidChange.fire();
}
return this;
}, (reason) => {
Expand All @@ -182,9 +182,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._configuration = null;
this._output = null;
this._debugger = null;
this._onDidChange.fire();
this._prebuild = null;
this._programmer = null;
this._onDidChange.fire();

return this;
});
Expand Down

0 comments on commit d6459d0

Please sign in to comment.