module HIDAPI
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.
Constants
- DeviceNotOpen
An open device is required for the method called.
- DeviceOpenFailed
Failed to open a device.
- DevicePathInvalid
Device
path invalid.- HidApiError
A general error from the
HIDAPI
library.- InvalidDevice
The device supplied was invalid for the
HIDAPI::Device
class.- VERSION
Public Class Methods
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.
# 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
Gets the engine used by the API.
All engine methods can be passed through the HIDAPI
module.
# File lib/hidapi.rb, line 25 def self.engine @engine ||= HIDAPI::Engine.new end
Sets the debugger to use.
# File lib/hidapi.rb, line 64 def self.set_debugger(&block) mutex.synchronize do @debugger = block_given? ? block : nil end end
Private Class Methods
# File lib/hidapi.rb, line 72 def self.mutex @mutex ||= Mutex.new end