From e0e003fa74a74a1db766ece968e5266cc0687478 Mon Sep 17 00:00:00 2001 From: Arturo Serna Leon Date: Fri, 7 Jul 2017 13:27:50 +0200 Subject: [PATCH 1/7] Add uploadPort memberto DeviceContext --- src/deviceContext.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/deviceContext.ts b/src/deviceContext.ts index 400708c0..79a86816 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -21,6 +21,12 @@ export interface IDeviceContext { */ port: string; + /** + * Upload Port. Defaults to COM port. It can be an IP address. + * @property {string} + */ + uploadPort: string; + /** * Current selected Arduino board alias. * @property {string} @@ -67,6 +73,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { private _port: string; + private _uploadPort: string; + private _board: string; private _sketch: string; @@ -130,6 +138,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; this._board = deviceConfigJson.board; this._sketch = deviceConfigJson.sketch; this._configuration = deviceConfigJson.configuration; @@ -141,6 +150,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { } } else { this._port = null; + this._uploadPort = null; this._board = null; this._sketch = null; this._configuration = null; @@ -167,6 +177,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_; @@ -194,6 +205,15 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { this.saveContext(); } + public get uploadPort() { + return this._uploadPort || this.port; + } + + public set uploadPort(value: string) { + this._uploadPort = value; + this.saveContext(); + } + public get board() { return this._board; } From 70a8567eedb99206453a830ecae175a5c92ad683 Mon Sep 17 00:00:00 2001 From: Arturo Serna Leon Date: Fri, 7 Jul 2017 13:50:37 +0200 Subject: [PATCH 2/7] Use uploadPort instead of port in upload. --- src/arduino/arduino.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 4cfcb32c..3ba8cbb0 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -103,7 +103,7 @@ export class ArduinoApp { if (!dc.sketch || !util.fileExistsSync(path.join(vscode.workspace.rootPath, dc.sketch))) { await this.getMainSketch(dc); } - if (!dc.port) { + if (!dc.uploadPort) { vscode.window.showErrorMessage("Please specify the upload serial port."); return; } @@ -111,13 +111,17 @@ export class ArduinoApp { 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); await vscode.workspace.saveAll(false); const appPath = path.join(vscode.workspace.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"); } From 23922103c46d7a821f22a350463da0107b0e1418 Mon Sep 17 00:00:00 2001 From: Arturo Serna Leon Date: Fri, 7 Jul 2017 13:57:54 +0200 Subject: [PATCH 3/7] Test. When uploadPort is not defined value is port. --- test/devicecontext.test.ts | 1 + 1 file changed, 1 insertion(+) 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); From 742f93bb9eb1c1e50b8af625373f91e87d8cf8e6 Mon Sep 17 00:00:00 2001 From: Arturo Serna Leon Date: Fri, 7 Jul 2017 15:26:54 +0200 Subject: [PATCH 4/7] set uploadPort in loadContext method --- src/arduino/arduino.ts | 2 +- src/deviceContext.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 3ba8cbb0..d55b6770 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -104,7 +104,7 @@ export class ArduinoApp { await this.getMainSketch(dc); } if (!dc.uploadPort) { - vscode.window.showErrorMessage("Please specify the upload serial port."); + vscode.window.showErrorMessage("Please specify the upload port."); return; } diff --git a/src/deviceContext.ts b/src/deviceContext.ts index 79a86816..27b76032 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -138,7 +138,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; + this._uploadPort = deviceConfigJson.uploadPort || deviceConfigJson.port; this._board = deviceConfigJson.board; this._sketch = deviceConfigJson.sketch; this._configuration = deviceConfigJson.configuration; @@ -206,7 +206,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { } public get uploadPort() { - return this._uploadPort || this.port; + return this._uploadPort; } public set uploadPort(value: string) { From 472b1f47b3313238d471c895b15be295983677bb Mon Sep 17 00:00:00 2001 From: Arturo Serna Leon Date: Fri, 7 Jul 2017 16:04:18 +0200 Subject: [PATCH 5/7] Improve comment --- src/deviceContext.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/deviceContext.ts b/src/deviceContext.ts index 27b76032..ba0db0d1 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -22,7 +22,9 @@ export interface IDeviceContext { port: string; /** - * Upload Port. Defaults to COM port. It can be an IP address. + * 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; From ef281024811be3a3d9e83066264b193367c32141 Mon Sep 17 00:00:00 2001 From: Arturo Date: Sun, 9 Jul 2017 12:24:34 +0200 Subject: [PATCH 6/7] Add uploadPort to schema --- misc/arduinoValidator.json | 5 +++++ 1 file changed, 5 insertions(+) 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", From f4102e54090ee74af3aab167f96d39be59659167 Mon Sep 17 00:00:00 2001 From: Arturo Date: Sun, 9 Jul 2017 12:39:12 +0200 Subject: [PATCH 7/7] Remove trailing whitespace --- src/deviceContext.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deviceContext.ts b/src/deviceContext.ts index ba0db0d1..747f7a37 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -22,7 +22,7 @@ export interface IDeviceContext { port: string; /** - * Port used for uploading the skecth. + * 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}