ruby-usb 0.1.3-x86-mswin32-60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +504 -0
- data/History.txt +19 -0
- data/Manifest.txt +11 -0
- data/README.txt +55 -0
- data/README.win32 +61 -0
- data/Rakefile +30 -0
- data/ext/constants.h +86 -0
- data/ext/extconf.rb +28 -0
- data/ext/usb.c +931 -0
- data/ext/usb.so +0 -0
- data/lib/usb.rb +420 -0
- data/sample/usb-power +46 -0
- metadata +71 -0
data/History.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
== 0.1.3 / 2008-03-30
|
2
|
+
|
3
|
+
* Fix broken gem packaging. Aslak Hellesøy <aslak.hellesoy@gmail.com>
|
4
|
+
|
5
|
+
== 0.1.2 / 2008-03-30
|
6
|
+
|
7
|
+
* First gem release on RubyForge. Aslak Hellesøy <aslak.hellesoy@gmail.com>
|
8
|
+
* Binary gem for Windows
|
9
|
+
* Source gem for POSIX
|
10
|
+
|
11
|
+
* usb.c: include st.h. Tanaka Akira <akr@fsij.org>
|
12
|
+
* fix a compile error on MacOS X reported by Tony Buser.
|
13
|
+
|
14
|
+
* lib/usb.rb (USB.each_device_by_class): new method. Tanaka Akira <akr@fsij.org>
|
15
|
+
|
16
|
+
== 0.1 / 2007-01-10
|
17
|
+
|
18
|
+
* First release. Tanaka Akira <akr@fsij.org>
|
19
|
+
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= ruby-usb
|
2
|
+
|
3
|
+
* http://www.a-k-r.org/ruby-usb/
|
4
|
+
* http://gitorious.org/projects/ruby-usb
|
5
|
+
* http://ruby-usb.rubyforge.org/
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
ruby-usb is a libusb binding library for Ruby.
|
10
|
+
|
11
|
+
== Author
|
12
|
+
|
13
|
+
* Tanaka Akira <akr@fsij.org>
|
14
|
+
* Aslak Helles�y <aslak.hellesoy@gmail.com> (Gem packaging only)
|
15
|
+
|
16
|
+
== License
|
17
|
+
|
18
|
+
LGPL
|
19
|
+
|
20
|
+
== Feature
|
21
|
+
|
22
|
+
* direct (non-rubyish) binding
|
23
|
+
* rubyish interface (work in progress)
|
24
|
+
|
25
|
+
== Requirements
|
26
|
+
|
27
|
+
* ruby : http://www.ruby-lang.org/
|
28
|
+
* libusb 0.1 : http://libusb.sourceforge.net/
|
29
|
+
|
30
|
+
== Download
|
31
|
+
|
32
|
+
* latest official release: http://www.a-k-r.org/ruby-usb/ruby-usb-0.1.tar.gz
|
33
|
+
* development version in Subversion repository:
|
34
|
+
% svn co svn://svn@svn.a-k-r.org/akr/ruby-usb/trunk ruby-usb
|
35
|
+
|
36
|
+
== Rubygems install
|
37
|
+
|
38
|
+
gem install ruby-usb
|
39
|
+
|
40
|
+
== Install
|
41
|
+
|
42
|
+
% ruby extconf.rb
|
43
|
+
% make
|
44
|
+
% make install
|
45
|
+
|
46
|
+
== Reference Manual
|
47
|
+
|
48
|
+
See rdoc/ or
|
49
|
+
http://www.a-k-r.org/ruby-usb/rdoc/
|
50
|
+
|
51
|
+
== See Also
|
52
|
+
|
53
|
+
* USB.org : http://www.usb.org/
|
54
|
+
* AC Power Control through USB : http://www.gniibe.org/ac-power-by-usb/ac-power-control.html
|
55
|
+
* How To Control USB Missile Launcher on Linux : http://blog.taragana.com/index.php/archive/how-to-control-usb-missile-launcher-on-linux/
|
data/README.win32
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= Building Ruby-USB on Windows
|
2
|
+
|
3
|
+
The binaries will work with the Ruby one-click installer, but we have to build everything
|
4
|
+
with MinGW. This also means we need to build our own Ruby with MinGW.
|
5
|
+
|
6
|
+
== Author of README.win32
|
7
|
+
|
8
|
+
Aslak Hellesøy <aslak.hellesoy@gmail.com>
|
9
|
+
|
10
|
+
== Installing prerequisites
|
11
|
+
* MinGW and MSYS: http://www.mingw.org/ (MinGW installer and msysCORE-1.0.11-2007.01.19-1.tar.bz2)
|
12
|
+
* LibUsb-Win32: http://libusb-win32.sourceforge.net/
|
13
|
+
* Ruby sources
|
14
|
+
|
15
|
+
== Building Ruby with MinGW
|
16
|
+
put MSYS and MinGW bin on the path, for example:
|
17
|
+
SET PATH=C:\MinGW\bin;C:\msys\bin;%PATH%
|
18
|
+
|
19
|
+
cd to ruby sources
|
20
|
+
|
21
|
+
sh configure --with-winsock2
|
22
|
+
make
|
23
|
+
make install
|
24
|
+
|
25
|
+
You now have a Ruby under c:\usr\local\bin\ruby.exe Try it:
|
26
|
+
|
27
|
+
C:\usr\local\bin\ruby --version
|
28
|
+
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mingw32]
|
29
|
+
(note the [i386-mingw32])
|
30
|
+
|
31
|
+
Now, copy zlib.so and openssl.so from your prebuilt Ruby to the one you built yourself,
|
32
|
+
your own build won't have it. This is needed in order for Rubygems to work.
|
33
|
+
|
34
|
+
Now you must install rubygems. After you have done that, install hoe:
|
35
|
+
\usr\local\bin\gem install hoe
|
36
|
+
You may have to comment out the line in hoe.rb that has `which dot`
|
37
|
+
|
38
|
+
== Prepare for building the native extensions
|
39
|
+
We must copy the libusb library and header file into ruby-usb.
|
40
|
+
First, cd to the toplevel dir (the directory of this file)
|
41
|
+
|
42
|
+
cp "C:\Program Files\LibUSB-Win32\lib\msvc\libusb.lib" ext\usb.lib
|
43
|
+
cp "C:\Program Files\LibUSB-Win32\include\usb.h" ext
|
44
|
+
|
45
|
+
== Build the gem with binary extensions
|
46
|
+
\usr\local\bin\rake clean compile
|
47
|
+
rake gem INLINE=1
|
48
|
+
|
49
|
+
== Install the gem in your official ruby (the one from Ruby one-click installer)
|
50
|
+
gem install pkg\ruby-usb-0.1.3-x86-mswin32.gem
|
51
|
+
|
52
|
+
== Test that it works in your official ruby
|
53
|
+
> irb
|
54
|
+
irb(main):001:0> require 'usb'
|
55
|
+
=> true
|
56
|
+
irb(main):002:0> puts USB.devices.inspect
|
57
|
+
[#<USB::Device bus-0/\\.\libusb0-0001--0x0a5c-0x2110 0a5c:2110 Broadcom Corp BCM2045B ? (Bluetooth)>, #<USB::Device bus-0/\\.\libusb0-0002--0x0483-0x2016 0483:2016 STMicroelectronics Biometric Coprocessor ? (Vendor specific (00,00))>]
|
58
|
+
|
59
|
+
== Releasing on RubyForge
|
60
|
+
rake release VERSION=0.1.3 # On a Mac
|
61
|
+
rubyforge add_file ruby-usb ruby-usb 0.1.3 pkg\ruby-usb-0.1.3-x86-mswin32-60.gem # On a Windows
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
|
4
|
+
hoe = Hoe.new('ruby-usb', '0.1.3') do |p|
|
5
|
+
p.summary = "Tanaka Akira's ruby-usb packaged as gems"
|
6
|
+
p.remote_rdoc_dir = ''
|
7
|
+
p.developer('Aslak Hellesøy', 'aslak.hellesoy@gmail.com')
|
8
|
+
p.developer('Tanaka Akira', 'akr@fsij.org')
|
9
|
+
p.clean_globs = ['ext/Makefile', 'ext/mkmf.log', 'ext/usb.bundle', 'ext/usb.o', 'ext/usb.so']
|
10
|
+
p.spec_extras[:dependencies] = lambda do |dependencies|
|
11
|
+
dependencies.reject!{|dep| dep.name == 'hoe'}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
case RUBY_PLATFORM
|
16
|
+
when /i386-mingw32/
|
17
|
+
filename = "ext/usb.so"
|
18
|
+
file filename do
|
19
|
+
Dir.chdir("ext") do
|
20
|
+
ruby "extconf.rb"
|
21
|
+
system('make')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
desc 'Compile'
|
25
|
+
task :compile => [filename]
|
26
|
+
when /i386-mswin32/
|
27
|
+
hoe.spec.files += ['ext/usb.so']
|
28
|
+
else
|
29
|
+
hoe.spec.extensions = ['ext/extconf.rb']
|
30
|
+
end
|
data/ext/constants.h
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
/*
|
2
|
+
constants.h - libusb constants
|
3
|
+
|
4
|
+
Copyright (C) 2007 Tanaka Akira
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
f(USB_CLASS_PER_INTERFACE)
|
22
|
+
f(USB_CLASS_AUDIO)
|
23
|
+
f(USB_CLASS_COMM)
|
24
|
+
f(USB_CLASS_HID)
|
25
|
+
f(USB_CLASS_PRINTER)
|
26
|
+
#ifdef USB_CLASS_PTP
|
27
|
+
f(USB_CLASS_PTP)
|
28
|
+
#endif
|
29
|
+
f(USB_CLASS_MASS_STORAGE)
|
30
|
+
f(USB_CLASS_HUB)
|
31
|
+
f(USB_CLASS_DATA)
|
32
|
+
f(USB_CLASS_VENDOR_SPEC)
|
33
|
+
f(USB_DT_DEVICE)
|
34
|
+
f(USB_DT_CONFIG)
|
35
|
+
f(USB_DT_STRING)
|
36
|
+
f(USB_DT_INTERFACE)
|
37
|
+
f(USB_DT_ENDPOINT)
|
38
|
+
f(USB_DT_HID)
|
39
|
+
f(USB_DT_REPORT)
|
40
|
+
f(USB_DT_PHYSICAL)
|
41
|
+
f(USB_DT_HUB)
|
42
|
+
f(USB_DT_DEVICE_SIZE)
|
43
|
+
f(USB_DT_CONFIG_SIZE)
|
44
|
+
f(USB_DT_INTERFACE_SIZE)
|
45
|
+
f(USB_DT_ENDPOINT_SIZE)
|
46
|
+
f(USB_DT_ENDPOINT_AUDIO_SIZE)
|
47
|
+
f(USB_DT_HUB_NONVAR_SIZE)
|
48
|
+
f(USB_MAXENDPOINTS)
|
49
|
+
f(USB_ENDPOINT_ADDRESS_MASK)
|
50
|
+
f(USB_ENDPOINT_DIR_MASK)
|
51
|
+
f(USB_ENDPOINT_TYPE_MASK)
|
52
|
+
f(USB_ENDPOINT_TYPE_CONTROL)
|
53
|
+
f(USB_ENDPOINT_TYPE_ISOCHRONOUS)
|
54
|
+
f(USB_ENDPOINT_TYPE_BULK)
|
55
|
+
f(USB_ENDPOINT_TYPE_INTERRUPT)
|
56
|
+
f(USB_MAXINTERFACES)
|
57
|
+
f(USB_MAXALTSETTING)
|
58
|
+
f(USB_MAXCONFIG)
|
59
|
+
f(USB_REQ_GET_STATUS)
|
60
|
+
f(USB_REQ_CLEAR_FEATURE)
|
61
|
+
f(USB_REQ_SET_FEATURE)
|
62
|
+
f(USB_REQ_SET_ADDRESS)
|
63
|
+
f(USB_REQ_GET_DESCRIPTOR)
|
64
|
+
f(USB_REQ_SET_DESCRIPTOR)
|
65
|
+
f(USB_REQ_GET_CONFIGURATION)
|
66
|
+
f(USB_REQ_SET_CONFIGURATION)
|
67
|
+
f(USB_REQ_GET_INTERFACE)
|
68
|
+
f(USB_REQ_SET_INTERFACE)
|
69
|
+
f(USB_REQ_SYNCH_FRAME)
|
70
|
+
f(USB_TYPE_STANDARD)
|
71
|
+
f(USB_TYPE_CLASS)
|
72
|
+
f(USB_TYPE_VENDOR)
|
73
|
+
f(USB_TYPE_RESERVED)
|
74
|
+
f(USB_RECIP_DEVICE)
|
75
|
+
f(USB_RECIP_INTERFACE)
|
76
|
+
f(USB_RECIP_ENDPOINT)
|
77
|
+
f(USB_RECIP_OTHER)
|
78
|
+
f(USB_ENDPOINT_IN)
|
79
|
+
f(USB_ENDPOINT_OUT)
|
80
|
+
f(USB_ERROR_BEGIN)
|
81
|
+
#ifdef LIBUSB_HAS_GET_DRIVER_NP
|
82
|
+
f(LIBUSB_HAS_GET_DRIVER_NP)
|
83
|
+
#endif
|
84
|
+
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
|
85
|
+
f(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
|
86
|
+
#endif
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2006 Tanaka Akira. All rights reserved.
|
2
|
+
#
|
3
|
+
# Redistribution and use in source and binary forms, with or without
|
4
|
+
# modification, are permitted provided that the following conditions
|
5
|
+
# are met:
|
6
|
+
# 1. Redistributions of source code must retain the above copyright
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
8
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
11
|
+
#
|
12
|
+
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
# SUCH DAMAGE.
|
23
|
+
|
24
|
+
require 'mkmf'
|
25
|
+
|
26
|
+
have_library("usb", "usb_init")
|
27
|
+
|
28
|
+
create_makefile('usb')
|
data/ext/usb.c
ADDED
@@ -0,0 +1,931 @@
|
|
1
|
+
/*
|
2
|
+
usb.c - libusb interface for Ruby.
|
3
|
+
|
4
|
+
Copyright (C) 2007 Tanaka Akira
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "ruby.h"
|
22
|
+
#include "st.h"
|
23
|
+
#include <usb.h>
|
24
|
+
#include <errno.h>
|
25
|
+
|
26
|
+
#ifndef RSTRING_PTR
|
27
|
+
# define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
28
|
+
# define RSTRING_LEN(s) (RSTRING(s)->len)
|
29
|
+
#endif
|
30
|
+
|
31
|
+
static VALUE rb_cUSB;
|
32
|
+
|
33
|
+
static VALUE rusb_dev_handle_new(usb_dev_handle *h);
|
34
|
+
|
35
|
+
#define define_usb_struct(c_name, ruby_name) \
|
36
|
+
static VALUE rb_cUSB_ ## ruby_name; \
|
37
|
+
static st_table *c_name ## _objects; \
|
38
|
+
typedef struct { struct usb_ ## c_name *ptr; VALUE parent; } rusb_ ## c_name ## _t; \
|
39
|
+
static void rusb_ ## c_name ## _free(void *p) { \
|
40
|
+
if (p) free(p); \
|
41
|
+
} \
|
42
|
+
static VALUE rusb_ ## c_name ## _make(struct usb_ ## c_name *p, VALUE parent) \
|
43
|
+
{ \
|
44
|
+
VALUE v; \
|
45
|
+
rusb_ ## c_name ## _t *d; \
|
46
|
+
if (p == NULL) { return Qnil; } \
|
47
|
+
if (st_lookup(c_name ## _objects, (st_data_t)p, (st_data_t *)&v)) \
|
48
|
+
return v; \
|
49
|
+
d = (rusb_ ## c_name ## _t *)xmalloc(sizeof(*d)); \
|
50
|
+
d->ptr = p; \
|
51
|
+
d->parent = parent; \
|
52
|
+
v = Data_Wrap_Struct(rb_cUSB_ ## ruby_name, 0, rusb_ ## c_name ## _free, d); \
|
53
|
+
st_add_direct(c_name ## _objects, (st_data_t)p, (st_data_t)v); \
|
54
|
+
return v; \
|
55
|
+
} \
|
56
|
+
static rusb_ ## c_name ## _t *check_usb_ ## c_name(VALUE v) \
|
57
|
+
{ \
|
58
|
+
Check_Type(v, T_DATA); \
|
59
|
+
if (RDATA(v)->dfree != rusb_ ## c_name ## _free) { \
|
60
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected USB::" #ruby_name ")", \
|
61
|
+
rb_class2name(CLASS_OF(v))); \
|
62
|
+
} \
|
63
|
+
return DATA_PTR(v); \
|
64
|
+
} \
|
65
|
+
static rusb_ ## c_name ## _t *get_rusb_ ## c_name(VALUE v) \
|
66
|
+
{ \
|
67
|
+
rusb_ ## c_name ## _t *d = check_usb_ ## c_name(v); \
|
68
|
+
if (!d) { \
|
69
|
+
rb_raise(rb_eArgError, "revoked USB::" #ruby_name); \
|
70
|
+
} \
|
71
|
+
return d; \
|
72
|
+
} \
|
73
|
+
static struct usb_ ## c_name *get_usb_ ## c_name(VALUE v) \
|
74
|
+
{ \
|
75
|
+
return get_rusb_ ## c_name(v)->ptr; \
|
76
|
+
} \
|
77
|
+
static VALUE get_usb_ ## c_name ## _parent(VALUE v) \
|
78
|
+
{ \
|
79
|
+
return get_rusb_ ## c_name(v)->parent; \
|
80
|
+
}
|
81
|
+
|
82
|
+
define_usb_struct(bus, Bus)
|
83
|
+
define_usb_struct(device, Device)
|
84
|
+
define_usb_struct(config_descriptor, Configuration)
|
85
|
+
define_usb_struct(interface, Interface)
|
86
|
+
define_usb_struct(interface_descriptor, Setting)
|
87
|
+
define_usb_struct(endpoint_descriptor, Endpoint)
|
88
|
+
|
89
|
+
static int mark_data_i(st_data_t key, st_data_t val, st_data_t arg)
|
90
|
+
{
|
91
|
+
if (DATA_PTR((VALUE)val))
|
92
|
+
rb_gc_mark((VALUE)val);
|
93
|
+
return ST_CONTINUE;
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE rusb_gc_root;
|
97
|
+
static void rusb_gc_mark(void *p) {
|
98
|
+
st_foreach(bus_objects, mark_data_i, 0);
|
99
|
+
st_foreach(device_objects, mark_data_i, 0);
|
100
|
+
st_foreach(config_descriptor_objects, mark_data_i, 0);
|
101
|
+
st_foreach(interface_objects, mark_data_i, 0);
|
102
|
+
st_foreach(interface_descriptor_objects, mark_data_i, 0);
|
103
|
+
st_foreach(endpoint_descriptor_objects, mark_data_i, 0);
|
104
|
+
}
|
105
|
+
|
106
|
+
/* -------- USB::Bus -------- */
|
107
|
+
static int revoke_data_i(st_data_t key, st_data_t val, st_data_t arg)
|
108
|
+
{
|
109
|
+
DATA_PTR((VALUE)val) = NULL;
|
110
|
+
return ST_DELETE;
|
111
|
+
}
|
112
|
+
|
113
|
+
/* USB.find_busses */
|
114
|
+
static VALUE
|
115
|
+
rusb_find_busses(VALUE cUSB)
|
116
|
+
{
|
117
|
+
st_foreach(bus_objects, revoke_data_i, 0);
|
118
|
+
st_foreach(device_objects, revoke_data_i, 0);
|
119
|
+
st_foreach(config_descriptor_objects, revoke_data_i, 0);
|
120
|
+
st_foreach(interface_objects, revoke_data_i, 0);
|
121
|
+
st_foreach(interface_descriptor_objects, revoke_data_i, 0);
|
122
|
+
st_foreach(endpoint_descriptor_objects, revoke_data_i, 0);
|
123
|
+
return INT2NUM(usb_find_busses());
|
124
|
+
}
|
125
|
+
|
126
|
+
/* USB.find_devices */
|
127
|
+
static VALUE
|
128
|
+
rusb_find_devices(VALUE cUSB)
|
129
|
+
{
|
130
|
+
return INT2NUM(usb_find_devices());
|
131
|
+
}
|
132
|
+
|
133
|
+
/* USB.first_bus */
|
134
|
+
static VALUE
|
135
|
+
rusb_first_bus(VALUE cUSB)
|
136
|
+
{
|
137
|
+
struct usb_bus *bus = usb_get_busses();
|
138
|
+
return rusb_bus_make(bus, Qnil);
|
139
|
+
}
|
140
|
+
|
141
|
+
/* USB::Bus#revoked? */
|
142
|
+
static VALUE
|
143
|
+
rusb_bus_revoked_p(VALUE v)
|
144
|
+
{
|
145
|
+
return RTEST(!check_usb_bus(v));
|
146
|
+
}
|
147
|
+
|
148
|
+
/* USB::Bus#prev */
|
149
|
+
static VALUE rusb_bus_prev(VALUE v) { return rusb_bus_make(get_usb_bus(v)->prev, Qnil); }
|
150
|
+
|
151
|
+
/* USB::Bus#next */
|
152
|
+
static VALUE rusb_bus_next(VALUE v) { return rusb_bus_make(get_usb_bus(v)->next, Qnil); }
|
153
|
+
|
154
|
+
/* USB::Bus#dirname */
|
155
|
+
static VALUE rusb_bus_dirname(VALUE v) { return rb_str_new2(get_usb_bus(v)->dirname); }
|
156
|
+
|
157
|
+
/* USB::Bus#location */
|
158
|
+
static VALUE rusb_bus_location(VALUE v) { return UINT2NUM(get_usb_bus(v)->location); }
|
159
|
+
|
160
|
+
/* USB::Bus#first_device */
|
161
|
+
static VALUE rusb_bus_first_device(VALUE v) { return rusb_device_make(get_usb_bus(v)->devices, v); }
|
162
|
+
|
163
|
+
/* -------- USB::Device -------- */
|
164
|
+
|
165
|
+
/* USB::Bus#revoked? */
|
166
|
+
static VALUE
|
167
|
+
rusb_device_revoked_p(VALUE v)
|
168
|
+
{
|
169
|
+
return RTEST(!check_usb_device(v));
|
170
|
+
}
|
171
|
+
|
172
|
+
/* USB::Device#prev */
|
173
|
+
static VALUE rusb_device_prev(VALUE v) { rusb_device_t *device = get_rusb_device(v); return rusb_device_make(device->ptr->prev, device->parent); }
|
174
|
+
|
175
|
+
/* USB::Device#next */
|
176
|
+
static VALUE rusb_device_next(VALUE v) { rusb_device_t *device = get_rusb_device(v); return rusb_device_make(device->ptr->next, device->parent); }
|
177
|
+
|
178
|
+
/* USB::Device#filename */
|
179
|
+
static VALUE rusb_device_filename(VALUE v) { return rb_str_new2(get_usb_device(v)->filename); }
|
180
|
+
|
181
|
+
/* USB::Device#bus */
|
182
|
+
static VALUE rusb_device_bus(VALUE v) { return rusb_bus_make(get_usb_device(v)->bus, Qnil); }
|
183
|
+
|
184
|
+
/* USB::Device#devnum */
|
185
|
+
static VALUE rusb_device_devnum(VALUE v) { return INT2FIX(get_usb_device(v)->devnum); }
|
186
|
+
|
187
|
+
/* USB::Device#num_children */
|
188
|
+
static VALUE rusb_device_num_children(VALUE v) { return INT2FIX(get_usb_device(v)->num_children); }
|
189
|
+
|
190
|
+
/* USB::Device#children */
|
191
|
+
static VALUE
|
192
|
+
rusb_device_children(VALUE vdevice)
|
193
|
+
{
|
194
|
+
rusb_device_t *d = get_rusb_device(vdevice);
|
195
|
+
struct usb_device *device = d->ptr;
|
196
|
+
int i;
|
197
|
+
VALUE children = rb_ary_new2(device->num_children);
|
198
|
+
for (i = 0; i < device->num_children; i++)
|
199
|
+
rb_ary_store(children, i, rusb_device_make(device->children[i], d->parent));
|
200
|
+
return children;
|
201
|
+
}
|
202
|
+
|
203
|
+
/* USB::Device#descriptor_bLength */
|
204
|
+
static VALUE rusb_devdesc_bLength(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bLength); }
|
205
|
+
|
206
|
+
/* USB::Device#descriptor_bDescriptorType */
|
207
|
+
static VALUE rusb_devdesc_bDescriptorType(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDescriptorType); }
|
208
|
+
|
209
|
+
/* USB::Device#descriptor_bcdUSB */
|
210
|
+
static VALUE rusb_devdesc_bcdUSB(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bcdUSB); }
|
211
|
+
|
212
|
+
/* USB::Device#descriptor_bDeviceClass */
|
213
|
+
static VALUE rusb_devdesc_bDeviceClass(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceClass); }
|
214
|
+
|
215
|
+
/* USB::Device#descriptor_bDeviceSubClass */
|
216
|
+
static VALUE rusb_devdesc_bDeviceSubClass(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceSubClass); }
|
217
|
+
|
218
|
+
/* USB::Device#descriptor_bDeviceProtocol */
|
219
|
+
static VALUE rusb_devdesc_bDeviceProtocol(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bDeviceProtocol); }
|
220
|
+
|
221
|
+
/* USB::Device#descriptor_bMaxPacketSize0 */
|
222
|
+
static VALUE rusb_devdesc_bMaxPacketSize0(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bMaxPacketSize0); }
|
223
|
+
|
224
|
+
/* USB::Device#descriptor_idVendor */
|
225
|
+
static VALUE rusb_devdesc_idVendor(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.idVendor); }
|
226
|
+
|
227
|
+
/* USB::Device#descriptor_idProduct */
|
228
|
+
static VALUE rusb_devdesc_idProduct(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.idProduct); }
|
229
|
+
|
230
|
+
/* USB::Device#descriptor_bcdDevice */
|
231
|
+
static VALUE rusb_devdesc_bcdDevice(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bcdDevice); }
|
232
|
+
|
233
|
+
/* USB::Device#descriptor_iManufacturer */
|
234
|
+
static VALUE rusb_devdesc_iManufacturer(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iManufacturer); }
|
235
|
+
|
236
|
+
/* USB::Device#descriptor_iProduct */
|
237
|
+
static VALUE rusb_devdesc_iProduct(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iProduct); }
|
238
|
+
|
239
|
+
/* USB::Device#descriptor_iSerialNumber */
|
240
|
+
static VALUE rusb_devdesc_iSerialNumber(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.iSerialNumber); }
|
241
|
+
|
242
|
+
/* USB::Device#descriptor_bNumConfigurations */
|
243
|
+
static VALUE rusb_devdesc_bNumConfigurations(VALUE v) { return INT2FIX(get_usb_device(v)->descriptor.bNumConfigurations); }
|
244
|
+
|
245
|
+
/* USB::Device#configurations */
|
246
|
+
static VALUE
|
247
|
+
rusb_device_config(VALUE v)
|
248
|
+
{
|
249
|
+
struct usb_device *device = get_usb_device(v);
|
250
|
+
int i;
|
251
|
+
VALUE children = rb_ary_new2(device->descriptor.bNumConfigurations);
|
252
|
+
for (i = 0; i < device->descriptor.bNumConfigurations; i++)
|
253
|
+
rb_ary_store(children, i, rusb_config_descriptor_make(&device->config[i], v));
|
254
|
+
return children;
|
255
|
+
}
|
256
|
+
|
257
|
+
/* USB::Device#usb_open */
|
258
|
+
static VALUE
|
259
|
+
rusb_device_open(VALUE vdevice)
|
260
|
+
{
|
261
|
+
struct usb_device *device = get_usb_device(vdevice);
|
262
|
+
usb_dev_handle *h = usb_open(device);
|
263
|
+
return rusb_dev_handle_new(h);
|
264
|
+
}
|
265
|
+
|
266
|
+
/* -------- USB::Configuration -------- */
|
267
|
+
|
268
|
+
/* USB::Configuration#revoked? */
|
269
|
+
static VALUE
|
270
|
+
rusb_config_revoked_p(VALUE v)
|
271
|
+
{
|
272
|
+
return RTEST(!check_usb_config_descriptor(v));
|
273
|
+
}
|
274
|
+
|
275
|
+
/* USB::Configuration#device */
|
276
|
+
static VALUE rusb_config_device(VALUE v) { return get_rusb_config_descriptor(v)->parent; }
|
277
|
+
|
278
|
+
/* USB::Configuration#bLength */
|
279
|
+
static VALUE rusb_config_bLength(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bLength); }
|
280
|
+
|
281
|
+
/* USB::Configuration#bDescriptorType */
|
282
|
+
static VALUE rusb_config_bDescriptorType(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bDescriptorType); }
|
283
|
+
|
284
|
+
/* USB::Configuration#wTotalLength */
|
285
|
+
static VALUE rusb_config_wTotalLength(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->wTotalLength); }
|
286
|
+
|
287
|
+
/* USB::Configuration#bNumInterfaces */
|
288
|
+
static VALUE rusb_config_bNumInterfaces(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bNumInterfaces); }
|
289
|
+
|
290
|
+
/* USB::Configuration#bConfigurationValue */
|
291
|
+
static VALUE rusb_config_bConfigurationValue(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bConfigurationValue); }
|
292
|
+
|
293
|
+
/* USB::Configuration#iConfiguration */
|
294
|
+
static VALUE rusb_config_iConfiguration(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->iConfiguration); }
|
295
|
+
|
296
|
+
/* USB::Configuration#bmAttributes */
|
297
|
+
static VALUE rusb_config_bmAttributes(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->bmAttributes); }
|
298
|
+
|
299
|
+
/* USB::Configuration#bMaxPower */
|
300
|
+
static VALUE rusb_config_bMaxPower(VALUE v) { return INT2FIX(get_usb_config_descriptor(v)->MaxPower); }
|
301
|
+
|
302
|
+
/* USB::Configuration#interfaces */
|
303
|
+
static VALUE
|
304
|
+
rusb_config_interfaces(VALUE v)
|
305
|
+
{
|
306
|
+
struct usb_config_descriptor *p = get_usb_config_descriptor(v);
|
307
|
+
int i;
|
308
|
+
VALUE interface = rb_ary_new2(p->bNumInterfaces);
|
309
|
+
for (i = 0; i < p->bNumInterfaces; i++)
|
310
|
+
rb_ary_store(interface, i, rusb_interface_make(&p->interface[i], v));
|
311
|
+
return interface;
|
312
|
+
}
|
313
|
+
|
314
|
+
/* -------- USB::Interface -------- */
|
315
|
+
|
316
|
+
/* USB::Interface#revoked? */
|
317
|
+
static VALUE
|
318
|
+
rusb_interface_revoked_p(VALUE v)
|
319
|
+
{
|
320
|
+
return RTEST(!check_usb_interface(v));
|
321
|
+
}
|
322
|
+
|
323
|
+
/* USB::Interface#configuration */
|
324
|
+
static VALUE rusb_interface_configuration(VALUE v) { return get_rusb_interface(v)->parent; }
|
325
|
+
|
326
|
+
/* USB::Interface#num_altsetting */
|
327
|
+
static VALUE rusb_interface_num_altsetting(VALUE v) { return INT2FIX(get_usb_interface(v)->num_altsetting); }
|
328
|
+
|
329
|
+
/* USB::Interface#settings */
|
330
|
+
static VALUE
|
331
|
+
rusb_interface_settings(VALUE v)
|
332
|
+
{
|
333
|
+
struct usb_interface *p = get_usb_interface(v);
|
334
|
+
int i;
|
335
|
+
VALUE altsetting = rb_ary_new2(p->num_altsetting);
|
336
|
+
for (i = 0; i < p->num_altsetting; i++)
|
337
|
+
rb_ary_store(altsetting, i, rusb_interface_descriptor_make(&p->altsetting[i], v));
|
338
|
+
return altsetting;
|
339
|
+
}
|
340
|
+
|
341
|
+
/* -------- USB::Setting -------- */
|
342
|
+
|
343
|
+
/* USB::Setting#revoked? */
|
344
|
+
static VALUE
|
345
|
+
rusb_setting_revoked_p(VALUE v)
|
346
|
+
{
|
347
|
+
return RTEST(!check_usb_interface_descriptor(v));
|
348
|
+
}
|
349
|
+
|
350
|
+
/* USB::Interface#interface */
|
351
|
+
static VALUE rusb_setting_interface(VALUE v) { return get_rusb_interface_descriptor(v)->parent; }
|
352
|
+
|
353
|
+
/* USB::Setting#bLength */
|
354
|
+
static VALUE rusb_setting_bLength(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bLength); }
|
355
|
+
|
356
|
+
/* USB::Setting#bDescriptorType */
|
357
|
+
static VALUE rusb_setting_bDescriptorType(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bDescriptorType); }
|
358
|
+
|
359
|
+
/* USB::Setting#bInterfaceNumber */
|
360
|
+
static VALUE rusb_setting_bInterfaceNumber(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceNumber); }
|
361
|
+
|
362
|
+
/* USB::Setting#bAlternateSetting */
|
363
|
+
static VALUE rusb_setting_bAlternateSetting(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bAlternateSetting); }
|
364
|
+
|
365
|
+
/* USB::Setting#bNumEndpoints */
|
366
|
+
static VALUE rusb_setting_bNumEndpoints(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bNumEndpoints); }
|
367
|
+
|
368
|
+
/* USB::Setting#bInterfaceClass */
|
369
|
+
static VALUE rusb_setting_bInterfaceClass(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceClass); }
|
370
|
+
|
371
|
+
/* USB::Setting#bInterfaceSubClass */
|
372
|
+
static VALUE rusb_setting_bInterfaceSubClass(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceSubClass); }
|
373
|
+
|
374
|
+
/* USB::Setting#bInterfaceProtocol */
|
375
|
+
static VALUE rusb_setting_bInterfaceProtocol(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->bInterfaceProtocol); }
|
376
|
+
|
377
|
+
/* USB::Setting#iInterface */
|
378
|
+
static VALUE rusb_setting_iInterface(VALUE v) { return INT2FIX(get_usb_interface_descriptor(v)->iInterface); }
|
379
|
+
|
380
|
+
/* USB::Setting#endpoints */
|
381
|
+
static VALUE
|
382
|
+
rusb_setting_endpoints(VALUE v)
|
383
|
+
{
|
384
|
+
struct usb_interface_descriptor *p = get_usb_interface_descriptor(v);
|
385
|
+
int i;
|
386
|
+
VALUE endpoint = rb_ary_new2(p->bNumEndpoints);
|
387
|
+
for (i = 0; i < p->bNumEndpoints; i++)
|
388
|
+
rb_ary_store(endpoint, i, rusb_endpoint_descriptor_make(&p->endpoint[i], v));
|
389
|
+
return endpoint;
|
390
|
+
}
|
391
|
+
|
392
|
+
/* -------- USB::Endpoint -------- */
|
393
|
+
|
394
|
+
/* USB::Endpoint#revoked? */
|
395
|
+
static VALUE
|
396
|
+
rusb_endpoint_revoked_p(VALUE v)
|
397
|
+
{
|
398
|
+
return RTEST(!check_usb_endpoint_descriptor(v));
|
399
|
+
}
|
400
|
+
|
401
|
+
/* USB::Endpoint#setting */
|
402
|
+
static VALUE rusb_endpoint_setting(VALUE v) { return get_rusb_endpoint_descriptor(v)->parent; }
|
403
|
+
|
404
|
+
/* USB::Endpoint#bLength */
|
405
|
+
static VALUE rusb_endpoint_bLength(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bLength); }
|
406
|
+
|
407
|
+
/* USB::Endpoint#bDescriptorType */
|
408
|
+
static VALUE rusb_endpoint_bDescriptorType(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bDescriptorType); }
|
409
|
+
|
410
|
+
/* USB::Endpoint#bEndpointAddress */
|
411
|
+
static VALUE rusb_endpoint_bEndpointAddress(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bEndpointAddress); }
|
412
|
+
|
413
|
+
/* USB::Endpoint#bmAttributes */
|
414
|
+
static VALUE rusb_endpoint_bmAttributes(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bmAttributes); }
|
415
|
+
|
416
|
+
/* USB::Endpoint#wMaxPacketSize */
|
417
|
+
static VALUE rusb_endpoint_wMaxPacketSize(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->wMaxPacketSize); }
|
418
|
+
|
419
|
+
/* USB::Endpoint#bInterval */
|
420
|
+
static VALUE rusb_endpoint_bInterval(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bInterval); }
|
421
|
+
|
422
|
+
/* USB::Endpoint#bRefresh */
|
423
|
+
static VALUE rusb_endpoint_bRefresh(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bRefresh); }
|
424
|
+
|
425
|
+
/* USB::Endpoint#bSynchAddress */
|
426
|
+
static VALUE rusb_endpoint_bSynchAddress(VALUE v) { return INT2FIX(get_usb_endpoint_descriptor(v)->bSynchAddress); }
|
427
|
+
|
428
|
+
/* -------- USB::DevHandle -------- */
|
429
|
+
|
430
|
+
static VALUE rb_cUSB_DevHandle;
|
431
|
+
|
432
|
+
void rusb_devhandle_free(void *_h)
|
433
|
+
{
|
434
|
+
usb_dev_handle *h = (usb_dev_handle *)_h;
|
435
|
+
if (h) usb_close(h);
|
436
|
+
}
|
437
|
+
|
438
|
+
static VALUE
|
439
|
+
rusb_dev_handle_new(usb_dev_handle *h)
|
440
|
+
{
|
441
|
+
return Data_Wrap_Struct(rb_cUSB_DevHandle, 0, rusb_devhandle_free, h);
|
442
|
+
}
|
443
|
+
|
444
|
+
static usb_dev_handle *check_usb_devhandle(VALUE v)
|
445
|
+
{
|
446
|
+
Check_Type(v, T_DATA);
|
447
|
+
if (RDATA(v)->dfree != rusb_devhandle_free) {
|
448
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected USB::DevHandle)",
|
449
|
+
rb_class2name(CLASS_OF(v)));
|
450
|
+
}
|
451
|
+
return DATA_PTR(v);
|
452
|
+
}
|
453
|
+
|
454
|
+
static usb_dev_handle *get_usb_devhandle(VALUE v)
|
455
|
+
{
|
456
|
+
usb_dev_handle *p = check_usb_devhandle(v); \
|
457
|
+
if (!p) {
|
458
|
+
rb_raise(rb_eArgError, "closed USB::DevHandle");
|
459
|
+
}
|
460
|
+
return p;
|
461
|
+
}
|
462
|
+
|
463
|
+
static int check_usb_error(char *reason, int ret)
|
464
|
+
{
|
465
|
+
if (ret < 0) {
|
466
|
+
errno = -ret;
|
467
|
+
rb_sys_fail(reason);
|
468
|
+
}
|
469
|
+
return ret;
|
470
|
+
}
|
471
|
+
|
472
|
+
/* USB::DevHandle#usb_close */
|
473
|
+
static VALUE
|
474
|
+
rusb_close(VALUE v)
|
475
|
+
{
|
476
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
477
|
+
check_usb_error("usb_close", usb_close(p));
|
478
|
+
DATA_PTR(v) = NULL;
|
479
|
+
return Qnil;
|
480
|
+
}
|
481
|
+
|
482
|
+
/* USB::DevHandle#usb_set_configuration(configuration) */
|
483
|
+
static VALUE
|
484
|
+
rusb_set_configuration(VALUE v, VALUE configuration)
|
485
|
+
{
|
486
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
487
|
+
int ret = usb_set_configuration(p, NUM2INT(configuration));
|
488
|
+
check_usb_error("usb_set_configuration", ret);
|
489
|
+
return Qnil;
|
490
|
+
}
|
491
|
+
|
492
|
+
/* USB::DevHandle#usb_set_altinterface(alternate) */
|
493
|
+
static VALUE
|
494
|
+
rusb_set_altinterface(VALUE v, VALUE alternate)
|
495
|
+
{
|
496
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
497
|
+
int ret = usb_set_altinterface(p, NUM2INT(alternate));
|
498
|
+
check_usb_error("usb_set_altinterface", ret);
|
499
|
+
return Qnil;
|
500
|
+
}
|
501
|
+
|
502
|
+
/* USB::DevHandle#usb_clear_halt(endpoint) */
|
503
|
+
static VALUE
|
504
|
+
rusb_clear_halt(VALUE v, VALUE ep)
|
505
|
+
{
|
506
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
507
|
+
int ret = usb_clear_halt(p, NUM2UINT(ep));
|
508
|
+
check_usb_error("usb_clear_halt", ret);
|
509
|
+
return Qnil;
|
510
|
+
}
|
511
|
+
|
512
|
+
/* USB::DevHandle#usb_reset */
|
513
|
+
static VALUE
|
514
|
+
rusb_reset(VALUE v)
|
515
|
+
{
|
516
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
517
|
+
int ret = usb_reset(p);
|
518
|
+
check_usb_error("usb_reset", ret);
|
519
|
+
/* xxx: call usb_close? */
|
520
|
+
return Qnil;
|
521
|
+
}
|
522
|
+
|
523
|
+
/* USB::DevHandle#usb_claim_interface(interface) */
|
524
|
+
static VALUE
|
525
|
+
rusb_claim_interface(VALUE v, VALUE interface)
|
526
|
+
{
|
527
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
528
|
+
int ret = usb_claim_interface(p, NUM2INT(interface));
|
529
|
+
check_usb_error("usb_claim_interface", ret);
|
530
|
+
return Qnil;
|
531
|
+
}
|
532
|
+
|
533
|
+
/* USB::DevHandle#usb_release_interface(interface) */
|
534
|
+
static VALUE
|
535
|
+
rusb_release_interface(VALUE v, VALUE interface)
|
536
|
+
{
|
537
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
538
|
+
int ret = usb_release_interface(p, NUM2INT(interface));
|
539
|
+
check_usb_error("usb_release_interface", ret);
|
540
|
+
return Qnil;
|
541
|
+
}
|
542
|
+
|
543
|
+
/* USB::DevHandle#usb_control_msg(requesttype, request, value, index, bytes, timeout) */
|
544
|
+
static VALUE
|
545
|
+
rusb_control_msg(
|
546
|
+
VALUE v,
|
547
|
+
VALUE vrequesttype,
|
548
|
+
VALUE vrequest,
|
549
|
+
VALUE vvalue,
|
550
|
+
VALUE vindex,
|
551
|
+
VALUE vbytes,
|
552
|
+
VALUE vtimeout)
|
553
|
+
{
|
554
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
555
|
+
int requesttype = NUM2INT(vrequesttype);
|
556
|
+
int request = NUM2INT(vrequest);
|
557
|
+
int value = NUM2INT(vvalue);
|
558
|
+
int index = NUM2INT(vindex);
|
559
|
+
int timeout = NUM2INT(vtimeout);
|
560
|
+
char *bytes;
|
561
|
+
int size;
|
562
|
+
int ret;
|
563
|
+
StringValue(vbytes);
|
564
|
+
rb_str_modify(vbytes);
|
565
|
+
bytes = RSTRING_PTR(vbytes);
|
566
|
+
size = RSTRING_LEN(vbytes);
|
567
|
+
ret = usb_control_msg(p, requesttype, request, value, index, bytes, size, timeout);
|
568
|
+
check_usb_error("usb_control_msg", ret);
|
569
|
+
return INT2NUM(ret);
|
570
|
+
}
|
571
|
+
|
572
|
+
/* USB::DevHandle#usb_get_string(index, langid, buf) */
|
573
|
+
static VALUE
|
574
|
+
rusb_get_string(
|
575
|
+
VALUE v,
|
576
|
+
VALUE vindex,
|
577
|
+
VALUE vlangid,
|
578
|
+
VALUE vbuf)
|
579
|
+
{
|
580
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
581
|
+
int index = NUM2INT(vindex);
|
582
|
+
int langid = NUM2INT(vlangid);
|
583
|
+
char *buf;
|
584
|
+
int buflen;
|
585
|
+
int ret;
|
586
|
+
StringValue(vbuf);
|
587
|
+
rb_str_modify(vbuf);
|
588
|
+
buf = RSTRING_PTR(vbuf);
|
589
|
+
buflen = RSTRING_LEN(vbuf);
|
590
|
+
ret = usb_get_string(p, index, langid, buf, buflen);
|
591
|
+
check_usb_error("usb_get_string", ret);
|
592
|
+
return INT2NUM(ret);
|
593
|
+
}
|
594
|
+
|
595
|
+
/* USB::DevHandle#usb_get_string_simple(index, buf) */
|
596
|
+
static VALUE
|
597
|
+
rusb_get_string_simple(
|
598
|
+
VALUE v,
|
599
|
+
VALUE vindex,
|
600
|
+
VALUE vbuf)
|
601
|
+
{
|
602
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
603
|
+
int index = NUM2INT(vindex);
|
604
|
+
char *buf;
|
605
|
+
int buflen;
|
606
|
+
int ret;
|
607
|
+
StringValue(vbuf);
|
608
|
+
rb_str_modify(vbuf);
|
609
|
+
buf = RSTRING_PTR(vbuf);
|
610
|
+
buflen = RSTRING_LEN(vbuf);
|
611
|
+
ret = usb_get_string_simple(p, index, buf, buflen);
|
612
|
+
check_usb_error("usb_get_string_simple", ret);
|
613
|
+
return INT2NUM(ret);
|
614
|
+
}
|
615
|
+
|
616
|
+
/* USB::DevHandle#usb_get_descriptor(type, index, buf) */
|
617
|
+
static VALUE
|
618
|
+
rusb_get_descriptor(
|
619
|
+
VALUE v,
|
620
|
+
VALUE vtype,
|
621
|
+
VALUE vindex,
|
622
|
+
VALUE vbuf)
|
623
|
+
{
|
624
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
625
|
+
int type = NUM2INT(vtype);
|
626
|
+
int index = NUM2INT(vindex);
|
627
|
+
char *buf;
|
628
|
+
int buflen;
|
629
|
+
int ret;
|
630
|
+
StringValue(vbuf);
|
631
|
+
rb_str_modify(vbuf);
|
632
|
+
buf = RSTRING_PTR(vbuf);
|
633
|
+
buflen = RSTRING_LEN(vbuf);
|
634
|
+
ret = usb_get_descriptor(p, type, index, buf, buflen);
|
635
|
+
check_usb_error("usb_get_descriptor", ret);
|
636
|
+
return INT2NUM(ret);
|
637
|
+
}
|
638
|
+
|
639
|
+
/* USB::DevHandle#usb_get_descriptor_by_endpoint(endpoint, type, index, buf) */
|
640
|
+
static VALUE
|
641
|
+
rusb_get_descriptor_by_endpoint(
|
642
|
+
VALUE v,
|
643
|
+
VALUE vep,
|
644
|
+
VALUE vtype,
|
645
|
+
VALUE vindex,
|
646
|
+
VALUE vbuf)
|
647
|
+
{
|
648
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
649
|
+
int ep = NUM2INT(vep);
|
650
|
+
int type = NUM2INT(vtype);
|
651
|
+
int index = NUM2INT(vindex);
|
652
|
+
char *buf;
|
653
|
+
int buflen;
|
654
|
+
int ret;
|
655
|
+
StringValue(vbuf);
|
656
|
+
rb_str_modify(vbuf);
|
657
|
+
buf = RSTRING_PTR(vbuf);
|
658
|
+
buflen = RSTRING_LEN(vbuf);
|
659
|
+
ret = usb_get_descriptor_by_endpoint(p, ep, type, index, buf, buflen);
|
660
|
+
check_usb_error("usb_get_descriptor_by_endpoint", ret);
|
661
|
+
return INT2NUM(ret);
|
662
|
+
}
|
663
|
+
|
664
|
+
/* USB::DevHandle#usb_bulk_write(endpoint, bytes, timeout) */
|
665
|
+
static VALUE
|
666
|
+
rusb_bulk_write(
|
667
|
+
VALUE v,
|
668
|
+
VALUE vep,
|
669
|
+
VALUE vbytes,
|
670
|
+
VALUE vtimeout)
|
671
|
+
{
|
672
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
673
|
+
int ep = NUM2INT(vep);
|
674
|
+
int timeout = NUM2INT(vtimeout);
|
675
|
+
char *bytes;
|
676
|
+
int size;
|
677
|
+
int ret;
|
678
|
+
StringValue(vbytes);
|
679
|
+
bytes = RSTRING_PTR(vbytes);
|
680
|
+
size = RSTRING_LEN(vbytes);
|
681
|
+
ret = usb_bulk_write(p, ep, bytes, size, timeout);
|
682
|
+
check_usb_error("usb_bulk_write", ret);
|
683
|
+
return INT2NUM(ret);
|
684
|
+
}
|
685
|
+
|
686
|
+
/* USB::DevHandle#usb_bulk_read(endpoint, bytes, timeout) */
|
687
|
+
static VALUE
|
688
|
+
rusb_bulk_read(
|
689
|
+
VALUE v,
|
690
|
+
VALUE vep,
|
691
|
+
VALUE vbytes,
|
692
|
+
VALUE vtimeout)
|
693
|
+
{
|
694
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
695
|
+
int ep = NUM2INT(vep);
|
696
|
+
int timeout = NUM2INT(vtimeout);
|
697
|
+
char *bytes;
|
698
|
+
int size;
|
699
|
+
int ret;
|
700
|
+
StringValue(vbytes);
|
701
|
+
rb_str_modify(vbytes);
|
702
|
+
bytes = RSTRING_PTR(vbytes);
|
703
|
+
size = RSTRING_LEN(vbytes);
|
704
|
+
ret = usb_bulk_read(p, ep, bytes, size, timeout);
|
705
|
+
check_usb_error("usb_bulk_read", ret);
|
706
|
+
return INT2NUM(ret);
|
707
|
+
}
|
708
|
+
|
709
|
+
/* USB::DevHandle#usb_interrupt_write(endpoint, bytes, timeout) */
|
710
|
+
static VALUE
|
711
|
+
rusb_interrupt_write(
|
712
|
+
VALUE v,
|
713
|
+
VALUE vep,
|
714
|
+
VALUE vbytes,
|
715
|
+
VALUE vtimeout)
|
716
|
+
{
|
717
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
718
|
+
int ep = NUM2INT(vep);
|
719
|
+
int timeout = NUM2INT(vtimeout);
|
720
|
+
char *bytes;
|
721
|
+
int size;
|
722
|
+
int ret;
|
723
|
+
StringValue(vbytes);
|
724
|
+
bytes = RSTRING_PTR(vbytes);
|
725
|
+
size = RSTRING_LEN(vbytes);
|
726
|
+
ret = usb_interrupt_write(p, ep, bytes, size, timeout);
|
727
|
+
check_usb_error("usb_interrupt_write", ret);
|
728
|
+
return INT2NUM(ret);
|
729
|
+
}
|
730
|
+
|
731
|
+
/* USB::DevHandle#usb_interrupt_read(endpoint, bytes, timeout) */
|
732
|
+
static VALUE
|
733
|
+
rusb_interrupt_read(
|
734
|
+
VALUE v,
|
735
|
+
VALUE vep,
|
736
|
+
VALUE vbytes,
|
737
|
+
VALUE vtimeout)
|
738
|
+
{
|
739
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
740
|
+
int ep = NUM2INT(vep);
|
741
|
+
int timeout = NUM2INT(vtimeout);
|
742
|
+
char *bytes;
|
743
|
+
int size;
|
744
|
+
int ret;
|
745
|
+
StringValue(vbytes);
|
746
|
+
rb_str_modify(vbytes);
|
747
|
+
bytes = RSTRING_PTR(vbytes);
|
748
|
+
size = RSTRING_LEN(vbytes);
|
749
|
+
ret = usb_interrupt_read(p, ep, bytes, size, timeout);
|
750
|
+
check_usb_error("usb_interrupt_read", ret);
|
751
|
+
return INT2NUM(ret);
|
752
|
+
}
|
753
|
+
|
754
|
+
#ifdef LIBUSB_HAS_GET_DRIVER_NP
|
755
|
+
/* USB::DevHandle#usb_get_driver_np(interface, name) */
|
756
|
+
static VALUE
|
757
|
+
rusb_get_driver_np(
|
758
|
+
VALUE v,
|
759
|
+
VALUE vinterface,
|
760
|
+
VALUE vname)
|
761
|
+
{
|
762
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
763
|
+
int interface = NUM2INT(vinterface);
|
764
|
+
char *name;
|
765
|
+
int namelen;
|
766
|
+
int ret;
|
767
|
+
StringValue(vname);
|
768
|
+
rb_str_modify(vname);
|
769
|
+
name = RSTRING_PTR(vname);
|
770
|
+
namelen = RSTRING_LEN(vname);
|
771
|
+
ret = usb_get_driver_np(p, interface, name, namelen);
|
772
|
+
check_usb_error("usb_get_driver_np", ret);
|
773
|
+
return Qnil;
|
774
|
+
}
|
775
|
+
#endif
|
776
|
+
|
777
|
+
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
|
778
|
+
/* USB::DevHandle#usb_detach_kernel_driver_np(interface) */
|
779
|
+
static VALUE
|
780
|
+
rusb_detach_kernel_driver_np(
|
781
|
+
VALUE v,
|
782
|
+
VALUE vinterface)
|
783
|
+
{
|
784
|
+
usb_dev_handle *p = get_usb_devhandle(v);
|
785
|
+
int interface = NUM2INT(vinterface);
|
786
|
+
int ret;
|
787
|
+
ret = usb_detach_kernel_driver_np(p, interface);
|
788
|
+
check_usb_error("usb_detach_kernel_driver_np", ret);
|
789
|
+
return Qnil;
|
790
|
+
}
|
791
|
+
#endif
|
792
|
+
|
793
|
+
/* -------- libusb binding initialization -------- */
|
794
|
+
|
795
|
+
void
|
796
|
+
Init_usb()
|
797
|
+
{
|
798
|
+
rb_cUSB = rb_define_module("USB");
|
799
|
+
|
800
|
+
#define f(name) rb_define_const(rb_cUSB, #name, INT2NUM(name));
|
801
|
+
#include "constants.h"
|
802
|
+
#undef f
|
803
|
+
|
804
|
+
bus_objects = st_init_numtable();
|
805
|
+
rb_cUSB_Bus = rb_define_class_under(rb_cUSB, "Bus", rb_cData);
|
806
|
+
|
807
|
+
device_objects = st_init_numtable();
|
808
|
+
rb_cUSB_Device = rb_define_class_under(rb_cUSB, "Device", rb_cData);
|
809
|
+
|
810
|
+
config_descriptor_objects = st_init_numtable();
|
811
|
+
rb_cUSB_Configuration = rb_define_class_under(rb_cUSB, "Configuration", rb_cData);
|
812
|
+
|
813
|
+
interface_objects = st_init_numtable();
|
814
|
+
rb_cUSB_Interface = rb_define_class_under(rb_cUSB, "Interface", rb_cData);
|
815
|
+
|
816
|
+
interface_descriptor_objects = st_init_numtable();
|
817
|
+
rb_cUSB_Setting = rb_define_class_under(rb_cUSB, "Setting", rb_cData);
|
818
|
+
|
819
|
+
endpoint_descriptor_objects = st_init_numtable();
|
820
|
+
rb_cUSB_Endpoint = rb_define_class_under(rb_cUSB, "Endpoint", rb_cData);
|
821
|
+
|
822
|
+
rb_cUSB_DevHandle = rb_define_class_under(rb_cUSB, "DevHandle", rb_cData);
|
823
|
+
|
824
|
+
rusb_gc_root = Data_Wrap_Struct(0, rusb_gc_mark, 0, 0); \
|
825
|
+
rb_global_variable(&rusb_gc_root);
|
826
|
+
|
827
|
+
usb_init();
|
828
|
+
usb_find_busses(); /* xxx: return value */
|
829
|
+
usb_find_devices(); /* xxx: return value */
|
830
|
+
|
831
|
+
rb_define_module_function(rb_cUSB, "find_busses", rusb_find_busses, 0);
|
832
|
+
rb_define_module_function(rb_cUSB, "find_devices", rusb_find_devices, 0);
|
833
|
+
rb_define_module_function(rb_cUSB, "first_bus", rusb_first_bus, 0);
|
834
|
+
|
835
|
+
rb_define_method(rb_cUSB_Bus, "revoked?", rusb_bus_revoked_p, 0);
|
836
|
+
rb_define_method(rb_cUSB_Bus, "prev", rusb_bus_prev, 0);
|
837
|
+
rb_define_method(rb_cUSB_Bus, "next", rusb_bus_next, 0);
|
838
|
+
rb_define_method(rb_cUSB_Bus, "dirname", rusb_bus_dirname, 0);
|
839
|
+
rb_define_method(rb_cUSB_Bus, "location", rusb_bus_location, 0);
|
840
|
+
rb_define_method(rb_cUSB_Bus, "first_device", rusb_bus_first_device, 0);
|
841
|
+
|
842
|
+
rb_define_method(rb_cUSB_Device, "revoked?", rusb_device_revoked_p, 0);
|
843
|
+
rb_define_method(rb_cUSB_Device, "prev", rusb_device_prev, 0);
|
844
|
+
rb_define_method(rb_cUSB_Device, "next", rusb_device_next, 0);
|
845
|
+
rb_define_method(rb_cUSB_Device, "filename", rusb_device_filename, 0);
|
846
|
+
rb_define_method(rb_cUSB_Device, "bus", rusb_device_bus, 0);
|
847
|
+
rb_define_method(rb_cUSB_Device, "devnum", rusb_device_devnum, 0);
|
848
|
+
rb_define_method(rb_cUSB_Device, "num_children", rusb_device_num_children, 0);
|
849
|
+
rb_define_method(rb_cUSB_Device, "children", rusb_device_children, 0);
|
850
|
+
rb_define_method(rb_cUSB_Device, "bLength", rusb_devdesc_bLength, 0);
|
851
|
+
rb_define_method(rb_cUSB_Device, "bDescriptorType", rusb_devdesc_bDescriptorType, 0);
|
852
|
+
rb_define_method(rb_cUSB_Device, "bcdUSB", rusb_devdesc_bcdUSB, 0);
|
853
|
+
rb_define_method(rb_cUSB_Device, "bDeviceClass", rusb_devdesc_bDeviceClass, 0);
|
854
|
+
rb_define_method(rb_cUSB_Device, "bDeviceSubClass", rusb_devdesc_bDeviceSubClass, 0);
|
855
|
+
rb_define_method(rb_cUSB_Device, "bDeviceProtocol", rusb_devdesc_bDeviceProtocol, 0);
|
856
|
+
rb_define_method(rb_cUSB_Device, "bMaxPacketSize0", rusb_devdesc_bMaxPacketSize0, 0);
|
857
|
+
rb_define_method(rb_cUSB_Device, "idVendor", rusb_devdesc_idVendor, 0);
|
858
|
+
rb_define_method(rb_cUSB_Device, "idProduct", rusb_devdesc_idProduct, 0);
|
859
|
+
rb_define_method(rb_cUSB_Device, "bcdDevice", rusb_devdesc_bcdDevice, 0);
|
860
|
+
rb_define_method(rb_cUSB_Device, "iManufacturer", rusb_devdesc_iManufacturer, 0);
|
861
|
+
rb_define_method(rb_cUSB_Device, "iProduct", rusb_devdesc_iProduct, 0);
|
862
|
+
rb_define_method(rb_cUSB_Device, "iSerialNumber", rusb_devdesc_iSerialNumber, 0);
|
863
|
+
rb_define_method(rb_cUSB_Device, "bNumConfigurations", rusb_devdesc_bNumConfigurations, 0);
|
864
|
+
rb_define_method(rb_cUSB_Device, "configurations", rusb_device_config, 0);
|
865
|
+
rb_define_method(rb_cUSB_Device, "usb_open", rusb_device_open, 0);
|
866
|
+
|
867
|
+
rb_define_method(rb_cUSB_Configuration, "revoked?", rusb_config_revoked_p, 0);
|
868
|
+
rb_define_method(rb_cUSB_Configuration, "device", rusb_config_device, 0);
|
869
|
+
rb_define_method(rb_cUSB_Configuration, "bLength", rusb_config_bLength, 0);
|
870
|
+
rb_define_method(rb_cUSB_Configuration, "bDescriptorType", rusb_config_bDescriptorType, 0);
|
871
|
+
rb_define_method(rb_cUSB_Configuration, "wTotalLength", rusb_config_wTotalLength, 0);
|
872
|
+
rb_define_method(rb_cUSB_Configuration, "bNumInterfaces", rusb_config_bNumInterfaces, 0);
|
873
|
+
rb_define_method(rb_cUSB_Configuration, "bConfigurationValue", rusb_config_bConfigurationValue, 0);
|
874
|
+
rb_define_method(rb_cUSB_Configuration, "iConfiguration", rusb_config_iConfiguration, 0);
|
875
|
+
rb_define_method(rb_cUSB_Configuration, "bmAttributes", rusb_config_bmAttributes, 0);
|
876
|
+
rb_define_method(rb_cUSB_Configuration, "bMaxPower", rusb_config_bMaxPower, 0);
|
877
|
+
rb_define_method(rb_cUSB_Configuration, "interfaces", rusb_config_interfaces, 0);
|
878
|
+
|
879
|
+
rb_define_method(rb_cUSB_Interface, "revoked?", rusb_interface_revoked_p, 0);
|
880
|
+
rb_define_method(rb_cUSB_Interface, "configuration", rusb_interface_configuration, 0);
|
881
|
+
rb_define_method(rb_cUSB_Interface, "num_altsetting", rusb_interface_num_altsetting, 0);
|
882
|
+
rb_define_method(rb_cUSB_Interface, "settings", rusb_interface_settings, 0);
|
883
|
+
|
884
|
+
rb_define_method(rb_cUSB_Setting, "revoked?", rusb_setting_revoked_p, 0);
|
885
|
+
rb_define_method(rb_cUSB_Setting, "interface", rusb_setting_interface, 0);
|
886
|
+
rb_define_method(rb_cUSB_Setting, "bLength", rusb_setting_bLength, 0);
|
887
|
+
rb_define_method(rb_cUSB_Setting, "bDescriptorType", rusb_setting_bDescriptorType, 0);
|
888
|
+
rb_define_method(rb_cUSB_Setting, "bInterfaceNumber", rusb_setting_bInterfaceNumber, 0);
|
889
|
+
rb_define_method(rb_cUSB_Setting, "bAlternateSetting", rusb_setting_bAlternateSetting, 0);
|
890
|
+
rb_define_method(rb_cUSB_Setting, "bNumEndpoints", rusb_setting_bNumEndpoints, 0);
|
891
|
+
rb_define_method(rb_cUSB_Setting, "bInterfaceClass", rusb_setting_bInterfaceClass, 0);
|
892
|
+
rb_define_method(rb_cUSB_Setting, "bInterfaceSubClass", rusb_setting_bInterfaceSubClass, 0);
|
893
|
+
rb_define_method(rb_cUSB_Setting, "bInterfaceProtocol", rusb_setting_bInterfaceProtocol, 0);
|
894
|
+
rb_define_method(rb_cUSB_Setting, "iInterface", rusb_setting_iInterface, 0);
|
895
|
+
rb_define_method(rb_cUSB_Setting, "endpoints", rusb_setting_endpoints, 0);
|
896
|
+
|
897
|
+
rb_define_method(rb_cUSB_Endpoint, "revoked?", rusb_endpoint_revoked_p, 0);
|
898
|
+
rb_define_method(rb_cUSB_Endpoint, "setting", rusb_endpoint_setting, 0);
|
899
|
+
rb_define_method(rb_cUSB_Endpoint, "bLength", rusb_endpoint_bLength, 0);
|
900
|
+
rb_define_method(rb_cUSB_Endpoint, "bDescriptorType", rusb_endpoint_bDescriptorType, 0);
|
901
|
+
rb_define_method(rb_cUSB_Endpoint, "bEndpointAddress", rusb_endpoint_bEndpointAddress, 0);
|
902
|
+
rb_define_method(rb_cUSB_Endpoint, "bmAttributes", rusb_endpoint_bmAttributes, 0);
|
903
|
+
rb_define_method(rb_cUSB_Endpoint, "wMaxPacketSize", rusb_endpoint_wMaxPacketSize, 0);
|
904
|
+
rb_define_method(rb_cUSB_Endpoint, "bInterval", rusb_endpoint_bInterval, 0);
|
905
|
+
rb_define_method(rb_cUSB_Endpoint, "bRefresh", rusb_endpoint_bRefresh, 0);
|
906
|
+
rb_define_method(rb_cUSB_Endpoint, "bSynchAddress", rusb_endpoint_bSynchAddress, 0);
|
907
|
+
|
908
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_close", rusb_close, 0);
|
909
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_set_configuration", rusb_set_configuration, 1);
|
910
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_set_altinterface", rusb_set_altinterface, 1);
|
911
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_clear_halt", rusb_clear_halt, 1);
|
912
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_reset", rusb_reset, 0);
|
913
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_claim_interface", rusb_claim_interface, 1);
|
914
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_release_interface", rusb_release_interface, 1);
|
915
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_control_msg", rusb_control_msg, 6);
|
916
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_get_string", rusb_get_string, 3);
|
917
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_get_string_simple", rusb_get_string_simple, 2);
|
918
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_get_descriptor", rusb_get_descriptor, 3);
|
919
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_get_descriptor_by_endpoint", rusb_get_descriptor_by_endpoint, 4);
|
920
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_bulk_write", rusb_bulk_write, 3);
|
921
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_bulk_read", rusb_bulk_read, 3);
|
922
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_interrupt_write", rusb_interrupt_write, 3);
|
923
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_interrupt_read", rusb_interrupt_read, 3);
|
924
|
+
|
925
|
+
#ifdef LIBUSB_HAS_GET_DRIVER_NP
|
926
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_get_driver_np", rusb_get_driver_np, 2);
|
927
|
+
#endif
|
928
|
+
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
|
929
|
+
rb_define_method(rb_cUSB_DevHandle, "usb_detach_kernel_driver_np", rusb_detach_kernel_driver_np, 2);
|
930
|
+
#endif
|
931
|
+
}
|