Class: HidApi::DeviceInfo

Inherits:
FFI::Struct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hid_api/device_info.rb

Overview

Represents the hid_device_info struct returned as part of the HidApi::hid_enumerate operation

Because the struct acts as a linked list, every item represents both a device in the enumeration AND an Enumerable representing the rest of the list.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.release(pointer) ⇒ Object



13
14
15
# File 'lib/hid_api/device_info.rb', line 13

def self.release(pointer)
  HidApi.hid_free_enumeration(pointer) unless pointer.null?
end

Instance Method Details

#eachObject

Exposes the linked list structure in an Enumerable-compatible format



44
45
46
47
48
49
50
51
52
53
# File 'lib/hid_api/device_info.rb', line 44

def each
  return enum_for(:each) unless block_given?

  pointer = self
  loop do
    break if pointer.null?
    yield pointer
    pointer = pointer.next
  end
end

#inspectObject



37
38
39
40
41
# File 'lib/hid_api/device_info.rb', line 37

def inspect
  product_string.tap do |s|
    s << " (%s)" % path unless path.empty?
  end
end