Class: LIBUSB::Setting

Inherits:
FFI::Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/libusb/setting.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface, *args) ⇒ Setting

Returns a new instance of Setting.



88
89
90
91
# File 'lib/libusb/setting.rb', line 88

def initialize(interface, *args)
  @interface = interface
  super(*args)
end

Instance Attribute Details

#interfaceInterface (readonly)

Returns the interface this setting belongs to.

Returns:

  • (Interface)

    the interface this setting belongs to.



94
95
96
# File 'lib/libusb/setting.rb', line 94

def interface
  @interface
end

Instance Method Details

#<=>(o) ⇒ Object



125
126
127
128
129
130
# File 'lib/libusb/setting.rb', line 125

def <=>(o)
  t = interface<=>o.interface
  t = bInterfaceNumber<=>o.bInterfaceNumber if t==0
  t = bAlternateSetting<=>o.bAlternateSetting if t==0
  t
end

#bAlternateSettingObject

Value used to select this alternate setting for this interface.



51
52
53
# File 'lib/libusb/setting.rb', line 51

def bAlternateSetting
  self[:bAlternateSetting]
end

#bDescriptorTypeObject

Descriptor type (0x04)



41
42
43
# File 'lib/libusb/setting.rb', line 41

def bDescriptorType
  self[:bDescriptorType]
end

#bInterfaceClassObject

USB-IF class code for this interface.



61
62
63
# File 'lib/libusb/setting.rb', line 61

def bInterfaceClass
  self[:bInterfaceClass]
end

#bInterfaceNumberObject

Number of the interface this setting belongs to.



46
47
48
# File 'lib/libusb/setting.rb', line 46

def bInterfaceNumber
  self[:bInterfaceNumber]
end

#bInterfaceProtocolObject

USB-IF protocol code for this interface, qualified by the #bInterfaceClass and #bInterfaceSubClass values.



71
72
73
# File 'lib/libusb/setting.rb', line 71

def bInterfaceProtocol
  self[:bInterfaceProtocol]
end

#bInterfaceSubClassObject

USB-IF subclass code for this interface, qualified by the #bInterfaceClass value.



66
67
68
# File 'lib/libusb/setting.rb', line 66

def bInterfaceSubClass
  self[:bInterfaceSubClass]
end

#bLengthObject

Size of this descriptor (in bytes).



36
37
38
# File 'lib/libusb/setting.rb', line 36

def bLength
  self[:bLength]
end

#bNumEndpointsObject

Number of endpoints used by this interface (excluding the control endpoint).



56
57
58
# File 'lib/libusb/setting.rb', line 56

def bNumEndpoints
  self[:bNumEndpoints]
end

#configurationObject

The Configuration this Setting belongs to.



123
# File 'lib/libusb/setting.rb', line 123

def configuration() self.interface.configuration end

#descriptionObject

Return name of this interface as String.



115
116
117
118
# File 'lib/libusb/setting.rb', line 115

def description
  return @description if defined? @description
  @description = device.try_string_descriptor_ascii(self.iInterface)
end

#deviceObject

The Device this Setting belongs to.



121
# File 'lib/libusb/setting.rb', line 121

def device() self.interface.configuration.device end

#endpointsObject



96
97
98
99
100
101
102
# File 'lib/libusb/setting.rb', line 96

def endpoints
  ifs = []
  self[:bNumEndpoints].times do |i|
    ifs << Endpoint.new(self, self[:endpoint] + i*Endpoint.size)
  end
  return ifs
end

#extraString

Extra descriptors.

Returns:

  • (String)


83
84
85
86
# File 'lib/libusb/setting.rb', line 83

def extra
  return if self[:extra].null?
  self[:extra].read_string(self[:extra_length])
end

#iInterfaceObject

Index of string descriptor describing this interface.



76
77
78
# File 'lib/libusb/setting.rb', line 76

def iInterface
  self[:iInterface]
end

#inspectObject



104
105
106
107
108
109
110
111
112
# File 'lib/libusb/setting.rb', line 104

def inspect
  attrs = []
  attrs << self.bAlternateSetting.to_s
  devclass = LIBUSB.dev_string(self.bInterfaceClass, self.bInterfaceSubClass, self.bInterfaceProtocol)
  attrs << devclass
  desc = self.description
  attrs << desc if desc != '?'
  "\#<#{self.class} #{attrs.join(' ')}>"
end