diff --git a/misc/arduinoValidator.json b/misc/arduinoValidator.json index 73baff4f..df08d571 100644 --- a/misc/arduinoValidator.json +++ b/misc/arduinoValidator.json @@ -13,6 +13,11 @@ "type": "string", "minLength": 1 }, + "uploadPort": { + "description": "Upload port", + "type": "string", + "minLength": 1 + }, "board": { "description": "Arduino board type", "type": "string", diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 9354ade9..ef9c6461 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -108,17 +108,21 @@ export class ArduinoApp { if (!dc.sketch || !util.fileExistsSync(path.join(ArduinoWorkspace.rootPath, dc.sketch))) { await this.getMainSketch(dc); } - if (!dc.port) { - vscode.window.showErrorMessage("Please specify the upload serial port."); + if (!dc.uploadPort) { + vscode.window.showErrorMessage("Please specify the upload port."); return; } arduinoChannel.show(); arduinoChannel.start(`Upload sketch - ${dc.sketch}`); - const serialMonitor = SerialMonitor.getInstance(); + let serialMonitor; + let needRestore = false; + if (dc.port === dc.uploadPort) { + serialMonitor = SerialMonitor.getInstance(); + needRestore = await serialMonitor.closeSerialMonitor(dc.port); + } - const needRestore = await serialMonitor.closeSerialMonitor(dc.port); UsbDetector.getInstance().pauseListening(); await vscode.workspace.saveAll(false); @@ -135,7 +139,8 @@ export class ArduinoApp { } const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch); - const args = ["--upload", "--board", boardDescriptor, "--port", dc.port, appPath]; + const args = ["--upload", "--board", boardDescriptor, "--port", dc.uploadPort, appPath]; + if (VscodeSettings.getInstance().logLevel === "verbose") { args.push("--verbose"); } diff --git a/src/deviceContext.ts b/src/deviceContext.ts index 010cade8..8ad80eac 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -22,6 +22,14 @@ export interface IDeviceContext { */ port: string; + /** + * Port used for uploading the skecth. + * It can be a COM port or an IP address (OTA) + * If undefined, it uses port value. + * @property {string} + */ + uploadPort: string; + /** * Current selected Arduino board alias. * @property {string} @@ -68,6 +76,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { private _port: string; + private _uploadPort: string; + private _board: string; private _sketch: string; @@ -138,6 +148,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { deviceConfigJson = util.tryParseJSON(fs.readFileSync(configFile.fsPath, "utf8")); if (deviceConfigJson) { this._port = deviceConfigJson.port; + this._uploadPort = deviceConfigJson.uploadPort || deviceConfigJson.port; this._board = deviceConfigJson.board; this._sketch = deviceConfigJson.sketch; this._configuration = deviceConfigJson.configuration; @@ -150,6 +161,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { } } else { this._port = null; + this._uploadPort = null; this._board = null; this._sketch = null; this._configuration = null; @@ -203,6 +215,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { } deviceConfigJson.sketch = this.sketch; deviceConfigJson.port = this.port; + deviceConfigJson.uploadPort = this.uploadPort; deviceConfigJson.board = this.board; deviceConfigJson.output = this.output; deviceConfigJson["debugger"] = this.debugger_; @@ -230,6 +243,15 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { this.saveContext(); } + public get uploadPort() { + return this._uploadPort; + } + + public set uploadPort(value: string) { + this._uploadPort = value; + this.saveContext(); + } + public get board() { return this._board; } diff --git a/test/devicecontext.test.ts b/test/devicecontext.test.ts index fac14055..21865a42 100644 --- a/test/devicecontext.test.ts +++ b/test/devicecontext.test.ts @@ -13,6 +13,7 @@ suite("Arduino: Device Context config", () => { deviceContext.loadContext().then(() => { assert.equal(deviceContext.board, "arduino:avr:diecimila"); assert.equal(deviceContext.port, "COM4"); + assert.equal(deviceContext.uploadPort, "COM4"); assert.equal(deviceContext.sketch, "blink.ino"); assert.equal(deviceContext.configuration, "cpu=atmega328"); assert.equal(deviceContext.output, null);