Skip to content

Commit dc09a0a

Browse files
author
Stefania
authored
Merge pull request #104 from arduino/1200bps-touch
set the board in bootloader mode touching it at 1200 bps
2 parents a627da5 + c35b59d commit dc09a0a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

demo/app.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ const handleUpload = () => {
4444
daemon.uploadSerial(target, 'serial_mirror', { bin: HEX });
4545
};
4646

47+
const handleBootloaderMode = (e, port) => {
48+
e.preventDefault();
49+
daemon.setBootloaderMode(port);
50+
};
51+
4752
const handleDownloadTool = e => {
4853
e.preventDefault();
4954
const toolname = document.getElementById('toolname');
@@ -171,6 +176,8 @@ class App extends React.Component {
171176
open
172177
</a> - <a href="#" onClick={(e) => this.handleClose(e, device.Name)}>
173178
close
179+
</a> - <a href="#" onClick={(e) => handleBootloaderMode(e, device.Name)}>
180+
bootloader mode
174181
</a>
175182
</li>);
176183

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arduino-create-agent-js-client",
3-
"version": "2.1.9",
3+
"version": "2.1.10",
44
"description": "JS module providing discovery of the Arduino Create Plugin and communication with it",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/daemon.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
*
1919
*/
2020

21-
import { Subject, BehaviorSubject, interval } from 'rxjs';
22-
import { takeUntil, filter, startWith, first, distinctUntilChanged } from 'rxjs/operators';
21+
import {
22+
Subject, BehaviorSubject, interval, timer
23+
} from 'rxjs';
24+
import {
25+
takeUntil, filter, startWith, first, distinctUntilChanged
26+
} from 'rxjs/operators';
2327

2428
const POLLING_INTERVAL = 1500;
2529

@@ -161,4 +165,16 @@ export default class Daemon {
161165
throw new Error('Stop Upload not supported on Chrome OS');
162166
}
163167
}
168+
169+
/**
170+
* Set the board in bootloader mode. This is needed to bo 100% sure to receive the correct vid/pid from the board.
171+
* To do that we just touch the port at 1200 bps and then close it. The sketch on the board will be erased.
172+
* @param {String} port the port name
173+
*/
174+
setBootloaderMode(port) {
175+
this.serialMonitorOpened.pipe(filter(open => open)).pipe(first()).subscribe(() => {
176+
timer(1000).subscribe(() => this.closeSerialMonitor(port));
177+
});
178+
this.openSerialMonitor(port, 1200);
179+
}
164180
}

0 commit comments

Comments
 (0)