Permalink
Browse files

Build with gyp; NPM package.json

  • Loading branch information...
1 parent 3995a8f commit bc2dd5e34f481840cb1e4b264e70ccd313a0a643 @kevinmehall kevinmehall committed Oct 28, 2012
Showing with 139 additions and 107 deletions.
  1. +1 −2 .gitignore
  2. +7 −0 LICENSE
  3. +0 −9 Makefile
  4. +27 −34 Readme.md
  5. +55 −0 binding.gyp
  6. +37 −7 package.json
  7. +1 −1 src/bindings.h
  8. +1 −1 src/node_usb.h
  9. +9 −9 tests/node-usb-test.coffee
  10. +1 −1 usb.js
  11. +0 −43 wscript
View
@@ -1,4 +1,3 @@
build/*
-usb_bindings.node
-.lock-wscript
+node_modules
*~
View
@@ -0,0 +1,7 @@
+Copyright (c) 2012 Nonolith Labs, LLC
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,9 +0,0 @@
-make:
- node-waf -v configure clean build
-
-debug:
- node-waf configure --debug=true clean build
- coffee tests/node-usb-test.coffee
-
-create-usb-ids:
- rm usb_ids.js; node util/create_usb_ids.js >> usb_ids.js
View
@@ -1,34 +1,31 @@
USB Library for Node.JS
===============================
-`usb.js` is a Node.JS library for communicating with USB devices in JavaScript / CoffeeScript.
-This library is based on Christopher Klein's [node-usb](https://github.com/schakko/node-usb),
-but the API is not compatible (hopefully you find it an improvement). Compared to node-usb,
-it's based entirely on libusb's asynchronous API for better efficiency, and provides a stream API
-for continuously streaming data.
+Node.JS library for communicating with USB devices in JavaScript / CoffeeScript.
+
+This is a refactoring / rewrite of Christopher Klein's [node-usb](https://github.com/schakko/node-usb). The API is not compatible (hopefully you find it an improvement).
+
+It's based entirely on libusb's asynchronous API for better efficiency, and provides a stream API for continuously streaming data or events.
+
+Tested with Node 0.6.12/Linux and 0.8.14/Linux.
-Tested with Node version 0.6.12/Linux.
Older versions of libusb segfault when using bulk or interrupt endpoints.
Use [libusb](http://libusb.org) or [libusbx](http://libusbx.org) 1.0.9 or greater.
Installation
============
-Make sure you have installed libusb-1.0-0-dev (Ubuntu: sudo apt-get install libusb-1.0-0-dev).
+Make sure you have installed libusb-1.0-0-dev (Ubuntu: `sudo apt-get install libusb-1.0-0-dev`).
Just run
- make
-
-in the git checkout.
+ npm install usb
-If you want to use the USB vendor ids, execute
-
- make create-usb-ids
+to install from npm. See the bottom of this page for instructions for building from a git checkout.
API
===
- var usb = require('./usb')
+ var usb = require('usb')
usb
---
@@ -110,7 +107,6 @@ Object with properties for the fields of the config descriptor:
Interface
---------
-
### .endpoint(address)
Return the InEndpoint or OutEndpoint with the specified address.
@@ -191,12 +187,9 @@ Endpoints in the IN direction (device->PC) have this type.
### .transfer(length, callback(data, error))
Perform a transfer to read data from the endpoint.
-If length is greater than maxPacketSize, libusb will automatically split the transfer in multple packets,
-and you will receive one callback with all data once all packets are complete.
+If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback with all data once all packets are complete.
-Callback first parameter is `data`, just like OutEndpoint, but will always be undefined as no data is returned.
-
-`this` in the callback is the OutEndpoint object.
+`this` in the callback is the InEndpoint object.
### .startStream(nTransfers=3, transferSize=maxPacketSize)
Start a streaming transfer from the endpoint.
@@ -209,7 +202,7 @@ if the Node v8 thread is busy. The `data` and `error` events are emitted as tran
### .stopStream()
Stop the streaming transfer.
-Further data may still be received. The `end` event is emitted once all transfers have completed or cancelled.
+Further data may still be received. The `end` event is emitted once all transfers have completed or canceled.
### Event: data(data : Buffer)
Emitted with data received by the stream
@@ -218,18 +211,19 @@ Emitted with data received by the stream
Emitted when the stream encounters an error.
### Event: end
-Emitted when the stream has been cancelled
+Emitted when the stream has been canceled
OutEndpoint
-----------
Endpoints in the OUT direction (PC->device) have this type.
-### .transfer(data, callback)
+### .transfer(data, callback(data, error))
Perform a transfer to write `data` to the endpoint.
-If length is greater than maxPacketSize, libusb will automatically split the transfer in multple packets,
-and you will receive one callback with all data once all packets are complete.
+If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback once all packets are complete.
+
+Callback first parameter is `data`, just like InEndpoint, but will always be undefined as no data is returned.
`this` in the callback is the OutEndpoint object.
@@ -248,7 +242,7 @@ Delegates to .transfer(), but differs in that it updates the stream state tracki
### .stopStream()
Stop the streaming transfer.
-No further `drain` events will be emitted. When all transfers have been completed, the OutEndpoint emits the `drain` event.
+No further `drain` events will be emitted. When all transfers have been completed, the OutEndpoint emits the `end` event.
### Event: drain
Emitted when the stream requests more data. Use the .write() method to start another transfer.
@@ -263,18 +257,17 @@ Emitted when the stream has been stopped and all pending requests have been comp
Development and testing
=======================
-To execute the unit tests, [CoffeeScript](http://coffeescript.org) is required. Run
-
- coffee tests/node-usb-test.coffee
-
+To build from git:
-For creating debug output you have to compile usb.js with
+ git clone https://github.com/nonolith/node-usb.git
+ cd node-usb
+ npm install
- make debug
+To execute the unit tests, [CoffeeScript](http://coffeescript.org) is required. Run
-or
+ npm test
- node-waf clean configure --debug=true build
+Some tests require an attached USB device -- firmware to be released soon.
Limitations
===========
View
@@ -0,0 +1,55 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'usb_bindings',
+ 'sources': [
+ './src/node_usb.cc',
+ './src/bindings.cc',
+ './src/usb.cc',
+ './src/device.cc',
+ './src/interface.cc',
+ './src/endpoint.cc',
+ './src/transfer.cc',
+ './src/stream.cc',
+ ],
+ 'cflags': [
+ '-O3',
+ '-Wall',
+ '-Werror',
+ '-msse2',
+ ],
+ 'cflags_cc': [
+ '-O3',
+ '-Wall',
+ '-Werror',
+ '-msse2',
+ '-std=gnu++0x'
+ ],
+ 'defines': [
+ '_FILE_OFFSET_BITS=64',
+ '_LARGEFILE_SOURCE',
+ ],
+ 'include_dirs+': [
+ 'src/'
+ ],
+ 'link_settings': {
+ 'conditions' : [
+ ['OS=="linux"',
+ {
+ 'libraries': [
+ '-lusb-1.0'
+ ]
+ }
+ ],
+ ['OS=="mac"',
+ {
+ 'libraries': [
+ '-lusb-1.0'
+ ]
+ }
+ ]
+ ]
+ }
+ }
+ ]
+}
View
@@ -1,9 +1,39 @@
-{ "name" : "node-usb"
-, "version" : "0.0.1"
-, "description" : "experimental libusb bindings"
-, "author": "Christopher Klein"
-, "main": "./usb_bindings"
-, "scripts": { "install": "node-waf configure build" }
-}
+{
+ "name": "usb",
+ "description": "Library to access USB devices",
+ "keywords": ["usb", "hardware"],
+ "author": {
+ "name": "Nonolith Labs",
+ "url": "http://www.nonolithlabs.com"
+ },
+ "contributors": [
+ {
+ "name": "Kevin Mehall",
+ "email": "km@kevinmehall.net",
+ "url": "http://kevinmehall.net"
+ },
+ {"name": "Christopher Klein"}
+ ],
+ "version": "0.1.0",
+ "engines" : {
+ "node" : ">=0.6.x <0.8.9999"
+ },
+ "main": "./usb",
+ "repository": {
+ "type": "git",
+ "url":"https://github.com/nonolith/node-usb.git"
+ },
+ "scripts": {
+ "preinstall": "node-gyp rebuild",
+ "test" : "coffee tests/node-usb-test.coffee"
+ },
+ "dependencies":{
+ "bindings": "1.0.x"
+ },
+ "devDependencies": {
+ "coffee-script": "~1.4.0"
+ },
+ "license": "MIT"
+}
View
@@ -2,7 +2,7 @@
#define SRC_BINDINGS_H
#include "node_usb.h"
-#include "libusb.h"
+#include "libusb-1.0/libusb.h"
// Taken from node-libmysqlclient
#define OBJUNWRAP ObjectWrap::Unwrap
View
@@ -12,7 +12,7 @@
#include <string>
#include <cstdlib>
-#include <libusb.h>
+#include <libusb-1.0/libusb.h>
#include <v8.h>
#include <node.h>
View
@@ -73,22 +73,22 @@ test "Control transfer in", ->
next()
wait()
-interface = null
+iface = null
test "Get interface", ->
- interface = device.interfaces[0]
- assert.notEqual(interface, undefined, "Interface must be defined")
- assert.equal(interface, device.interface(0))
+ iface = device.interfaces[0]
+ assert.notEqual(iface, undefined, "Interface must be defined")
+ assert.equal(iface, device.interface(0))
test "Claim interface", ->
- interface.claim()
+ iface.claim()
inEndpoint = null
outEndpoint = null
test "Get in endpoint", ->
- inEndpoint = interface.endpoints[0]
+ inEndpoint = iface.endpoints[0]
assert.notEqual(inEndpoint, undefined, "Endpoint must be defined")
- assert.equal(inEndpoint, interface.endpoint(0x81))
+ assert.equal(inEndpoint, iface.endpoint(0x81))
assert.equal(inEndpoint.direction, usb.LIBUSB_ENDPOINT_IN)
test "Attempt to write to IN endpoint", ->
@@ -102,9 +102,9 @@ test "Read from IN endpoint", ->
wait()
test "Get out endpoint", ->
- outEndpoint = interface.endpoints[1]
+ outEndpoint = iface.endpoints[1]
assert.notEqual(outEndpoint, undefined, "Endpoint must be defined")
- assert.equal(outEndpoint, interface.endpoint(0x02))
+ assert.equal(outEndpoint, iface.endpoint(0x02))
assert.equal(outEndpoint.direction, usb.LIBUSB_ENDPOINT_OUT)
test "Attempt to read from OUT endpoint", ->
View
2 usb.js
@@ -1,7 +1,7 @@
/**
* Expose complete node-usb binding to node.js
*/
-var usb = exports = module.exports = require("./usb_bindings");
+var usb = exports = module.exports = require("bindings")("usb_bindings");
var events = require('events');
View
43 wscript
@@ -1,43 +0,0 @@
-import os
-import Options, Utils
-from os import unlink, symlink, chdir, popen
-from os.path import exists
-
-srcdir = '.'
-blddir = 'build'
-VERSION = '0.1'
-REVISION = popen("git log | head -n1 | awk '{printf \"%s\", $2}'").readline()
-
-def set_options(opt):
- opt.tool_options("compiler_cxx")
- opt.tool_options("compiler_cc")
- opt.add_option('--debug', action='store', default=False, help='Enable debugging output')
-
-def configure(conf):
- conf.check_tool('compiler_cxx')
- conf.check_tool("compiler_cc")
- conf.check_tool('node_addon')
- conf.find_program('pkg-config', mandatory=True)
-
- conf.check_cfg(package='libusb-1.0', uselib_store='USB10', mandatory=1, args='--cflags --libs')
- conf.env.append_unique('CPPFLAGS', ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE"])
- conf.env.append_unique('CXXFLAGS', ["-Wall", "-std=gnu++0x"])
- conf.env.append_value('CPPFLAGS_NODE', ['-DEV_MULTIPLICITY=1'])
-
-def build(bld):
- obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
- obj.target = 'usb_bindings'
- obj.source = './src/node_usb.cc ./src/bindings.cc ./src/usb.cc ./src/device.cc ./src/interface.cc ./src/endpoint.cc ./src/transfer.cc ./src/stream.cc'
- obj.includes = bld.env['CPPPATH_USB10']
- obj.uselib = ["USB10"]
- obj.name = "node-usb"
- obj.defines = ['NODE_USB_REVISION="' + REVISION + '"']
-
- if (Options.options.debug != False) and (Options.options.debug == 'true'):
- obj.defines.append('ENABLE_DEBUG=1')
-
-def shutdown():
- t = 'usb_bindings.node';
-
- if exists('build/Release/' + t) and not exists(t):
- symlink('build/Release/' + t, t)

0 comments on commit bc2dd5e

Please sign in to comment.