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

add default output path #655

Closed
wants to merge 11 commits into from
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<username>/Downloads/arduino-1.8.1` for Linux. (Requires a restart after change). The default value is automatically detected from your Arduino IDE installation path.
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@
"arduino.defaultBaudRate": {
"type": "number",
"default": 115200
},
"arduino.defaultOutputPath": {
"type": "string",
"default": ""
}
}
},
Expand Down
16 changes: 12 additions & 4 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/arduino/arduinoSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IArduinoSettings {
sketchbookPath: string;
preferencePath: string;
defaultBaudRate: number;
defaultOutputPath: string;
preferences: Map<string, string>;
reloadPreferences(): void;
}
Expand All @@ -35,6 +36,8 @@ export class ArduinoSettings implements IArduinoSettings {
private _sketchbookPath: string;

private _defaultBaudRate: number;

private _defaultOutputPath: string;

private _preferences: Map<string, string>;

Expand All @@ -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 === "") {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -227,4 +235,13 @@ export class ArduinoSettings implements IArduinoSettings {
this._defaultBaudRate = configValue;
}
}

private async tryGetDefaultOutputPath(): Promise<void> {
const configValue = VscodeSettings.getInstance().defaultOutputPath;
if (!configValue || !configValue.trim()) {
this._defaultOutputPath = undefined;
} else {
this._defaultOutputPath = configValue;
}
}
}
6 changes: 6 additions & 0 deletions src/arduino/vscodeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,6 +27,7 @@ export interface IVscodeSettings {
ignoreBoards: string[];
skipHeaderProvider: boolean;
defaultBaudRate: number;
defaultOutputPath: string;
updateAdditionalUrls(urls: string | string[]): void;
}

Expand Down Expand Up @@ -76,6 +78,10 @@ export class VscodeSettings implements IVscodeSettings {
public get defaultBaudRate(): number {
return this.getConfigValue<number>(configKeys.DEFAULT_BAUD_RATE);
}

public get defaultOutputPath(): string {
return this.getConfigValue<string>(configKeys.DEFAULT_OUTPUT_PATH);
}

public get skipHeaderProvider(): boolean {
return this.getConfigValue<boolean>(configKeys.SKIP_HEADER_PROVIDER);
Expand Down