Ruby USB - Big Eyes Small Mouth Character Generator

Download Report

Transcript Ruby USB - Big Eyes Small Mouth Character Generator

Ruby USB
Michael Hewner
rubyusb.technofetish.net
rubyusb ‘at’ hewner.com
What’s Cool About USB?
• Everywhere & well specified
• You can build your own (but not in ruby)
• Self-describing (especially HID devices)
USB Human Interface Devices
For the complete HID spec details check out
Device Class Definition for HID 1.11
http://www.usb.org/developers/devclass_docs/HID1_11.pdf
The Goal: Annotated Data
10000000011111011
1
Left mouse
button
0
0
Distinct but
logically
grouped
Annotated
with the string
“security
stuff”
nothing
-5
Measures in °C
Minimum Value -36
Implicitly *10^3
A Partial Mouse HID Descriptor
USAGE_PAGE (Generic Desktop)
USAGE (Mouse)
COLLECTION (Application)
USAGE (Pointer)
COLLECTION (Physical)
USAGE_PAGE (Button)
USAGE_MINIMUM (Button 1)
USAGE_MAXIMUM (Button 3)
LOGICAL_MINIMUM (0)
LOGICAL_MAXIMUM (1)
REPORT_COUNT (3)
REPORT_SIZE (1)
INPUT (Data,Var,Abs)
REPORT_COUNT (1)
REPORT_SIZE (5)
INPUT (Cnst,Var,Abs)
…and more follows
05 01
09 02
A1 01
09 01
A1 00
05 09
19 01
29 03
15 00
25 01
95 03
75 01
81 02
95 01
75 05
81 03
1 0 0 XXXXX
3 1 Bit “Button” Fields
1 5 Bit Empty Space
Examples of RubyUSB
How Does it Work?
Part 1 of 3: libUSB
LibUSB
Cross -Platform
C USB Library
C Structs
&
Raw USB Descriptions
• Provides basic C access to all key USB fuctionality
• Supposedly cross-platform (OS X and BSD) but I’ve only tested on Linux
• The version in the Debian package repository doesn’t work – you need to get
the latest from CVS
• You must disconnect devices from the kernel
How Does it Work?
Part 2 of 3: HIDParser
HIDParser
C++ OO Parser
For HID Reports
Report
Descriptor
Objects
• Parses the HID into “Report Descriptor Objects” that describe a particular kind
of communication
• Vast majority of HID constructs are supported
• Suite of unit tests
• Needs more testing on interesting HID devices
How Does it Work?
Part 3 of 3: RubyUSB
RubyUSB
Handy
Documented
USB Library
• Tries to implictly do the right thing
• Produces annotated Objects
• Needs more work for Output and some other stuff
The Big Picture
Your
AVR
USB
LibUSB
Simple
Commands
Rock’n
USB
C
Device
HIDParse
Raw
CrossUSB
Platform Descriptions
C USB
Library
C++ OO Report
Parser Descriptor
For HID Objects
Reports
Raw USB Reports
RubyUSB
Handy
Documented
USB Library
Fancy
Report
Objects
Your
Rock’n
App
AVRUSB: So Very Cool
So easy to build your own custom USB
devices anybody can do it. As long as
anybody has a soldering iron and an avr
microcontroller programmer.
http://www.obdev.at/products/avrusb/hidkeys.html
Future Stuff
• Improved packaging building and
installation
• Improved ruby objects
• More testing with a variety of usb devices
• Evdev for even easier but less cool fun