No transfer_type or synchronization_type methods for endpoint?
Opened this issue · 5 comments
I can see the transfer method "Interrupt" if I do:
device.interfaces[9].endpoints[0].inspect
=> #<LIBUSB::Endpoint 10 IN Interrupt>
However I can't seem to get this "Interrupt" string any other way other than inspect.
The inspect source is figuring quite a lot of very useful stuff like transfer_type, synchronization_type and usage_type but this info cannot be accessed any other way but parsing the inspect string, why is this?
Can we please have transport_type, synchronization_type and usage_type methods that return a string like "Interrupt"?
Here is the method in question that can be found in /lib/libusb/endpoint.rb
def inspect
endpoint_address = self.bEndpointAddress
num = endpoint_address & 0b00001111
inout = (endpoint_address & 0b10000000) == 0 ? "OUT" : "IN "
bits = self.bmAttributes
transfer_type = %w[Control Isochronous Bulk Interrupt][0b11 & bits]
type = [transfer_type]
if transfer_type == 'Isochronous'
synchronization_type = %w[NoSynchronization Asynchronous Adaptive Synchronous][(0b1100 & bits) >> 2]
usage_type = %w[Data Feedback ImplicitFeedback ?][(0b110000 & bits) >> 4]
type << synchronization_type << usage_type
end
"\#<#{self.class} #{num} #{inout} #{type.join(" ")}>"
end
Thanks for this idea! I fully agree with you - there should be some more convenient methods and parsing of #inspect is no good way. What do you think about the above commit?
Looks fantastic! - inspect method is much cleaner now too :) - Thanks a bunch, I'll install from git and test out :)
Been testing it today, not ran into problems - would be great if this is added to master :)
currently have this in my Gemfile:
gem 'libusb', :github => "larskanis/libusb", :branch => "descriptor_convenience_methods"
OK, it's merged to master.
Sweet, thank you :)