Modified example to use list of supported boards
This commit is contained in:
parent
dc601ab518
commit
9c85396758
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = {
|
||||||
|
"Feather_nRF52840":[0X239A,0X8029],
|
||||||
|
"Metro_nRF52840":[0X239A,0X803F],
|
||||||
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
// IMPORTANT: install dependency via 'npm i node-hid' in the same location as the script
|
// IMPORTANT: install the dependency via 'npm i node-hid' in the same location as the script
|
||||||
// If the install fails on windows you may need to run 'npm i -g windows-build-tools' first to be able to compile native code needed for this library
|
// If the install fails on windows you may need to run 'npm i -g windows-build-tools' first to be able to compile native code needed for this library
|
||||||
|
|
||||||
var HID = require('node-hid');
|
var HID = require('node-hid');
|
||||||
var os = require('os')
|
var os = require('os')
|
||||||
|
// list of supported devices
|
||||||
|
var boards = require('./boards.js')
|
||||||
|
|
||||||
var isWin = (os.platform() === 'win32');
|
var isWin = (os.platform() === 'win32');
|
||||||
var devices = HID.devices();
|
var devices = HID.devices();
|
||||||
|
|
||||||
// choose either of the following supported devices:
|
// this will choose any device found in the boards.js file
|
||||||
// Metro_nRF52840, Feather_nRF52840
|
var deviceInfo = devices.find(anySupportedBoard);
|
||||||
|
|
||||||
var deviceInfo = devices.find(Feather_nRF52840);
|
|
||||||
var reportLen = 64;
|
var reportLen = 64;
|
||||||
|
|
||||||
var message = "Hello World!"
|
var message = "Hello World!"
|
||||||
|
@ -51,17 +51,21 @@ if( deviceInfo ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function anySupportedBoard(d) {
|
||||||
|
|
||||||
function Feather_nRF52840(d) {
|
for (var key in boards) {
|
||||||
return isDevice(0X239A,0X8029,d)
|
if (boards.hasOwnProperty(key)) {
|
||||||
}
|
if (isDevice(boards[key],d)) {
|
||||||
|
console.log("Found " + d.product);
|
||||||
function Metro_nRF52840(d) {
|
return true;
|
||||||
return isDevice(0X239A,0X803F,d)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isDevice(vid,pid,d){
|
function isDevice(board,d){
|
||||||
return d.vendorId==vid && d.productId==pid;
|
return d.vendorId==board[0] && d.productId==board[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue