Skip to content

Commit fa28358

Browse files
committed
Merge pull request #299 from parallaxinc/reconnect
Automatic Reconnect on USB discovery
2 parents ea942b8 + 878cb13 commit fa28358

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ function onRender(err){
7373
newFile,
7474
showNewVersionOverlay,
7575
changeFile,
76-
changeProject
76+
changeProject,
77+
deviceAdded
7778
} = handlers;
7879

7980
// Finish Loading Plugin
@@ -92,6 +93,10 @@ function onRender(err){
9293
showNewVersionOverlay();
9394
})
9495
.catch(console.error.bind(console));
96+
97+
chrome.usb.onDeviceAdded.addListener(function(){
98+
setTimeout(deviceAdded, 200);
99+
});
95100
}
96101

97102
function onRegister(err){

manifest.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88
"serial",
99
"unlimitedStorage",
1010
"syncFileSystem",
11-
"storage"
11+
"storage",
12+
"usb",
13+
{
14+
"usbDevices": [
15+
{ "vendorId": 1027, "productId": 24577 },
16+
{ "vendorId": 1027, "productId": 24597 }
17+
]
18+
}
1219
],
1320
"icons": {
1421
"16": "icons/icon16.png",

src/plugins/handlers.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,36 @@ function handlers(app, opts, done){
615615
download();
616616
}
617617

618+
function deviceAdded(){
619+
const { device } = store.getState();
620+
621+
const scanOpts = {
622+
reject: [
623+
/Bluetooth-Incoming-Port/,
624+
/Bluetooth-Modem/,
625+
/dev\/cu\./
626+
]
627+
};
628+
629+
app.scanBoards(scanOpts)
630+
.then(function(devices){
631+
store.dispatch(creators.updateDevices(devices));
632+
if(device.selected && device.path && !device.connected && _.some(devices, 'path', device.selected.path)){
633+
var board = app.getBoard(device.selected);
634+
if(board){
635+
board.removeListener('terminal', onTerminal);
636+
board.removeListener('close', onClose);
637+
board.open()
638+
.then(function(){
639+
connect();
640+
board.on('terminal', onTerminal);
641+
board.on('close', onClose);
642+
});
643+
}
644+
}
645+
});
646+
}
647+
618648
function enableAutoDownload(){
619649
store.dispatch(creators.enableAutoDownload());
620650
}
@@ -672,7 +702,8 @@ function handlers(app, opts, done){
672702
download,
673703
toggleEcho,
674704
enableAutoDownload,
675-
disableAutoDownload
705+
disableAutoDownload,
706+
deviceAdded
676707
});
677708

678709
done();

0 commit comments

Comments
 (0)