diff --git a/demo/app.jsx b/demo/app.jsx index 5daa479d..7a906b7b 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,24 @@ 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.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) =>
  • {device.Name} - IsOpen: @@ -306,8 +315,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/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", diff --git a/src/daemon.js b/src/daemon.js index 733c4a6e..64e404bf 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -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.boardPortAfterUpload = new Subject().pipe(first()); + 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,31 @@ 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.boardPortAfterUpload.next({ + hasChanged: true, + newPort: this.uploadingPort + }); + } + } + + if (boardFound) { + this.waitingForPortToComeUp.unsubscribe(); + this.uploadingPort = null; + this.serialDevicesBeforeUpload = null; + this.boardPortAfterUpload.next({ + hasChanged: false + }); + } + }); + }); this._upload(uploadPayload, uploadCommandInfo); }); }