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.9 to 1.0.0

hidapi/.appveyor.yml

4

hidapi/AUTHORS.txt

@@ -13,5 +13,7 @@

libusb/hidapi Team:
Development/maintainance since June 4th 2019
For a comprehensive list of contributions, see the commit list at github:
http://github.com/signal11/hidapi/commits/master
https://github.com/libusb/hidapi/commits/master
{
"name": "node-hid",
"description": "USB HID device access library",
"version": "0.7.9",
"version": "1.0.0",
"author": "Hans Hübner <hans.huebner@gmail.com> (https://github.com/hanshuebner)",

@@ -19,3 +19,3 @@ "bugs": "https://github.com/node-hid/node-hid/issues",

"showdevices": "node src/show-devices.js",
"prepublish": "git submodule update --init",
"prepublishOnly": "git submodule update --init",
"install": "prebuild-install || node-gyp rebuild",

@@ -42,9 +42,7 @@ "prebuild": "prebuild --all --verbose --include-regex \"HID.*node$\"",

"bindings": "^1.5.0",
"nan": "^2.13.2",
"prebuild-install": "^5.3.0"
"nan": "^2.14.0",
"prebuild-install": "^5.3.3"
},
"devDependencies": {
"node-abi": "^2.8.0",
"prebuild": "^8.2.1",
"prebuild-ci": "^2.3.0",
"prebuild": "^9.1.1",
"rimraf": "^2.6.2"

@@ -51,0 +49,0 @@ },

@@ -27,3 +27,3 @@ # node-hid - Access USB HID devices from Node.js #

* [device.on('data', function(data) {} )](#deviceondata-functiondata--)
* [device.on('error, function(error) {} )](#deviceonerror-functionerror--)
* [device.on('error', function(error) {} )](#deviceonerror-functionerror--)
* [device.write(data)](#devicewritedata)

@@ -38,2 +38,3 @@ * [device.close()](#deviceclose)

* [device.getFeatureReport(report_id, report_length)](#devicegetfeaturereportreport_id-report_length)
* [device.setNonBlocking(no_block)](#devicesetnonblockingno_block)
* [Windows notes](#windows-notes)

@@ -63,3 +64,3 @@ * [Mice and keyboards](#mice-and-keyboards)

### Supported Platofrms ###
### Supported Platforms ###
- Windows x86 (32-bit) (¹)

@@ -343,2 +344,7 @@ - Windows x64 (64-bit)

### `device.setNonBlocking(no_block)`
- `no_block` - boolean. Set to `true` to enable non-blocking reads
- exactly mirrors `hid_set_nonblocking()` in [`hidapi`](https://github.com/libusb/hidapi)
-----

@@ -348,5 +354,5 @@

### Mice and keyboards
In general you cannot access USB HID keyboards or mice.
The OS owns these devices.
### Keyboards and mice
The OS will prevent USB HID keyboards or mice, or devices that appear as a keyboard to the OS (such as some barcode readers or RFID scanners). This is a security precaution. Otherwise, it would be trivial to build keyloggers.
There are non-standard work-arounds for this, but in general you cannot use `node-hid` to access keyboard-like devices.

@@ -423,12 +429,12 @@ ### Xbox 360 Controller on Windows 10

* All OSes:
* `node-gyp` installed globally: `npm install -g node-gyp`
* Linux (kernel 2.6+) : install examples shown for Ubuntu
* Linux (kernel 2.6+) : (install examples shown for Debian/Ubuntu)
* Compilation tools: `apt install build-essential git`
* gcc-4.8+: `apt install gcc-4.8 g++-4.8 && export CXX=g++-4.8`
* libusb-1.0-0 w/headers:`sudo apt install libusb-1.0-0 libusb-1.0-0-dev`
* libudev-dev: (Fedora only) `yum install libusbx-devel`
* libusb-1.0-0 w/headers:`apt install libusb-1.0-0 libusb-1.0-0-dev`
* libudev-dev: `apt install libudev-dev` (Debian/Ubuntu) /
`yum install libusbx-devel` (Fedora)
* Mac OS X 10.8+
* [Xcode](https://itunes.apple.com/us/app/xcode/id497799835?mt=12)
* Windows XP, 7, 8, 10

@@ -463,3 +469,4 @@ * Visual C++ compiler and Python 2.7

cd node-hid # must change into node-hid directory
npm run prepublish # get the needed hidapi submodule
npm install -g rimraf # just so it doesn't get 'clean'ed
npm run prepublishOnly # get the needed hidapi submodule
npm install --build-from-source # rebuilds the module with C code

@@ -469,4 +476,4 @@ node ./src/show-devices.js

You will see some warnings from the C compiler as it compiles
[hidapi](https://github.com/signal11/hidapi) (the underlying C library `node-hid` uses).
You may see some warnings from the C compiler as it compiles
[hidapi](https://github.com/libusb/hidapi) (the underlying C library `node-hid` uses).
This is expected.

@@ -504,3 +511,5 @@

```
(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)
Examples of `node-hid` in Electron:
* [electron-hid-toy](https://github.com/todbot/electron-hid-toy) - a simple example of using `node-hid`, that will hopefully always track the latest Electron release
* [Blink1Control2](https://github.com/todbot/Blink1Control2/) - a complete application, using webpack (e.g. see its [webpack-config.js](https://github.com/todbot/Blink1Control2/blob/master/webpack.config.js))

@@ -507,0 +516,0 @@ ## Using `node-hid` in NW.js projects

@@ -13,6 +13,20 @@ /**

var REPORT_ID = 1;
var REPORT_LENGTH = 9;
var REPORT2_ID = 2;
var REPORT_LENGTH = 8;
var REPORT2_LENGTH = 60;
var blink1Version = 0; // to be filled in later
var serial_number = process.argv[2];
var JSONstringifyHex = function(arr) {
var str='[';
for (var i = 0; i < arr.length-1; i++) {
str += '0x' + arr[i].toString(16)
if(i<arr.length-2) { str+=','; }
}
str += ']';
return str;
};
var devices_found = HID.devices( VENDOR_ID, PRODUCT_ID );

@@ -27,7 +41,7 @@

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

@@ -38,3 +52,3 @@ hidDevice = new HID.HID( VENDOR_ID, PRODUCT_ID );

console.log(err);
process.exit(1);
process.exit(1);
}

@@ -46,24 +60,43 @@

console.log("deviceInfo.serialNumber:", deviceInfo.serialNumber);
console.log("\n");
// shamelessly stolen from node-blink1
var blink1_sendCommand = function( /* command [, args ...]*/ ) {
var featureReport = [REPORT_ID, 0, 0, 0, 0, 0, 0, 0, 0];
featureReport[1] = arguments[0].charCodeAt(0);
var featureReport = new Array(REPORT_LENGTH + 1).fill(0); // + 1 for reportId
featureReport[0] = REPORT_ID;
featureReport[1] = arguments[0].charCodeAt(0); // cmd
for (var i = 1; i < arguments.length; i++) {
featureReport[i + 1] = arguments[i];
}
console.log("report sent:", JSONstringifyHex(featureReport));
var rc = hidDevice.sendFeatureReport(featureReport);
console.log("report sent:", featureReport);
console.log("sent size:",featureReport.length," actual size:", rc);
};
var blink1_sendCommand2 = function(/*command, args...*/) {
var featureReport = new Array(REPORT2_LENGTH + 1).fill(0);
featureReport[0] = REPORT2_ID;
featureReport[1] = arguments[0].charCodeAt(0);
for (var i = 1; i < arguments.length; i++) {
featureReport[i + 1] = arguments[i];
}
console.log("report2 sent:"+ JSONstringifyHex(featureReport));
var rc = hidDevice.sendFeatureReport(featureReport);
console.log("sent size:",featureReport.length," actual size:", rc);
};
var blink1_readResponse = function(callback) {
callback.apply(null, [hidDevice.getFeatureReport(REPORT_ID, REPORT_LENGTH)]);
callback.apply(null, [hidDevice.getFeatureReport(REPORT_ID, REPORT_LENGTH+1)]);
};
var blink1_readResponse2 = function(callback) {
callback.apply(null, [hidDevice.getFeatureReport(REPORT2_ID, REPORT2_LENGTH+1)]);
};
var blink1_getVersion = function(callback) {
blink1_sendCommand('v');
blink1_readResponse(function(response) {
var version = String.fromCharCode(response[3]) + '.' + String.fromCharCode(response[4]);
console.log('getVersion response: ',JSONstringifyHex(response))
// var version = String.fromCharCode(response[3]) + '.' + String.fromCharCode(response[4]);
var version = Number.parseInt(String.fromCharCode(response[3]))*100 + Number.parseInt(String.fromCharCode(response[4]))
callback(version);

@@ -73,2 +106,19 @@ });

// var blink1_getStartupParams = function(callback) {
// blink1_sendCommand('b');
// blink1_readResponse(function(response) {})
// });
var blink1_getChipId = function(callback) {
blink1_sendCommand2('U');
blink1_readResponse2(function(response) {
console.log('getChipId response: ',JSONstringifyHex(response))
// var version = String.fromCharCode(response[3]) + '.' + String.fromCharCode(response[4]);
// NOTE: as of node-hid@1.0, response contains reportId as first element of array
// var version = Number.parseInt(String.fromCharCode(response[4]))*100 + Number.parseInt(String.fromCharCode(response[5]))
var chipId = response;
callback(chipId);
});
};
var blink1_fadeToColor = function( fadeMillis, r,g,b, ledn ) {

@@ -80,7 +130,8 @@ var dms = fadeMillis / 10;

blink1_getVersion( function(version) {
console.log("blink(1) version: ", version);
blink1Version = version;
console.log("\nblink(1) version: ", version);
});
setTimeout( function() {
console.log("Setting blink(1) to #00FF33 over 300 millisecs");
console.log("\nSetting blink(1) to #00FF33 over 300 millisecs");
blink1_fadeToColor( 300, 0x00,0xFF,0x33, 0);

@@ -90,3 +141,3 @@ }, 100);

setTimeout( function() {
console.log("Setting blink(1) to #FF6633 over 700 millisecs");
console.log("\nSetting blink(1) to #FF6633 over 700 millisecs");
blink1_fadeToColor( 700, 0xff,0x66,0x00, 0);

@@ -96,5 +147,14 @@ }, 1000);

setTimeout( function() {
console.log("Setting blink(1) to #000000 over 1000 millisecs, and closing");
if( blink1Version > 300 ) {
console.log("\nGetting chipId (mk3 only)");
blink1_getChipId(function(response) {
// do something here
});
}
}, 2000);
setTimeout( function() {
console.log("\nSetting blink(1) to #000000 over 1000 millisecs, and closing");
blink1_fadeToColor( 1000, 0x00,0x00,0x00, 0);
hidDevice.close();
}, 2000 );
}, 3000 );

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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