libusb 0.2.2-x86-mingw32 → 0.3.0-x86-mingw32
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/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/.yardopts +6 -1
- data/Gemfile +16 -0
- data/{History.txt → History.md} +28 -16
- data/README.md +144 -0
- data/Rakefile +28 -24
- data/ext/extconf.rb +33 -0
- data/lib/libusb.rb +2 -3
- data/lib/libusb/call.rb +49 -7
- data/lib/libusb/compat.rb +15 -9
- data/lib/libusb/configuration.rb +15 -3
- data/lib/libusb/constants.rb +19 -6
- data/lib/libusb/context.rb +181 -3
- data/lib/libusb/dev_handle.rb +91 -40
- data/lib/libusb/endpoint.rb +41 -14
- data/lib/libusb/eventmachine.rb +183 -0
- data/lib/libusb/transfer.rb +21 -8
- data/lib/libusb/version_gem.rb +19 -0
- data/lib/libusb/{version.rb → version_struct.rb} +0 -0
- data/libusb.gemspec +31 -0
- data/test/test_libusb_compat.rb +1 -1
- data/test/test_libusb_compat_mass_storage.rb +2 -2
- data/test/test_libusb_descriptors.rb +1 -1
- data/test/test_libusb_event_machine.rb +118 -0
- data/test/test_libusb_iso_transfer.rb +6 -1
- data/test/test_libusb_mass_storage.rb +9 -3
- data/test/test_libusb_mass_storage2.rb +1 -1
- data/test/test_libusb_structs.rb +45 -0
- data/test/test_libusb_threads.rb +89 -0
- data/test/test_libusb_version.rb +4 -0
- metadata +44 -44
- data/.autotest +0 -23
- data/.gemtest +0 -0
- data/Manifest.txt +0 -3
- data/README.rdoc +0 -115
- data/test/test_libusb_keyboard.rb +0 -50
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
CHANGED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in libusb.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'eventmachine'
|
8
|
+
end
|
9
|
+
|
10
|
+
platforms :rbx do
|
11
|
+
# travis currently runs a slightly older version of rbx,
|
12
|
+
# that needs this special ffi version.
|
13
|
+
if ENV['TRAVIS']
|
14
|
+
gem 'ffi', :git => "git://github.com/ffi/ffi.git", :ref => '5f31908'
|
15
|
+
end
|
16
|
+
end
|
data/{History.txt → History.md}
RENAMED
@@ -1,40 +1,52 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
0.3.0 / 2013-01-21
|
2
|
+
------------------
|
3
|
+
* Build bundled libusbx sources in case libusb-1.0.so can not be loaded from the system
|
4
|
+
* Replace Hoe with Bundler
|
5
|
+
* Add timeout and completion_flag to Context#handle_events
|
6
|
+
* Add asynchronous DevHandle#{control|interrupt|bulk}_transfer method variants
|
7
|
+
* Add the ability to retrieve the data already transfered when it comes to an exception
|
8
|
+
* Add notification API for libusb's file describtors for event driven USB transfers
|
9
|
+
* Add experimental integration to EventMachine
|
10
|
+
* Add several convenience methods to descriptors
|
11
|
+
* Add missing return code checks to libusb_init() and libusb_get_device_list()
|
12
|
+
|
13
|
+
0.2.2 / 2012-10-19
|
14
|
+
------------------
|
3
15
|
* Add method Interface#bInterfaceNumber
|
4
16
|
* Fix methods (#claim_interface, #detach_kernel_driver) with Interface-type parameter
|
5
17
|
* update to libusbx-1.0.14 for windows build
|
6
18
|
|
7
|
-
|
8
|
-
|
19
|
+
0.2.1 / 2012-09-25
|
20
|
+
------------------
|
9
21
|
* Rename Configuration#maxPower to #bMaxPower as done in libusbx-1.0.13 and in ruby-usb.gem
|
10
22
|
* update to libusbx-1.0.13 for windows build (with support for libusbK and libusb0)
|
11
23
|
|
12
|
-
|
13
|
-
|
24
|
+
0.2.0 / 2012-06-15
|
25
|
+
------------------
|
14
26
|
* Divide up the libusb library across multiple files, required with autoload
|
15
27
|
* add methods: LIBUSB.has_capability?, Device#device_speed (libusb-1.0.9+)
|
16
28
|
* add possibility to read out libusb version: LIBUSB.version (libusbx-1.0.10+)
|
17
29
|
* add methods: Device#parent, Device#port_number, Device#port_path (libusbx-1.0.12+)
|
18
30
|
* switch to libusbx-1.0.12 for windows build
|
19
31
|
|
20
|
-
|
21
|
-
|
32
|
+
0.1.3 / 2012-03-15
|
33
|
+
-------------------
|
22
34
|
* Add documentation of descriptor accessors
|
23
35
|
* Fix #extra accessor of Configuration, Setting and Endpoint
|
24
36
|
|
25
|
-
|
26
|
-
|
37
|
+
0.1.2 / 2012-03-14
|
38
|
+
------------------
|
27
39
|
* Mark all blocking functions as blocking in FFI, so that parallel threads are not blocked
|
28
40
|
* Add method Device#open_interface
|
29
41
|
* Add block variant to #claim_interface
|
30
42
|
* update API documentation
|
31
43
|
|
32
|
-
|
33
|
-
|
44
|
+
0.1.1 / 2011-12-09
|
45
|
+
------------------
|
34
46
|
* avoid ffi calls with :blocking=>true, als long as it isn't stable on win32
|
35
47
|
|
36
|
-
|
37
|
-
|
48
|
+
0.1.0 / 2011-10-01
|
49
|
+
------------------
|
38
50
|
* add test suite based on mass storage devices
|
39
51
|
* usable async transfers
|
40
52
|
* migration to rake-compiler and hoe
|
@@ -45,6 +57,6 @@
|
|
45
57
|
* add LIBUSB constants
|
46
58
|
* downcase methods names
|
47
59
|
|
48
|
-
|
49
|
-
|
60
|
+
0.0.1 / 2009-06-23
|
61
|
+
------------------
|
50
62
|
* first public release
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
<!-- -*- coding: utf-8 -*- -->
|
2
|
+
|
3
|
+
[](https://travis-ci.org/larskanis/libusb)
|
4
|
+
|
5
|
+
Access USB devices from Ruby
|
6
|
+
============================
|
7
|
+
|
8
|
+
LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary USB devices.
|
9
|
+
|
10
|
+
* [libusb](http://libusbx.org) is a library that gives full access to devices connected via the USB bus. No special kernel driver is thus necessary for accessing USB devices.
|
11
|
+
* This Ruby binding supports the API version 1.0 of [libusb](http://libusbx.org). Note that the old "legacy" version 0.1.x of libusb uses a completely different API that is covered by the ruby extension [ruby-usb](http://www.a-k-r.org/ruby-usb/) .
|
12
|
+
|
13
|
+
|
14
|
+
LIBUSB for Ruby is covered by the GNU Lesser General Public License version 3.
|
15
|
+
|
16
|
+
Features
|
17
|
+
--------
|
18
|
+
|
19
|
+
* Access to descriptors of devices, configurations, interfaces, settings and endpoints
|
20
|
+
* Synchronous and asynchronous communication for bulk, control, interrupt and isochronous transfers
|
21
|
+
* Compatibility layer for [ruby-usb](http://www.a-k-r.org/ruby-usb/) (API based on libusb-0.1). See {::USB} for description.
|
22
|
+
|
23
|
+
Synopsis
|
24
|
+
--------
|
25
|
+
See [the documentation](http://rubydoc.info/gems/libusb/frames) for a full API description.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require "libusb"
|
29
|
+
|
30
|
+
usb = LIBUSB::Context.new
|
31
|
+
device = usb.devices(:idVendor => 0x04b4, :idProduct => 0x8613).first
|
32
|
+
device.open_interface(0) do |handle|
|
33
|
+
handle.control_transfer(:bmRequestType => 0x40, :bRequest => 0xa0, :wValue => 0xe600, :wIndex => 0x0000, :dataOut => 1.chr)
|
34
|
+
end
|
35
|
+
```
|
36
|
+
{LIBUSB::Context#devices} is used to get all or only particular devices.
|
37
|
+
After {LIBUSB::Device#open_interface opening and claiming} the {LIBUSB::Device} the resulting {LIBUSB::DevHandle} can be
|
38
|
+
used to communicate with the connected USB device
|
39
|
+
by {LIBUSB::DevHandle#control_transfer}, {LIBUSB::DevHandle#bulk_transfer},
|
40
|
+
{LIBUSB::DevHandle#interrupt_transfer} or by using the {LIBUSB::Transfer} classes.
|
41
|
+
|
42
|
+
A {LIBUSB::Device} can also be used to retrieve information about it,
|
43
|
+
by using the device descriptor attributes.
|
44
|
+
A {LIBUSB::Device} could have several configurations. You can then decide of which
|
45
|
+
configuration to enable. You can only enable one configuration at a time.
|
46
|
+
|
47
|
+
Each {LIBUSB::Configuration} has one or more interfaces. These can be seen as functional group
|
48
|
+
performing a single feature of the device.
|
49
|
+
|
50
|
+
Each {LIBUSB::Interface} has at least one {LIBUSB::Setting}. The first setting is always default.
|
51
|
+
An alternate setting can be used independent on each interface.
|
52
|
+
|
53
|
+
Each {LIBUSB::Setting} specifies it's own set of communication endpoints.
|
54
|
+
Each {LIBUSB::Endpoint} specifies the type of transfer, direction, polling interval and
|
55
|
+
maximum packet size.
|
56
|
+
|
57
|
+
|
58
|
+
Prerequisites
|
59
|
+
-------------
|
60
|
+
|
61
|
+
* Linux, MacOSX or Windows system with Ruby MRI 1.8.7/1.9.x, JRuby or recent version of Rubinius
|
62
|
+
* [libusb](http://libusb.org) or [libusbx](http://libusbx.org) library version 1.0.8+ :
|
63
|
+
* Debian or Ubuntu:
|
64
|
+
|
65
|
+
```
|
66
|
+
$ sudo apt-get install libusb-1.0-0-dev
|
67
|
+
```
|
68
|
+
* OS-X: install with homebrew:
|
69
|
+
|
70
|
+
```
|
71
|
+
$ brew install libusb
|
72
|
+
```
|
73
|
+
or macports:
|
74
|
+
|
75
|
+
```
|
76
|
+
$ port install libusb
|
77
|
+
```
|
78
|
+
* Windows: libusb.gem already comes with a precompiled `libusb.dll`, but you need to install a device driver (see below)
|
79
|
+
|
80
|
+
|
81
|
+
Install
|
82
|
+
-------
|
83
|
+
|
84
|
+
$ gem install libusb
|
85
|
+
|
86
|
+
Latest code can be used in this way:
|
87
|
+
|
88
|
+
$ git clone git://github.com/larskanis/libusb.git
|
89
|
+
$ rake install_gem
|
90
|
+
|
91
|
+
|
92
|
+
Usage on Windows
|
93
|
+
----------------
|
94
|
+
|
95
|
+
In contrast to Linux, any access to an USB device by LIBUSB on Windows requires a proper driver
|
96
|
+
installed in the system. Fortunately creating such a driver is quite easy with
|
97
|
+
[Zadig](http://sourceforge.net/projects/libwdi/files/zadig/). Select the interesting USB device,
|
98
|
+
choose WinUSB driver and press "Install Driver". That's it. You may take the generated output directory
|
99
|
+
with it's INI-file and use it for driver installation on other 32 or 64 bit Windows
|
100
|
+
systems.
|
101
|
+
|
102
|
+
|
103
|
+
Cross compiling for Windows
|
104
|
+
---------------------------
|
105
|
+
|
106
|
+
Libusb-gem can be build on a linux or darwin host for the win32 platform,
|
107
|
+
using the mingw cross compiler collection. Libusb is downloaded from source
|
108
|
+
git repo, cross compiled and included in the generated libusb.gem.
|
109
|
+
|
110
|
+
Install mingw32. On a debian based system this should work:
|
111
|
+
|
112
|
+
$ apt-get install mingw32
|
113
|
+
|
114
|
+
On MacOS X, if you have MacPorts installed:
|
115
|
+
|
116
|
+
$ port install i386-mingw32-gcc
|
117
|
+
|
118
|
+
Download and cross compile libusb for win32:
|
119
|
+
|
120
|
+
$ rake cross gem
|
121
|
+
|
122
|
+
If everything works, there should be `libusb-VERSION-x86-mingw32.gem` in the pkg
|
123
|
+
directory.
|
124
|
+
|
125
|
+
EventMachine integration
|
126
|
+
------------------------
|
127
|
+
|
128
|
+
Libusb for Ruby comes with an experimental integration to [EventMachine](http://rubyeventmachine.com/).
|
129
|
+
That API is currently proof of concept - see {LIBUSB::Context#eventmachine_register}.
|
130
|
+
If you're experienced with EventMachine, please leave a comment.
|
131
|
+
|
132
|
+
|
133
|
+
Resources
|
134
|
+
---------
|
135
|
+
|
136
|
+
* Project's home page: http://github.com/larskanis/libusb
|
137
|
+
* API documentation: http://rubydoc.info/gems/libusb/frames
|
138
|
+
* Mailinglist: http://rubyforge.org/mailman/listinfo/libusb-hackers
|
139
|
+
* Overall introduction to USB: http://www.usbmadesimple.co.uk
|
140
|
+
|
141
|
+
Todo
|
142
|
+
----
|
143
|
+
|
144
|
+
* stabilize EventMachine interface
|
data/Rakefile
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# -*- ruby -*-
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'hoe'
|
4
|
+
require 'bundler/gem_tasks'
|
6
5
|
require 'pathname'
|
7
6
|
require 'uri'
|
8
7
|
require 'rake/extensiontask'
|
9
8
|
require 'rake/extensioncompiler'
|
10
9
|
|
10
|
+
task :gem => :build
|
11
|
+
task :compile do
|
12
|
+
sh "ruby ext/extconf.rb"
|
13
|
+
end
|
14
|
+
task :test=>:compile do
|
15
|
+
sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"
|
16
|
+
end
|
17
|
+
travis_tests = %w[test_libusb_capability.rb test_libusb_structs.rb test_libusb_version.rb]
|
18
|
+
task :travis=>:compile do
|
19
|
+
sh "ruby -w -W2 -I. -Ilib -e \"#{travis_tests.map{|f| "require 'test/#{f}';"}.join}\" -- -v"
|
20
|
+
end
|
21
|
+
task :default => :test
|
11
22
|
|
12
23
|
# Cross-compilation constants
|
13
24
|
COMPILE_HOME = Pathname( "./tmp" ).expand_path
|
@@ -45,28 +56,10 @@ LIBUSB_TARBALL = STATIC_SOURCESDIR + File.basename( LIBUSB_SOURCE_URI
|
|
45
56
|
STATIC_LIBUSB_BUILDDIR = STATIC_BUILDDIR + LIBUSB_TARBALL.basename(".tar.bz2")
|
46
57
|
LIBUSB_CONFIGURE = STATIC_LIBUSB_BUILDDIR + 'configure'
|
47
58
|
LIBUSB_MAKEFILE = STATIC_LIBUSB_BUILDDIR + 'Makefile'
|
48
|
-
LIBUSB_DLL
|
49
|
-
|
50
|
-
|
51
|
-
hoe = Hoe.spec 'libusb' do
|
52
|
-
developer('Lars Kanis', 'kanis@comcard.de')
|
53
|
-
|
54
|
-
extra_deps << ['ffi', '>= 1.0']
|
55
|
-
extra_dev_deps << ['rake-compiler', '>= 0.6']
|
56
|
-
|
57
|
-
self.url = 'http://github.com/larskanis/libusb'
|
58
|
-
self.summary = 'Access USB devices from Ruby via libusb-1.0'
|
59
|
-
self.description = 'LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary USB devices'
|
60
|
-
|
61
|
-
self.readme_file = 'README.rdoc'
|
62
|
-
spec_extras[:rdoc_options] = ['--main', readme_file, "--charset=UTF-8"]
|
63
|
-
spec_extras[:files] = `git ls-files`.split
|
64
|
-
self.extra_rdoc_files << self.readme_file
|
65
|
-
|
66
|
-
# clean intermediate files and folders
|
67
|
-
self.clean_globs << STATIC_BUILDDIR.to_s
|
68
|
-
end
|
59
|
+
LIBUSB_DLL = STATIC_LIBUSB_BUILDDIR + 'libusb/.libs/libusb-1.0.dll'
|
69
60
|
|
61
|
+
EXT_BUILDDIR = Pathname( "./ext" ).expand_path
|
62
|
+
EXT_LIBUSB_BUILDDIR = EXT_BUILDDIR + LIBUSB_TARBALL.basename(".tar.bz2")
|
70
63
|
|
71
64
|
#####################################################################
|
72
65
|
### C R O S S - C O M P I L A T I O N - T A S K S
|
@@ -135,10 +128,11 @@ task :libusb_dll => [ "copy:libusb_dll" ]
|
|
135
128
|
|
136
129
|
desc 'Cross compile libusb for win32'
|
137
130
|
task :cross => [ :mingw32, :libusb_dll ] do |t|
|
138
|
-
spec =
|
131
|
+
spec = Gem::Specification::load("libusb.gemspec")
|
139
132
|
spec.instance_variable_set(:"@cache_file", nil) if spec.respond_to?(:cache_file)
|
140
133
|
spec.platform = Gem::Platform.new('i386-mingw32')
|
141
134
|
spec.files << "lib/#{File.basename(LIBUSB_DLL)}"
|
135
|
+
spec.files -= `git ls-files ext/libusbx-*`.split("\n")
|
142
136
|
|
143
137
|
# Generate a package for this gem
|
144
138
|
Gem::PackageTask.new(spec) do |pkg|
|
@@ -156,4 +150,14 @@ task :mingw32 do
|
|
156
150
|
end
|
157
151
|
end
|
158
152
|
|
153
|
+
desc "Download and update bundled libusb(x)"
|
154
|
+
task :update_libusb => LIBUSB_TARBALL do
|
155
|
+
sh 'rm', '-r', (EXT_BUILDDIR + "libusbx-*").to_s do end
|
156
|
+
sh 'git', 'rm', '-rfq', (EXT_BUILDDIR + "libusbx-*").to_s do end
|
157
|
+
sh 'tar', '-xjf', LIBUSB_TARBALL.to_s, '-C', EXT_LIBUSB_BUILDDIR.parent.to_s
|
158
|
+
drops = %w[msvc].map{|f| (EXT_LIBUSB_BUILDDIR+f).to_s }
|
159
|
+
sh 'rm', '-r', '-f', *drops
|
160
|
+
sh 'git', 'add', EXT_LIBUSB_BUILDDIR.to_s
|
161
|
+
end
|
162
|
+
|
159
163
|
# vim: syntax=ruby
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ffi'
|
5
|
+
|
6
|
+
begin
|
7
|
+
module LibTest
|
8
|
+
extend FFI::Library
|
9
|
+
ext = FFI::Platform.windows? ? 'dll' : 'so'
|
10
|
+
bundled_dll = File.expand_path("../../lib/libusb-1.0.#{ext}", __FILE__)
|
11
|
+
ffi_lib(['libusb-1.0', bundled_dll])
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
# Unable to load libusb library on this system,
|
15
|
+
# so we build our bundled version:
|
16
|
+
|
17
|
+
libusb_dir = Dir[File.expand_path('../../ext/libusbx-*', __FILE__)].first
|
18
|
+
root_dir = File.expand_path('../..', __FILE__)
|
19
|
+
raise "could not find embedded libusb sources" unless libusb_dir
|
20
|
+
|
21
|
+
old_dir = Dir.pwd
|
22
|
+
Dir.chdir libusb_dir
|
23
|
+
cmd = "./configure --prefix=#{root_dir} && make && make install"
|
24
|
+
puts cmd
|
25
|
+
system cmd
|
26
|
+
raise "libusb build exited with #{$?.exitstatus}" if $?.exitstatus!=0
|
27
|
+
Dir.chdir old_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
File.open("Makefile", "w") do |mf|
|
31
|
+
mf.puts "# Dummy makefile since libusb-1.0 is usable on this system"
|
32
|
+
mf.puts "all install::\n"
|
33
|
+
end
|
data/lib/libusb.rb
CHANGED
@@ -14,12 +14,11 @@
|
|
14
14
|
# along with Libusb for Ruby. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
16
|
module LIBUSB
|
17
|
-
VERSION = "0.2.2"
|
18
|
-
|
19
17
|
require 'libusb/call'
|
20
18
|
require 'libusb/constants'
|
21
19
|
require 'libusb/context'
|
22
|
-
autoload :
|
20
|
+
autoload :VERSION, 'libusb/version_gem'
|
21
|
+
autoload :Version, 'libusb/version_struct'
|
23
22
|
autoload :Configuration, 'libusb/configuration'
|
24
23
|
autoload :DevHandle, 'libusb/dev_handle'
|
25
24
|
autoload :Device, 'libusb/device'
|
data/lib/libusb/call.rb
CHANGED
@@ -17,16 +17,15 @@ require 'rubygems'
|
|
17
17
|
require 'ffi'
|
18
18
|
|
19
19
|
module LIBUSB
|
20
|
-
# C level interface
|
20
|
+
# C level interface - for internal use only
|
21
|
+
#
|
22
|
+
# All enum codes are available as constants in {LIBUSB} namespace.
|
21
23
|
module Call
|
22
24
|
extend FFI::Library
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
ffi_lib 'libusb-1.0'
|
29
|
-
end
|
26
|
+
ext = FFI::Platform.windows? ? 'dll' : 'so'
|
27
|
+
bundled_dll = File.expand_path("../../libusb-1.0.#{ext}", __FILE__)
|
28
|
+
ffi_lib(['libusb-1.0', bundled_dll])
|
30
29
|
|
31
30
|
ClassCodes = enum :libusb_class_code, [
|
32
31
|
:CLASS_PER_INTERFACE, 0,
|
@@ -211,7 +210,16 @@ module LIBUSB
|
|
211
210
|
attach_function 'libusb_free_transfer', [:pointer], :void
|
212
211
|
|
213
212
|
attach_function 'libusb_handle_events', [:libusb_context], :int, :blocking=>true
|
213
|
+
try_attach_function 'libusb_handle_events_completed', [:libusb_context, :pointer], :int, :blocking=>true
|
214
|
+
attach_function 'libusb_handle_events_timeout', [:libusb_context, :pointer], :int, :blocking=>true
|
215
|
+
try_attach_function 'libusb_handle_events_timeout_completed', [:libusb_context, :pointer, :pointer], :int, :blocking=>true
|
216
|
+
|
217
|
+
callback :libusb_pollfd_added_cb, [:int, :short, :pointer], :void
|
218
|
+
callback :libusb_pollfd_removed_cb, [:int, :pointer], :void
|
214
219
|
|
220
|
+
attach_function 'libusb_get_pollfds', [:libusb_context], :pointer
|
221
|
+
attach_function 'libusb_get_next_timeout', [:libusb_context, :pointer], :int
|
222
|
+
attach_function 'libusb_set_pollfd_notifiers', [:libusb_context, :libusb_pollfd_added_cb, :libusb_pollfd_removed_cb, :pointer], :void
|
215
223
|
|
216
224
|
callback :libusb_transfer_cb_fn, [:pointer], :void
|
217
225
|
|
@@ -267,5 +275,39 @@ module LIBUSB
|
|
267
275
|
:iSerialNumber, :uint8,
|
268
276
|
:bNumConfigurations, :uint8
|
269
277
|
end
|
278
|
+
|
279
|
+
class Timeval < FFI::Struct
|
280
|
+
layout :tv_sec, :long,
|
281
|
+
:tv_usec, :long
|
282
|
+
|
283
|
+
# set timeval to the number of milliseconds
|
284
|
+
# @param [Fixnum] value
|
285
|
+
def in_ms=(value)
|
286
|
+
self[:tv_sec], self[:tv_usec] = (value*1000).divmod(1000000)
|
287
|
+
end
|
288
|
+
|
289
|
+
# get the number of milliseconds in timeval
|
290
|
+
# @return [Fixnum]
|
291
|
+
def in_ms
|
292
|
+
self[:tv_sec]*1000 + self[:tv_usec]/1000
|
293
|
+
end
|
294
|
+
|
295
|
+
# set timeval to the number of seconds
|
296
|
+
# @param [Numeric] value
|
297
|
+
def in_s=(value)
|
298
|
+
self[:tv_sec], self[:tv_usec] = (value*1000000).divmod(1000000)
|
299
|
+
end
|
300
|
+
|
301
|
+
# get the number of seconds in timeval
|
302
|
+
# @return [Float]
|
303
|
+
def in_s
|
304
|
+
self[:tv_sec] + self[:tv_usec]/1000000.0
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
class Pollfd < FFI::Struct
|
309
|
+
layout :fd, :int,
|
310
|
+
:events, :short
|
311
|
+
end
|
270
312
|
end
|
271
313
|
end
|