{"id":75,"date":"2007-03-17T09:03:15","date_gmt":"2007-03-17T17:03:15","guid":{"rendered":"http:\/\/jaredrobinson.com\/blog\/?p=75"},"modified":"2007-03-17T09:03:15","modified_gmt":"2007-03-17T17:03:15","slug":"mtnwestruby-ruby-usb","status":"publish","type":"post","link":"https:\/\/jaredrobinson.com\/blog\/mtnwestruby-ruby-usb\/","title":{"rendered":"mtnwestruby: Ruby USB"},"content":{"rendered":"<p>\nmtnwestruby: Ruby USB by Michael Hewner<br \/>\n16 March 2007\n<\/p>\n<p>\nNerds love to customize their software &#8212; their shell prompt, adding vim plugins, emacs, etc. After a while, they run out of things to customize. What do they do now? Customize USB hardware!<\/p>\n<p>\nRuby USB is about fun, about controlling USB devices using Ruby. No<br \/>\none paid him to work on it. USB devices are self describing. You can even build<br \/>\nyour own USB devices, which has nothing to do with Ruby. The most interesting<br \/>\nUSB spec is the one for Human Interface Devices. For HID, the device sends a<br \/>\ndescription of the format of the data that it&#8217;s going to send and what it means<br \/>\n&#8212; before it actually sends the data. No reverse engineering necessary!<\/p>\n<p>\nRuby USB simplifies the interpretation of the meta-data coming from a USB<br \/>\ndevice.<\/p>\n<p>\n<code>mouse_interface.all_input_usages => [Button (9)::Button ...]<\/code><br \/>\n<code>keyboard_interface.all_input_usages # will list ever key available on the keyboard<\/code><\/p>\n<p>\nMichael did not write libUSB; his Ruby library merely uses it. It supposedly<br \/>\nsupports all UNIX operating systems, although he&#8217;s only tested it on Linux.<\/p>\n<p>\nLessons learned:<\/p>\n<ul>\n<li>Don&#8217;t write the USB HID parsing library in C++ and patch it into Ruby &#8212; it&#8217;s too much work. He should have written it directly in Ruby.\n<li>Write unit tests.\n<\/ul>\n<\/p>\n<p>\nAVRUSB: Build your own custom USB device &#8212; requires that you have a soldering iron and an AVR microcontroller.<\/p>\n<p>\nEvdev uses the linux-level USB device layer to let you talk to USB devices. It&#8217;s easier to use, more rock solid, but doesn&#8217;t let you do as many cool things.<\/p>\n<p>\nQ: Is Ruby USB ruby-thread safe?<br \/>\nA: Haven&#8217;t tested it. There are probably some bugs.<\/p>\n<p>\nQ: Do you have the ability to send output to USB devices?<br \/>\nA: He&#8217;s working on it. It&#8217;s almost ready.<\/p>\n<p>\nQ: What&#8217;s the craziest thing you&#8217;ve done with Ruby USB?<br \/>\nA: Glued two keyboards together. Made one work for Vi insert mode, and one for Vi command mode. It didn&#8217;t work out well because he would frequently type on the wrong keyboard, and because it was too large to fit on his lap comfortably.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mtnwestruby: Ruby USB by Michael Hewner 16 March 2007 Nerds love to customize their software &#8212; their shell prompt, adding vim plugins, emacs, etc. After a while, they run out of things to customize. What do they do now? Customize USB hardware! Ruby USB is about fun, about controlling USB devices using Ruby. No one &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaredrobinson.com\/blog\/mtnwestruby-ruby-usb\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;mtnwestruby: Ruby USB&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,17],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-programming","category-tech"],"_links":{"self":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":0,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}