Socket
Socket
Sign inDemoInstall

node-hid

Package Overview
Dependencies
Maintainers
5
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-hid - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

17

package.json
{
"name": "node-hid",
"description": "USB HID device access library",
"version": "0.7.2",
"version": "0.7.3",
"author": "Hans Hübner <hans.huebner@gmail.com> (https://github.com/hanshuebner)",
"bugs": "https://github.com/node-hid/node-hid/issues",
"homepage": "https://github.com/node-hid/node-hid#readme",
"contributors": [

@@ -21,6 +23,8 @@ "Blake Miner <miner.blake@gmail.com>",

"prebuild-upload": "prebuild --all --strip --verbose --upload",
"prebuild-ci": "prebuild-ci",
"gypclean": "node-gyp clean",
"gypconfigure": "node-gyp configure",
"gypbuild": "node-gyp build",
"clean": "rimraf build node_modules prebuilds",
"gyprebuild": "node-gyp rebuild",
"clean": "rimraf build node_modules prebuilds package-lock.json",
"distclean": "npm run clean && rimraf hidapi"

@@ -38,10 +42,11 @@ },

"bindings": "^1.3.0",
"nan": "^2.6.2",
"prebuild-install": "^2.2.2"
"nan": "^2.10.0",
"prebuild-install": "^4.0.0"
},
"devDependencies": {
"prebuild": "^6.2.2",
"rimraf": "^2.5.3"
"prebuild": "^7.6.0",
"prebuild-ci": "^2.2.3",
"rimraf": "^2.6.2"
},
"gypfile": true
}

@@ -18,2 +18,3 @@ How to publish node-hid

```
npm run clean # clean out directory
npm publish # update npmjs, be sure to have Authy app for OTP code

@@ -27,2 +28,8 @@ ```

#### notes ####
- As of Node v10 on Windows, may need to do:
-- `$env:Path += ";C:\Program Files\Git\mingw64\libexec\git-core
-- and install git with "make unix tools available to windows command prompt"
#### old way ###

@@ -29,0 +36,0 @@

@@ -65,14 +65,14 @@ # node-hid - Access USB HID devices from Node.js #

| Platform / Arch | Node v4.x | Node v6.x | Node v7.x | Node v8.x | Node v9.x |
| --- | --- | --- | --- | --- | --- |
| Windows / x86 | ☑ | ☑ | ☑ | ☑ | ☑ |
| Windows / x64 | ☑ | ☑ | ☑ | ☑ | ☑ |
| Mac OSX / x64 | ☑ | ☑ | ☑ | ☑ | ☑ |
| Linux / x64 | ☑ | ☑ | ☑ | ☑ | ☑ |
| Linux / ia32¹ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / ARM v6¹ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / ARM v7¹ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / ARM v8¹ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / MIPSel¹ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / PPC64¹ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Platform / Arch | Node v4.x | Node v6.x | Node v7.x | Node v8.x | Node v9.x | Node v10.x
| --- | --- | --- | --- | --- | --- | --- |
| Windows / x86 | ☑ | ☑ | ☑ | ☑ | ☑ | ☑ |
| Windows / x64 | ☑ | ☑ | ☑ | ☑ | ☑ | ☑ |
| Mac OSX / x64 | ☑ | ☑ | ☑ | ☑ | ☑ | ☑ |
| Linux / x64 | ☑ | ☑ | ☑ | ☑ | ☑ | ☑ |
| Linux / ia32¹ | ☐ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / ARM v6¹ | ☐ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / ARM v7¹ | ☐ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / ARM v8¹ | ☐ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / MIPSel¹ | ☐ | ☐ | ☐ | ☐ | ☐ | ☐ |
| Linux / PPC64¹ | ☐ | ☐ | ☐ | ☐ | ☐ | ☐ |

@@ -353,14 +353,16 @@ ¹ ia32, ARM, MIPSel and PPC64 platforms are known to work but are not currently part of our test or build matrix. ARM v4 and v5 was dropped from Node.js after Node v0.10.

### Selecting driver type
NOTE: The multi-driver feature is currently disabled. See issue #242.
(NOTE: The multi-driver feature of `HID.setDriverType()` is currently disabled. See issue #242 )
By default as of `node-hid@0.7.0`, the [hidraw](https://www.kernel.org/doc/Documentation/hid/hidraw.txt) driver is used to talk to HID devices. Before `node-hid@0.7.0`, the more older but less capable [libusb](http://libusb.info/) driver was used. With `hidraw` Linux apps can now see `usage` and `usagePage` attributes of devices.
If your kernel does not support `hidraw`) or if you would like to be explicit, you can set the driverType by hand:
```js
var HID = require('node-hid');
HID.setDriverType('libusb'); // or 'hidraw'
console.log(HID.devices());
If you would still like to use the `libusb` driver, then you can do either:
```
See [`show-devices.js`](./src/show-devices.js) for an example where you can
choose driverType on the command-line.
npm install node-hid@0.5.7
```
or:
```
npm install node-hid --build-from-source --driver=libusb
```
### udev device permissions

@@ -372,11 +374,20 @@ Most Linux distros use `udev` to manage access to physical devices,

This rule is a file, placed in `/etc/udev/rules.d`, with the lines:
This rule is a text file placed in `/etc/udev/rules.d`.
For an example HID device (say a blink(1) light with vendorId = 0x27b8 and productId = 0x01ed,
the rules file to support both `hidraw` and `libusb` would look like:
```
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="27b8", ATTRS{idProduct}=="01ed", MODE:="666", GROUP="plugdev"
KERNEL=="hidraw*", ATTRS{idVendor}=="27b8", ATTRS{idProduct}=="01ed", MODE="0666", GROUP="plugdev"
```
(the above is for vendorId = 27b8, productId = 01ed)
Note that the values for idVendor and idProduct must be in hex and lower-case.
Then the udev service is reloaded with: `sudo udevadm control --reload-rules`
For an example, see the
Save this file as `/etc/udev/rules.d/51-blink1.rules`, unplug the HID device,
and reload the rules with:
```
sudo udevadm control --reload-rules
```
For a complete example, see the
[blink1 udev rules](https://github.com/todbot/blink1/blob/master/linux/51-blink1.rules).

@@ -442,3 +453,3 @@

npm run gypconfigure # "node-gyp configure" configure makefiles
npm run gypcompile # "node-gyp build" build native code
npm run gypbuild # "node-gyp build" build native code
```

@@ -463,2 +474,10 @@

If using `node-hid` with `webpack`, you may find it useful to list `node-hid` as an external in your `webpack-config.js`:
```
externals: {
"node-hid": 'commonjs node-hid'
}
```
(You can see an example of this in [Blink1Control2](https://github.com/todbot/Blink1Control2/)'s [webpack-config.js](https://github.com/todbot/Blink1Control2/blob/master/webpack.config.js)
## Using `node-hid` in NW.js projects

@@ -465,0 +484,0 @@ (TBD)

@@ -0,1 +1,3 @@

#!/usr/bin/env node
var HID = require('../');

@@ -2,0 +4,0 @@

@@ -6,2 +6,4 @@ /**

'use strict';
var HID = require('../');

@@ -14,2 +16,4 @@

var serial_number = process.argv[2];
var devices_found = HID.devices( VENDOR_ID, PRODUCT_ID );

@@ -23,3 +27,15 @@

var hidDevice = new HID.HID( VENDOR_ID, PRODUCT_ID );
var hidDevice;
try {
if( serial_number ) {
console.log("opening serial number "+serial_number);
hidDevice = new HID.HID( VENDOR_ID, PRODUCT_ID, serial_number );
} else {
console.log("opening first device");
hidDevice = new HID.HID( VENDOR_ID, PRODUCT_ID );
}
} catch(err) {
console.log(err);
process.exit(1);
}

@@ -26,0 +42,0 @@ var deviceInfo = hidDevice.getDeviceInfo();

@@ -19,9 +19,26 @@ //

// We must filter devices by vendorId, productId, usagePage, and usage
// because Teensy RawHID sketch shows up as TWO devices to node-hid / hidapi
var deviceInfo = devices.find( function(d) {
var isTeensy = d.vendorId===0x16C0 && d.productId===0x0486;
return isTeensy && d.usagePage===0xFFAB && d.usage===0x200;
});
// because Teensy RawHID sketch shows up as TWO devices to node-hid
// Note this only works on Mac & Windows though as the underlying
// hidapi C library doesn't support usagePage on libusb or hidraw
var isTeensy = function(d) { return d.vendorId===0x16C0 && d.productId===0x0486;}
var isRawHidUsage = function(d) { return d.usagePage===0xFFAB && d.usage===0x2000; }
var device;
if( os.platform() == 'linux' ) {
var deviceList = devices.filter(function(d) { return isTeensy(d) });
//console.log("deviceList:",deviceList); // should be two devices
if( deviceList.length == 2 ) {
device = new HID.HID( deviceList[0].path ); // normally first device
}
}
else { // Mac & Windows
var deviceInfo = devices.find( function(d) {
return isTeensy(d) && isRawHidUsage(d);
});
device = new HID.HID( deviceInfo.path );
}
console.log("deviceInfo: ", deviceInfo);
if( !deviceInfo ) {
if( !device ) {
console.log(devices);

@@ -32,4 +49,2 @@ console.log("Could not find RawHID device in device list");

var device = new HID.HID( deviceInfo.path );
device.on('data', function(data) {

@@ -67,5 +82,5 @@ console.log("got data:",data);

console.log("waiting 5 seconds for data from Teensy");
console.log("waiting 10 seconds for data from Teensy");
setTimeout( function() {
device.close();
}, 5000);
}, 10000);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc