Skip to content

Commit

Permalink
Add hidraw and libusb drivers. Add Linux HID.setDriverType() to allow…
Browse files Browse the repository at this point in the history
… runtime driver selection. Addresses #309, #249
  • Loading branch information
todbot committed May 30, 2019
1 parent c01e986 commit 47fa54d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
56 changes: 52 additions & 4 deletions binding.gyp
@@ -1,6 +1,6 @@
{
'variables': {
'driver%': 'hidraw'
'driver%': 'libusb'
},
'targets': [
{
Expand All @@ -18,9 +18,9 @@
'-framework CoreFoundation'
],
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.9',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.9',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'OTHER_LDFLAGS': [
'-framework IOKit',
'-framework CoreFoundation'
Expand Down Expand Up @@ -111,6 +111,54 @@
'cflags!': [
'-ansi'
]
},

{
'target_name': 'hidapi-linux-hidraw',
'conditions': [
[ 'OS=="linux"', {
'type': 'static_library',
'sources': [ 'hidapi/linux/hid.c' ],
'direct_dependent_settings': {
'include_dirs': [
'hidapi/hidapi',
"<!(node -e \"require('nan')\")"
]
},
'include_dirs': [
'hidapi/hidapi'
],
'defines': [
'_LARGEFILE_SOURCE',
'_FILE_OFFSET_BITS=64',
],
'cflags': ['-g'],
'cflags!': [
'-ansi'
]
}],
],
},
{
'target_name': 'HID-hidraw',
'conditions': [
[ 'OS=="linux"', {
'sources': [ 'src/HID.cc' ],
'dependencies': ['hidapi-linux-hidraw'],
'defines': [
'_LARGEFILE_SOURCE',
'_FILE_OFFSET_BITS=64',
],
'libraries': [
'-ludev',
'-lusb-1.0'
],
'cflags!': ['-ansi', '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'cflags': ['-g', '-exceptions'],
'cflags_cc': ['-g', '-exceptions']
}]
],
}
]
}
27 changes: 11 additions & 16 deletions nodehid.js
Expand Up @@ -13,23 +13,18 @@ function setDriverType(type) {
var binding = null;
function loadBinding() {
if( !binding ) {
binding = require('bindings')('HID.node');
if( os.platform() === 'linux' ) {
// Linux defaults to hidraw
if( !driverType || driverType === 'hidraw' ) {
binding = require('bindings')('HID-hidraw.node');
} else {
binding = require('bindings')('HID.node');
}
}
else {
binding = require('bindings')('HID.node');
}
}

// disabled until prebuild gets multi-target support, see node-hid#242
// if( !binding ) {
// if( os.platform() === 'linux' ) {
// // Linux defaults to hidraw
// if( !driverType || driverType === 'hidraw' ) {
// binding = require('bindings')('HID-hidraw.node');
// } else {
// binding = require('bindings')('HID.node');
// }
// }
// else {
// binding = require('bindings')('HID.node');
// }
// }
}

//This class is a wrapper for `binding.HID` class
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "node-hid",
"description": "USB HID device access library",
"version": "0.7.8",
"version": "0.7.9",
"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",
Expand All @@ -18,7 +18,7 @@
"showdevices": "node src/show-devices.js",
"prepublish": "git submodule update --init",
"install": "prebuild-install || node-gyp rebuild",
"prebuild": "prebuild --all --verbose",
"prebuild": "prebuild --all --verbose --include-regex \"\\.node$\"",
"prebuild-upload": "prebuild --all --strip --verbose --upload",
"prebuild-ci": "prebuild-ci",
"gypclean": "node-gyp clean",
Expand Down

0 comments on commit 47fa54d

Please sign in to comment.