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

Commit cb3b978

Browse files
committed
Merge branch 'develop' into intellisense-autoconfig.rebased
2 parents 313d0cb + d6459d0 commit cb3b978

16 files changed

+255
-111
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## Version 0.3.4
5+
6+
- Release date: November 22, 2020
7+
8+
### Changed
9+
- Add DTR and RTS signals on serial open and buad rate change
10+
- Improves c_cpp_properties.json autogeneration for intelliSense
11+
412
## Version 0.3.3
513

614
- Release date: October 29, 2020

package-lock.json

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

package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-arduino",
33
"displayName": "Arduino",
44
"description": "Arduino for Visual Studio Code",
5-
"version": "0.3.3",
5+
"version": "0.3.4",
66
"publisher": "vsciot-vscode",
77
"aiKey": "83dd2c27-6594-41d3-85a9-bdb22070eb42",
88
"preview": true,
@@ -93,6 +93,10 @@
9393
"light": "images/ArduinoUpload_16.svg"
9494
}
9595
},
96+
{
97+
"command": "arduino.cliUpload",
98+
"title": "Arduino CLI: Upload"
99+
},
96100
{
97101
"command": "arduino.uploadUsingProgrammer",
98102
"title": "Arduino: Upload Using Programmer"
@@ -101,6 +105,10 @@
101105
"command": "arduino.rebuildIntelliSenseConfig",
102106
"title": "Arduino: Rebuild IntelliSense Configuration"
103107
},
108+
{
109+
"command": "arduino.cliUploadUsingProgrammer",
110+
"title": "Arduino CLI: Upload Using Programmer"
111+
},
104112
{
105113
"command": "arduino.selectProgrammer",
106114
"title": "Arduino: Select Programmer"
@@ -451,6 +459,11 @@
451459
"type": "object",
452460
"title": "Arduino configuration",
453461
"properties": {
462+
"arduino.useArduinoCli": {
463+
"type": "boolean",
464+
"default": false,
465+
"markdownDescription": "Use Arduino CLI installed instead of Arduino IDE. `#arduino.path#` must be set, as there is no default path for 'arduino-cli'. (Requires a restart after change)"
466+
},
454467
"arduino.path": {
455468
"type": "string",
456469
"default": "",

src/arduino/arduino.ts

+111-20
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export enum BuildMode {
3636
Verify = "Verifying",
3737
Analyze = "Analyzing",
3838
Upload = "Uploading",
39+
CliUpload = "Uploading latest binaries",
3940
UploadProgrammer = "Uploading (programmer)",
41+
CliUploadProgrammer = "Uploading latest binaries (programmer)",
4042
};
4143

4244
/**
@@ -219,34 +221,44 @@ export class ArduinoApp {
219221
}
220222
}
221223

222-
/**
223-
* Install arduino board package based on package name and platform hardware architecture.
224-
*/
224+
/**
225+
* Installs arduino board package.
226+
* (If using the aduino CLI this installs the corrosponding core.)
227+
* @param {string} packageName - board vendor
228+
* @param {string} arch - board architecture
229+
* @param {string} version - version of board package or core to download
230+
* @param {boolean} [showOutput=true] - show raw output from command
231+
*/
225232
public async installBoard(packageName: string, arch: string = "", version: string = "", showOutput: boolean = true) {
226233
arduinoChannel.show();
227234
const updatingIndex = packageName === "dummy" && !arch && !version;
228235
if (updatingIndex) {
229236
arduinoChannel.start(`Update package index files...`);
230237
} else {
231238
try {
232-
const packagePath = path.join(this._settings.packagePath, "packages", packageName);
239+
const packagePath = path.join(this._settings.packagePath, "packages", packageName, arch);
233240
if (util.directoryExistsSync(packagePath)) {
234241
util.rmdirRecursivelySync(packagePath);
235242
}
236243
arduinoChannel.start(`Install package - ${packageName}...`);
237244
} catch (error) {
238245
arduinoChannel.start(`Install package - ${packageName} failed under directory : ${error.path}${os.EOL}
239-
Please make sure the folder is not occupied by other procedures .`);
246+
Please make sure the folder is not occupied by other procedures .`);
240247
arduinoChannel.error(`Error message - ${error.message}${os.EOL}`);
241248
arduinoChannel.error(`Exit with code=${error.code}${os.EOL}`);
242249
return;
243250
}
244251
}
252+
arduinoChannel.info(`${packageName}${arch && ":" + arch}${version && ":" + version}`);
245253
try {
246-
await util.spawn(this._settings.commandPath,
247-
["--install-boards", `${packageName}${arch && ":" + arch}${version && ":" + version}`],
248-
undefined,
249-
{ channel: showOutput ? arduinoChannel.channel : null });
254+
this._settings.useArduinoCli ?
255+
await util.spawn(this._settings.commandPath,
256+
["core", "install", `${packageName}${arch && ":" + arch}${version && "@" + version}`], undefined,
257+
{ channel: showOutput ? arduinoChannel.channel : null }) :
258+
await util.spawn(this._settings.commandPath,
259+
["--install-boards", `${packageName}${arch && ":" + arch}${version && ":" + version}`], undefined,
260+
{ channel: showOutput ? arduinoChannel.channel : null });
261+
250262
if (updatingIndex) {
251263
arduinoChannel.end("Updated package index files.");
252264
} else {
@@ -272,6 +284,13 @@ Please make sure the folder is not occupied by other procedures .`);
272284
arduinoChannel.end(`Uninstalled board package - ${boardName}${os.EOL}`);
273285
}
274286

287+
/**
288+
* Downloads or updates a library
289+
* @param {string} libName - name of the library to download
290+
* @param {string} version - version of library to download
291+
* @param {boolean} [showOutput=true] - show raw output from command
292+
*/
293+
275294
public async installLibrary(libName: string, version: string = "", showOutput: boolean = true) {
276295
arduinoChannel.show();
277296
const updatingIndex = (libName === "dummy" && !version);
@@ -281,6 +300,11 @@ Please make sure the folder is not occupied by other procedures .`);
281300
arduinoChannel.start(`Install library - ${libName}`);
282301
}
283302
try {
303+
this.useArduinoCli() ?
304+
await util.spawn(this._settings.commandPath,
305+
["lib", "install", `${libName}${version && "@" + version}`],
306+
undefined,
307+
{ channel: showOutput ? arduinoChannel.channel : undefined }) :
284308
await util.spawn(this._settings.commandPath,
285309
["--install-library", `${libName}${version && ":" + version}`],
286310
undefined,
@@ -450,8 +474,25 @@ Please make sure the folder is not occupied by other procedures .`);
450474
arduinoChannel.error(`Running ${what}-build command failed: ${os.EOL}${msg}`);
451475
return false;
452476
}
477+
return true;
478+
}
479+
}
480+
481+
/**
482+
* Checks if the arduino cli is being used
483+
* @returns {bool} - true if arduino cli is being use
484+
*/
485+
private useArduinoCli() {
486+
return this._settings.useArduinoCli;
487+
// return VscodeSettings.getInstance().useArduinoCli;
488+
}
489+
490+
private getProgrammerString(): string {
491+
const selectProgrammer = this.programmerManager.currentProgrammer;
492+
if (!selectProgrammer) {
493+
logger.notifyUserError("getProgrammerString", new Error(constants.messages.NO_PROGRAMMMER_SELECTED));
494+
return;
453495
}
454-
return true;
455496
}
456497

457498
/**
@@ -475,7 +516,7 @@ Please make sure the folder is not occupied by other procedures .`);
475516
}
476517
const boardDescriptor = this.boardManager.currentBoard.getBuildConfig();
477518

478-
args.push("--board", boardDescriptor);
519+
this._settings.useArduinoCli ? args.push("-b", boardDescriptor) : args.push("--board", boardDescriptor);
479520

480521
if (!ArduinoWorkspace.rootPath) {
481522
vscode.window.showWarningMessage("Workspace doesn't seem to have a folder added to it yet.");
@@ -507,7 +548,26 @@ Please make sure the folder is not occupied by other procedures .`);
507548
await selectSerial();
508549
return false;
509550
}
510-
args.push("--upload");
551+
552+
this._settings.useArduinoCli ? args.push("compile", "--upload") : args.push("--upload");
553+
554+
if (dc.port) {
555+
args.push("--port", dc.port);
556+
}
557+
558+
} else if (mode === BuildMode.CliUpload) {
559+
if ((!dc.configuration || !/upload_method=[^=,]*st[^,]*link/i.test(dc.configuration)) && !dc.port) {
560+
await selectSerial();
561+
return false;
562+
}
563+
564+
if (!this._settings.useArduinoCli) {
565+
arduinoChannel.error("This command is only avaialble while using the Arduino CLI");
566+
return false;
567+
}
568+
569+
args.push("upload");
570+
511571
if (dc.port) {
512572
args.push("--port", dc.port);
513573
}
@@ -521,15 +581,43 @@ Please make sure the folder is not occupied by other procedures .`);
521581
await selectSerial();
522582
return false;
523583
}
524-
args.push("--upload",
525-
"--port", dc.port,
526-
"--useprogrammer",
527-
"--pref", `programmer=${programmer}`);
584+
this._settings.useArduinoCli ?
585+
args.push("compile",
586+
"--upload",
587+
"--porgrammer", programmer) :
588+
args.push("--upload",
589+
"--useprogrammer",
590+
"--pref", `programmer=${programmer}`);
591+
592+
args.push("--port", dc.port);
593+
594+
} else if (mode === BuildMode.CliUploadProgrammer) {
595+
const programmer = this.programmerManager.currentProgrammer;
596+
if (!programmer) {
597+
logger.notifyUserError("getProgrammerString", new Error(constants.messages.NO_PROGRAMMMER_SELECTED));
598+
return false;
599+
}
600+
if (!dc.port) {
601+
await selectSerial();
602+
return false;
603+
}
604+
605+
if (!this._settings.useArduinoCli) {
606+
arduinoChannel.error("This command is only avaialble while using the Arduino CLI");
607+
return false;
608+
}
609+
610+
args.push("compile",
611+
"--upload",
612+
"--porgrammer", programmer,
613+
"--port", dc.port);
614+
528615
} else {
529616
args.push("--verify");
530617
}
531618

532-
if (dc.buildPreferences) {
619+
// TODO: Option to add prefrences when using the CLI
620+
if (dc.buildPreferences && !this._settings.useArduinoCli) {
533621
for (const pref of dc.buildPreferences) {
534622
// Note: BuildPrefSetting makes sure that each preference
535623
// value consists of exactly two items (key and value).
@@ -538,9 +626,12 @@ Please make sure the folder is not occupied by other procedures .`);
538626
}
539627

540628
// We always build verbosely but filter the output based on the settings
541-
args.push("--verbose-build");
629+
if (!this._settings.useArduinoCli) {
630+
args.push("--verbose-build");
631+
}
632+
542633
if (verbose) {
543-
args.push("--verbose-upload");
634+
this._settings.useArduinoCli ? args.push ("--verbose") : args.push("--verbose-upload");
544635
}
545636

546637
await vscode.workspace.saveAll(false);
@@ -559,7 +650,7 @@ Please make sure the folder is not occupied by other procedures .`);
559650
logger.notifyUserError("InvalidOutPutPath", new Error(constants.messages.INVALID_OUTPUT_PATH + buildDir));
560651
return false;
561652
}
562-
args.push("--pref", `build.path=${buildDir}`);
653+
this._settings.useArduinoCli ? args.push ("--build-path", buildDir) : args.push("--pref", `build.path=${buildDir}`);
563654
arduinoChannel.info(`Please see the build logs in output path: ${buildDir}`);
564655
} else {
565656
const msg = "Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README.";

src/arduino/arduinoSettings.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface IArduinoSettings {
2222
preferencePath: string;
2323
defaultBaudRate: number;
2424
preferences: Map<string, string>;
25+
useArduinoCli: boolean;
2526
reloadPreferences(): void;
2627
}
2728

@@ -38,18 +39,21 @@ export class ArduinoSettings implements IArduinoSettings {
3839

3940
private _preferences: Map<string, string>;
4041

42+
private _useArduinoCli: boolean;
43+
4144
public constructor() {
4245
}
4346

4447
public async initialize() {
4548
const platform = os.platform();
4649
this._commandPath = VscodeSettings.getInstance().commandPath;
50+
this._useArduinoCli = VscodeSettings.getInstance().useArduinoCli;
4751
await this.tryResolveArduinoPath();
4852
await this.tryGetDefaultBaudRate();
4953
if (platform === "win32") {
5054
await this.updateWindowsPath();
5155
if (this._commandPath === "") {
52-
this._commandPath = "arduino_debug.exe";
56+
this._useArduinoCli ? this._commandPath = "arduino-cli.exe" : this._commandPath = "arduino_debug.exe";
5357
}
5458
} else if (platform === "linux") {
5559
if (util.directoryExistsSync(path.join(this._arduinoPath, "portable"))) {
@@ -150,6 +154,10 @@ export class ArduinoSettings implements IArduinoSettings {
150154
return this._preferences;
151155
}
152156

157+
public get useArduinoCli() {
158+
return this._useArduinoCli;
159+
}
160+
153161
public get defaultBaudRate() {
154162
return this._defaultBaudRate;
155163
}

0 commit comments

Comments
 (0)