Skip to content

Commit 26d03c3

Browse files
author
Alberto Iannaccone
committed
set the board in bootloader mode touching it at 1200 bps
1 parent a627da5 commit 26d03c3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

demo/app.jsx

Lines changed: 7 additions & 0 deletions
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

src/daemon.js

Lines changed: 18 additions & 2 deletions
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)