Skip to content

set the board in bootloader mode touching it at 1200 bps #104

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 2 commits into from
Mar 27, 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
7 changes: 7 additions & 0 deletions demo/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const handleUpload = () => {
daemon.uploadSerial(target, 'serial_mirror', { bin: HEX });
};

const handleBootloaderMode = (e, port) => {
e.preventDefault();
daemon.setBootloaderMode(port);
};

const handleDownloadTool = e => {
e.preventDefault();
const toolname = document.getElementById('toolname');
Expand Down Expand Up @@ -171,6 +176,8 @@ class App extends React.Component {
open
</a> - <a href="#" onClick={(e) => this.handleClose(e, device.Name)}>
close
</a> - <a href="#" onClick={(e) => handleBootloaderMode(e, device.Name)}>
bootloader mode
</a>
</li>);

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.1.9",
"version": "2.1.10",
"description": "JS module providing discovery of the Arduino Create Plugin and communication with it",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
20 changes: 18 additions & 2 deletions src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
*
*/

import { Subject, BehaviorSubject, interval } from 'rxjs';
import { takeUntil, filter, startWith, first, distinctUntilChanged } from 'rxjs/operators';
import {
Subject, BehaviorSubject, interval, timer
} from 'rxjs';
import {
takeUntil, filter, startWith, first, distinctUntilChanged
} from 'rxjs/operators';

const POLLING_INTERVAL = 1500;

Expand Down Expand Up @@ -161,4 +165,16 @@ export default class Daemon {
throw new Error('Stop Upload not supported on Chrome OS');
}
}

/**
* Set the board in bootloader mode. This is needed to bo 100% sure to receive the correct vid/pid from the board.
* To do that we just touch the port at 1200 bps and then close it. The sketch on the board will be erased.
* @param {String} port the port name
*/
setBootloaderMode(port) {
this.serialMonitorOpened.pipe(filter(open => open)).pipe(first()).subscribe(() => {
timer(1000).subscribe(() => this.closeSerialMonitor(port));
});
this.openSerialMonitor(port, 1200);
}
}