Module: HIDAPI
- Defined in:
- lib/hidapi.rb,
lib/hidapi/device.rb,
lib/hidapi/engine.rb,
lib/hidapi/errors.rb,
lib/hidapi/version.rb,
lib/hidapi/language.rb,
lib/hidapi/setup_task_helper.rb
Overview
A Ruby implementation of the HID API library from Signal 11 software.
I am not associated with Signal 11 software.
This library was written out of a need to get better debugging information. By writing it, I learned quite a bit about HID devices and how to get them working with multiple operating systems from one Ruby gem. To do this, I use LIBUSB.
This module contains the library and wraps around an instance of the HIDAPI::Engine class to simplify calls. For instance, HIDAPI.engine.enumerate can also be used as just HIDAPI.enumerate.
Defined Under Namespace
Classes: Device, Engine, Language, SetupTaskHelper
Constant Summary collapse
- HidApiError =
A general error from the HIDAPI library.
Class.new(StandardError)
- InvalidDevice =
The device supplied was invalid for the HIDAPI::Device class.
Class.new(HidApiError)
- DeviceOpenFailed =
Failed to open a device.
Class.new(HidApiError)
- DeviceNotOpen =
An open device is required for the method called.
Class.new(HidApiError)
- DevicePathInvalid =
Device path invalid.
Class.new(HidApiError)
- VERSION =
'0.1.8'
Class Method Summary collapse
-
.debug(msg = nil, &block) ⇒ Object
Processes a debug message.
-
.engine ⇒ Object
Gets the engine used by the API.
-
.method_missing(m, *a, &b) ⇒ Object
:nodoc:.
-
.respond_to_missing?(m) ⇒ Boolean
:nodoc:.
-
.set_debugger(&block) ⇒ Object
Sets the debugger to use.
Class Method Details
.debug(msg = nil, &block) ⇒ Object
Processes a debug message.
You can either provide a debug message directly or via a block. If a block is provided, it will not be executed unless a debugger has been set and the message is left nil.
50 51 52 53 54 55 56 57 58 |
# File 'lib/hidapi.rb', line 50 def self.debug(msg = nil, &block) dbg = @debugger if dbg mutex.synchronize do msg = block.call if block_given? && msg.nil? dbg.call(msg) end end end |
.engine ⇒ Object
Gets the engine used by the API.
All engine methods can be passed through the HIDAPI module.
25 26 27 |
# File 'lib/hidapi.rb', line 25 def self.engine @engine ||= HIDAPI::Engine.new end |
.method_missing(m, *a, &b) ⇒ Object
:nodoc:
30 31 32 33 34 35 36 37 |
# File 'lib/hidapi.rb', line 30 def self.method_missing(m,*a,&b) # :nodoc: if engine.respond_to?(m) engine.send(m,*a,&b) else # no super available for modules. raise NoMethodError, "undefined method `#{m}` for HIDAPI:Module" end end |
.respond_to_missing?(m) ⇒ Boolean
:nodoc:
40 41 42 |
# File 'lib/hidapi.rb', line 40 def self.respond_to_missing?(m) # :nodoc: engine.respond_to?(m) end |
.set_debugger(&block) ⇒ Object
Sets the debugger to use.
:yields: the message to debug
64 65 66 67 68 |
# File 'lib/hidapi.rb', line 64 def self.set_debugger(&block) mutex.synchronize do @debugger = block_given? ? block : nil end end |