diff --git a/README.md b/README.md index 2435de20..e77fed5d 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,8 @@ The following Visual Studio Code settings are available for the Arduino extensio "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json", "http://arduino.esp8266.com/stable/package_esp8266com_index.json" ], - "arduino.defaultBaudRate": 115200 + "arduino.defaultBaudRate": 115200, + "arduino.defaultOutputPath": "" } ``` - `arduino.path` - Path to Arduino, you can use a custom version of Arduino by modifying this setting to include the full path. Example: `C:\\Program Files\\Arduino` for Windows, `/Applications` for Mac, `/home//Downloads/arduino-1.8.1` for Linux. (Requires a restart after change). The default value is automatically detected from your Arduino IDE installation path. @@ -84,6 +85,7 @@ serialport-list -f jsonline - `arduino.disableTestingOpen` - Enable/disable automatic sending of a test message to the serial port for checking the open status. The default value is `false` (a test message will be sent). - `arduino.skipHeaderProvider` - Enable/disable the extension providing completion items for headers. This functionality is included in newer versions of the C++ extension. The default value is `false`. - `arduino.defaultBaudRate` - Default baud rate for the serial port monitor. The default value is 115200. Supported values are 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400 and 250000. +- `arduino.defaultOutputPath` - Default output path for the compiler. By default, this option is not set. The following settings are as per sketch settings of the Arduino extension. You can find them in `.vscode/arduino.json` under the workspace. diff --git a/package.json b/package.json index 93f488e5..93b81755 100644 --- a/package.json +++ b/package.json @@ -462,6 +462,10 @@ "arduino.defaultBaudRate": { "type": "number", "default": 115200 + }, + "arduino.defaultOutputPath": { + "type": "string", + "default": "" } } }, diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index d222000e..f06581f9 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -146,7 +146,10 @@ export class ArduinoApp { Logger.notifyUserError("InvalidOutPutPath", new Error(constants.messages.INVALID_OUTPUT_PATH + outputPath)); return; } - + args.push("--pref", `build.path=${outputPath}`); + arduinoChannel.info(`Please see the build logs in Output path: ${outputPath}`); + } else if (!VscodeSettings.getInstance().defaultOutputPath) { + const outputPath = VscodeSettings.getInstance().defaultOutputPath; args.push("--pref", `build.path=${outputPath}`); arduinoChannel.info(`Please see the build logs in Output path: ${outputPath}`); } else { @@ -211,7 +214,10 @@ export class ArduinoApp { Logger.notifyUserError("InvalidOutPutPath", new Error(constants.messages.INVALID_OUTPUT_PATH + outputPath)); return; } - + args.push("--pref", `build.path=${outputPath}`); + arduinoChannel.info(`Please see the build logs in Output path: ${outputPath}`); + } else if (!VscodeSettings.getInstance().defaultOutputPath) { + const outputPath = VscodeSettings.getInstance().defaultOutputPath; args.push("--pref", `build.path=${outputPath}`); arduinoChannel.info(`Please see the build logs in Output path: ${outputPath}`); } else { @@ -273,7 +279,10 @@ export class ArduinoApp { Logger.notifyUserError("InvalidOutPutPath", new Error(constants.messages.INVALID_OUTPUT_PATH + outputPath)); return; } - + args.push("--pref", `build.path=${outputPath}`); + arduinoChannel.info(`Please see the build logs in Output path: ${outputPath}`); + } else if (!VscodeSettings.getInstance().defaultOutputPath) { + const outputPath = VscodeSettings.getInstance().defaultOutputPath; args.push("--pref", `build.path=${outputPath}`); arduinoChannel.info(`Please see the build logs in Output path: ${outputPath}`); } else { @@ -291,7 +300,6 @@ export class ArduinoApp { arduinoChannel.error(`Exit with code=${reason.code}${os.EOL}`); return false; } - } // Add selected library path to the intellisense search path. diff --git a/src/arduino/arduinoSettings.ts b/src/arduino/arduinoSettings.ts index 58419519..bee7ccbd 100644 --- a/src/arduino/arduinoSettings.ts +++ b/src/arduino/arduinoSettings.ts @@ -21,6 +21,7 @@ export interface IArduinoSettings { sketchbookPath: string; preferencePath: string; defaultBaudRate: number; + defaultOutputPath: string; preferences: Map; reloadPreferences(): void; } @@ -35,6 +36,8 @@ export class ArduinoSettings implements IArduinoSettings { private _sketchbookPath: string; private _defaultBaudRate: number; + + private _defaultOutputPath: string; private _preferences: Map; @@ -46,6 +49,7 @@ export class ArduinoSettings implements IArduinoSettings { this._commandPath = VscodeSettings.getInstance().commandPath; await this.tryResolveArduinoPath(); await this.tryGetDefaultBaudRate(); + await this.tryGetDefaultOutputPath(); if (platform === "win32") { await this.updateWindowsPath(); if (this._commandPath === "") { @@ -153,6 +157,10 @@ export class ArduinoSettings implements IArduinoSettings { public get defaultBaudRate() { return this._defaultBaudRate; } + + public get defaultOutputPath(): string { + return this._defaultOutputPath; + } public reloadPreferences() { this._preferences = util.parseConfigFile(this.preferencePath); @@ -227,4 +235,13 @@ export class ArduinoSettings implements IArduinoSettings { this._defaultBaudRate = configValue; } } + + private async tryGetDefaultOutputPath(): Promise { + const configValue = VscodeSettings.getInstance().defaultOutputPath; + if (!configValue || !configValue.trim()) { + this._defaultOutputPath = undefined; + } else { + this._defaultOutputPath = configValue; + } + } } diff --git a/src/arduino/vscodeSettings.ts b/src/arduino/vscodeSettings.ts index a2fce5ab..a028219e 100644 --- a/src/arduino/vscodeSettings.ts +++ b/src/arduino/vscodeSettings.ts @@ -14,6 +14,7 @@ const configKeys = { IGNORE_BOARDS: "arduino.ignoreBoards", SKIP_HEADER_PROVIDER: "arduino.skipHeaderProvider", DEFAULT_BAUD_RATE: "arduino.defaultBaudRate", + DEFAULT_OUTPUT_PATH: "arduino.defaultOutputPath", }; export interface IVscodeSettings { @@ -26,6 +27,7 @@ export interface IVscodeSettings { ignoreBoards: string[]; skipHeaderProvider: boolean; defaultBaudRate: number; + defaultOutputPath: string; updateAdditionalUrls(urls: string | string[]): void; } @@ -76,6 +78,10 @@ export class VscodeSettings implements IVscodeSettings { public get defaultBaudRate(): number { return this.getConfigValue(configKeys.DEFAULT_BAUD_RATE); } + + public get defaultOutputPath(): string { + return this.getConfigValue(configKeys.DEFAULT_OUTPUT_PATH); + } public get skipHeaderProvider(): boolean { return this.getConfigValue(configKeys.SKIP_HEADER_PROVIDER);