Skip to content

fix bug about board reapping on different ports after upload #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions demo/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -98,14 +87,16 @@ class App extends React.Component {
downloadStatus: '',
downloadError: '',
serialInput: '',
supportedBoards: []
supportedBoards: [],
uploadingPort: ''
};
this.handleOpen = this.handleOpen.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleSend = this.handleSend.bind(this);
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() {
Expand Down Expand Up @@ -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) => <li key={i}>
{device.Name} - IsOpen: <span className={device.IsOpen ? 'open' : 'closed'}>
Expand Down Expand Up @@ -306,8 +315,9 @@ class App extends React.Component {

<div className="section">
<h2>Upload a sample sketch on a MKR1000 at /dev/ttyACM0</h2>
<button onClick={ handleUpload } disabled={ this.state.uploadStatus === daemon.UPLOAD_IN_PROGRESS }>Upload Sketch</button><br/>
<button onClick={ this.handleUpload } disabled={ this.state.uploadStatus === daemon.UPLOAD_IN_PROGRESS }>Upload Sketch</button><br/>
<div>Upload status: <span className={ uploadClass }> { this.state.uploadStatus }</span> <span>{ this.state.uploadError }</span></div>
<div>Uploading port: { this.state.uploadingPort || '-' }</div>
</div>

{ daemon.downloading ? <div className="section">
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
32 changes: 31 additions & 1 deletion src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);
});
}
Expand Down