From 5b9a238f984d3f9ec8682bcd5f9b2f6a4a2f8c9d Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Fri, 2 Aug 2019 14:58:20 +0200 Subject: [PATCH 1/3] fix bug about board reapping on different ports after upload --- demo/app.jsx | 32 +++++++++++++++++++------------- src/daemon.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/demo/app.jsx b/demo/app.jsx index 5daa479d..2e59a0ff 100644 --- a/demo/app.jsx +++ b/demo/app.jsx @@ -36,17 +36,6 @@ const scrollToBottom = (target) => { const daemon = new Daemon('https://builder.arduino.cc/v3/boards', chromeExtensionID); const firmwareUpdater = new FirmwareUpdater(daemon); -const handleUpload = () => { - const target = { - board: 'arduino:samd:mkr1000', - port: '/dev/ttyACM0', - network: false - }; - - // Upload a compiled sketch. - daemon.uploadSerial(target, 'serial_mirror', { bin: HEX }); -}; - const handleBootloaderMode = (e, port) => { e.preventDefault(); daemon.setBootloaderMode(port); @@ -98,7 +87,8 @@ class App extends React.Component { downloadStatus: '', downloadError: '', serialInput: '', - supportedBoards: [] + supportedBoards: [], + uploadingPort: '' }; this.handleOpen = this.handleOpen.bind(this); this.handleClose = this.handleClose.bind(this); @@ -106,6 +96,7 @@ class App extends React.Component { this.handleChangeSerial = this.handleChangeSerial.bind(this); this.showError = this.showError.bind(this); this.clearError = this.clearError.bind(this); + this.handleUpload = this.handleUpload.bind(this); } componentDidMount() { @@ -191,6 +182,20 @@ class App extends React.Component { this.setState({ serialInput: '' }); } + handleUpload() { + const target = { + board: 'arduino:samd:mkr1000', + port: '/dev/ttyACM1', + network: false + }; + + this.setState({ uploadingPort: target.port }); + daemon.uploadingPortChanged.subscribe(newPort => this.setState({ uploadingPort: newPort })); + + // Upload a compiled sketch. + daemon.uploadSerial(target, 'serial_mirror', { bin: HEX }); + }; + render() { const listSerialDevices = this.state.serialDevices.map((device, i) =>
  • {device.Name} - IsOpen: @@ -306,8 +311,9 @@ class App extends React.Component {

    Upload a sample sketch on a MKR1000 at /dev/ttyACM0

    -
    +
    Upload status: { this.state.uploadStatus } { this.state.uploadError }
    +
    Uploading port: { this.state.uploadingPort || '-' }
    { daemon.downloading ?
    diff --git a/src/daemon.js b/src/daemon.js index 733c4a6e..0af522ea 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -19,7 +19,7 @@ */ import { - Subject, BehaviorSubject, interval, timer + Subject, BehaviorSubject, interval, timer, UnsubscriptionError } from 'rxjs'; import { takeUntil, filter, startWith, first, distinctUntilChanged @@ -79,6 +79,9 @@ export default class Daemon { this.downloadingError = this.downloading.pipe(filter(download => download.status === this.DOWNLOAD_ERROR)) .pipe(first()) .pipe(takeUntil(this.downloadingDone)); + + this.uploadingPortChanged = new Subject(); + this.uploadingPort = null; } notifyUploadError(err) { @@ -113,7 +116,9 @@ export default class Daemon { * @param {boolean} verbose */ uploadSerial(target, sketchName, compilationResult, verbose = true) { - this.uploading.next({ status: this.UPLOAD_IN_PROGRESS }); + this.uploadingPort = target.port; + this.uploading.next({ status: this.UPLOAD_IN_PROGRESS, msg: 'Upload started' }); + this.serialDevicesBeforeUpload = this.devicesList.getValue().serial; this.closeSerialMonitor(target.port); @@ -139,6 +144,25 @@ export default class Daemon { data: compilationResult[ext] // For chromeOS plugin, consider to align this }; + this.uploadingDone.subscribe(() => { + this.waitingForPortToComeUp = timer(1000).subscribe(() => { + const currentSerialDevices = this.devicesList.getValue().serial; + let boardFound = currentSerialDevices.find(device => device.Name === this.uploadingPort); + if (!boardFound) { + boardFound = currentSerialDevices.find(d => this.serialDevicesBeforeUpload.every(e => e.Name !== d.Name)); + if (boardFound) { + this.uploadingPort = boardFound.Name; + this.uploadingPortChanged.next(this.uploadingPort) + } + } + + if (boardFound) { + this.waitingForPortToComeUp.unsubscribe(); + this.uploadingPort = null; + this.serialDevicesBeforeUpload = null; + } + }) + }) this._upload(uploadPayload, uploadCommandInfo); }); } From f09f469da21810a611679ee5608e48e181360675 Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Fri, 2 Aug 2019 15:47:51 +0200 Subject: [PATCH 2/3] avoid multiple subscription when port changes after upload --- demo/app.jsx | 8 ++++++-- src/daemon.js | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/demo/app.jsx b/demo/app.jsx index 2e59a0ff..7a906b7b 100644 --- a/demo/app.jsx +++ b/demo/app.jsx @@ -190,11 +190,15 @@ class App extends React.Component { }; this.setState({ uploadingPort: target.port }); - daemon.uploadingPortChanged.subscribe(newPort => this.setState({ uploadingPort: newPort })); + daemon.boardPortAfterUpload.subscribe(portStatus => { + if (portStatus.hasChanged) { + this.setState({ uploadingPort: portStatus.newPort }); + } + }); // Upload a compiled sketch. daemon.uploadSerial(target, 'serial_mirror', { bin: HEX }); - }; + } render() { const listSerialDevices = this.state.serialDevices.map((device, i) =>
  • diff --git a/src/daemon.js b/src/daemon.js index 0af522ea..64e404bf 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -19,7 +19,7 @@ */ import { - Subject, BehaviorSubject, interval, timer, UnsubscriptionError + Subject, BehaviorSubject, interval, timer } from 'rxjs'; import { takeUntil, filter, startWith, first, distinctUntilChanged @@ -80,7 +80,7 @@ export default class Daemon { .pipe(first()) .pipe(takeUntil(this.downloadingDone)); - this.uploadingPortChanged = new Subject(); + this.boardPortAfterUpload = new Subject().pipe(first()); this.uploadingPort = null; } @@ -152,7 +152,10 @@ export default class Daemon { boardFound = currentSerialDevices.find(d => this.serialDevicesBeforeUpload.every(e => e.Name !== d.Name)); if (boardFound) { this.uploadingPort = boardFound.Name; - this.uploadingPortChanged.next(this.uploadingPort) + this.boardPortAfterUpload.next({ + hasChanged: true, + newPort: this.uploadingPort + }); } } @@ -160,9 +163,12 @@ export default class Daemon { this.waitingForPortToComeUp.unsubscribe(); this.uploadingPort = null; this.serialDevicesBeforeUpload = null; + this.boardPortAfterUpload.next({ + hasChanged: false + }); } - }) - }) + }); + }); this._upload(uploadPayload, uploadCommandInfo); }); } From c404d5991f4b3cbab3da959220fed3d879e4a37a Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Mon, 5 Aug 2019 10:38:04 +0200 Subject: [PATCH 3/3] 2.3.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 94bd26f9..f060cb92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.3.0", + "version": "2.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 013c4fe7..d24fba35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.3.0", + "version": "2.3.1", "description": "JS module providing discovery of the Arduino Create Plugin and communication with it", "main": "lib/index.js", "module": "es/index.js",