diff options
| author | Timon Skerutsch <[email protected]> | 2019-05-29 15:50:45 +0200 |
|---|---|---|
| committer | Timon Skerutsch <[email protected]> | 2019-05-29 15:50:45 +0200 |
| commit | 9c85396758128d2f80b0f5609bb03e8e8f7e8441 (patch) | |
| tree | 4c1c024f4ab9e779c1e6fc4d96b879d6bcddec96 | |
| parent | dc601ab5181957515decb4c3a5fc58d0c14d1b38 (diff) | |
Modified example to use list of supported boards
| -rw-r--r-- | examples/device/hid_generic_inout/boards.js | 4 | ||||
| -rw-r--r-- | examples/device/hid_generic_inout/hid_test.js | 34 |
2 files changed, 23 insertions, 15 deletions
diff --git a/examples/device/hid_generic_inout/boards.js b/examples/device/hid_generic_inout/boards.js new file mode 100644 index 000000000..e8437cf53 --- /dev/null +++ b/examples/device/hid_generic_inout/boards.js @@ -0,0 +1,4 @@ +module.exports = { + "Feather_nRF52840":[0X239A,0X8029], + "Metro_nRF52840":[0X239A,0X803F], +}
\ No newline at end of file diff --git a/examples/device/hid_generic_inout/hid_test.js b/examples/device/hid_generic_inout/hid_test.js index ef627c7ae..eed6b78e2 100644 --- a/examples/device/hid_generic_inout/hid_test.js +++ b/examples/device/hid_generic_inout/hid_test.js @@ -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 var HID = require('node-hid'); var os = require('os') +// list of supported devices +var boards = require('./boards.js') var isWin = (os.platform() === 'win32'); var devices = HID.devices(); -// choose either of the following supported devices: -// Metro_nRF52840, Feather_nRF52840 - -var deviceInfo = devices.find(Feather_nRF52840); +// this will choose any device found in the boards.js file +var deviceInfo = devices.find(anySupportedBoard); var reportLen = 64; var message = "Hello World!" @@ -51,17 +51,21 @@ if( deviceInfo ) { } - - -function Feather_nRF52840(d) { - return isDevice(0X239A,0X8029,d) +function anySupportedBoard(d) { + + for (var key in boards) { + if (boards.hasOwnProperty(key)) { + if (isDevice(boards[key],d)) { + console.log("Found " + d.product); + return true; + } + } + } + return false; } -function Metro_nRF52840(d) { - return isDevice(0X239A,0X803F,d) -} +function isDevice(board,d){ + return d.vendorId==board[0] && d.productId==board[1]; +} -function isDevice(vid,pid,d){ - return d.vendorId==vid && d.productId==pid; -}
\ No newline at end of file |
