Monday, August 30, 2010

Magic Trackpad using ten fingers and with gentoo linux support

I picked up a magic trackpad this past friday and decided to see what it was capable of under linux. The video above shows that the magic trackpad hardware provides a great deal of information to the host operating system. As I'd hoped it seems to be nearly as capable as a fingerworks igesture or touchpad in some regards. In the video you can see that the trackpad is able to: detect 10 fingers, track finger contact elliptical size (i.e. along two axes) and orientation, do all the above smoothly at a high sample rate.

The video was created by streaming the debugfs file entry corresponding to the trackpad into a pygame application. The pygame code parses the apple protocol packets to determine ellipse sizes, positions and orientations and then blits them to the screen on transparent surfaces. This code is by no means pretty, in fact "quick hack" is probably a better description. Any suggestions, enhancements, criticisms,etc. are welcome.

If you want to try the code below yourself, you first need to make sure you have debugfs set up properly. Assuming you enabled debugfs when building your kernel, make sure debugfs is mounted and if it's not, mount it with something like:
mount -t debugfs none /sys/kernel/debug/
Now, if you look in /sys/kernel/debug/hid/ you should see a directory whose name corresponds to the address of your magic trackpad. If you switch into this directory you'll see an events file which you can then read with cat, tail, or the python script below. Note that support for the magic trackpad is still in a very preliminary stage, so getting things working is fairly involved. I'll describe how to play around with the hardware at a low level in the description below.

First, start with a kernel new enough to have magic-mouse support. In my case, I chose gentoo-2.6.35-r5. Now grab the multitouch branch of Chase Douglas's debian git repository. You'll need to copy or merge several files from Chase's kernel source to your own:
possibly a few others

If you feel like using the same kernel as Chase, just skip straight to compiling his source tree. Once the kernel is built and you've booted into it, it's time to play around with the trackpad.

Depending on the version of bluez you're using, the procedure for pairing to an HID device will vary. In bluez 3.32 you would first set the trackpad as a trusted device using DBUS, which you could either do programmatically or using a graphical tool like d-feet to call the method
/org/bluez/hci0/org.bluez.Adapter.SetTrusted("bluetooth address of your trackpad").

Once the device is set as trusted you would need to actually setup a pairing as root:
passkey-agent --default 0000
then use d-feet or DBUS CLI to call CreateDevice("BluetoothAddress"). At this point if you call ListDevices() you should a new device corresponding to the trackpad.
Once you've paired with the trackpad and loaded the hid-magicmouse kernel module you should see messages in the system log indicating that a new input device has been registered.

input: Apple Wireless Trackpad as /class/input/input6
magicmouse 0005:05AC:030E.0005: input,hidraw4: BLUETOOTH HID v1.60 Mouse [Apple Wireless Trackpad] on 00:27:48:09:63:60
input: Apple Wireless Trackpad as /class/input/input7

Note that you'll also want an up to date installation of evdev, otherwise you might get messages like this:

evdev.c(EVIOCGBIT): Suspicious buffer size 511, limiting output to 64 bytes. See

If you want to see the touch reports the trackpad produces you can use the evtest application. In gentoo this is provided by the joystick ebuild. Now if you do

]$ evtest /dev/input/event6
Input driver version is 1.0.0
Input device ID: bus 0x5 vendor 0x5ac product 0x30e version 0x160
Input device name: "Apple Wireless Trackpad"
Supported events:
Event type 0 (Sync)
Event type 1 (Key)
Event code 272 (LeftBtn)
Event code 325 (ToolFinger)
Event code 330 (Touch)
Event code 333 (Tool Doubletap)
Event code 334 (Tool Tripletap)
Event code 335 (?)
Event type 3 (Absolute)
Event code 0 (X)
Value 3097
Min -2909
Max 3167
Event code 1 (Y)
Value 2238
Min -2456
Max 2565
Event code 48 (?)
Value 0
Min 0
Max 255
Event code 49 (?)
Value 0
Min 0
Max 255
Event code 52 (?)
Value 0
Min -32
Max 31
Event code 53 (?)
Value 0
Min -2909
Max 3167
Event code 54 (?)
Value 0
Min -2456
Max 2565
Event code 57 (?)
Value 0
Min 0
Max 15
Event type 4 (Misc)
Event code 3 (RawData)
Testing ... (interrupt to exit)

Now if you touch with two fingers you'll see a slew of output which should include something like:

Event: time 1283194689.870573, -------------- Config Sync ------------
Event: time 1283194689.870586, type 1 (Key), code 330 (Touch), value 0
Event: time 1283194689.870587, type 1 (Key), code 333 (Tool Doubletap), value 0
Event: time 1283194689.870589, -------------- Report Sync ------------


  1. So a magic trackpad beats the heck out of a tragic macpad huh? ;-) (Sorry for being punny, couldn't resist)

    Seriously this sounds pretty cool; makes me want to try it too. I've gotten fond of how it works in MacOS.

  2. Hey, my dear friends, if you are hunting for a wild look Michael Kors Handbags Outlet at a reasonable price; you really should not miss this Michael Kors Handbags On Sale. It is truly a qualifying item. (tags: Michael Kors Outlet Online,Michael Kors Sale,Michael Kors Outlet)
    It posted by Michael Kors Outlet Store.

  3. Less than a week later, he had a 26 point, 10 assist performance in a 107 104 win over the Chicago Bulls. He was subsequently named the Player of the Week in only his first week in the NBA, a feat last achieved by in 1992. On November 9, 2013, Carter Williams recorded a career high 13 assists to go with 21 points in a 127 125 double overtime loss to Cleveland.

    For eight years, archdiocese officials wrestled with whether a priest in Hugo Cheap Oakley Sunglasses was fit for ministry. Church officials in Ray Ban Sale UK 2004 found Bolsos Michael Kors Baratos 2,300 pornographic images on his computer, which was found by a parishioner. A 2012 letter from Nienstedt to a cardinal Longchamp Soldes Destockage in Rome noted that an investigator for the archdiocese that many of the images were borderline illegal due to the apparent age of those photographed.

  4. They can be related to stress or too much caffeine or nicotine. But sometimes, PVCs can be caused by heart disease or electrolyte imbalance. If you have a lot of PVCs, or symptoms linked to them, see a heart doctor (cardiologist).. Divide batter evenly into 10 muffin liners and bake for 15 20 minutes or until toothpick comes out clean or with just a few crumbs attached. Cool muffins for 5 minutes then remove and transfer to a wire rack to finish cooling. Muffins are best served warm with a little butter on top..

    Four regions containing Longchamp Soldes Destockage such bulk ice stand out Ray Ban Sale UK in the map: Promethei Terra in the Cheap Oakley Sunglasses lower right of the map, Arabia Terra Bolsos Michael Kors Baratos in the upper centre, Arcadia Planitia in the upper left, and Elysium Planetia spanning from the centre right, across the Martian line (180 degrees longitude), to the centre left of the map. The ice deposits here are less than about 1 m below the surface, writes Dr. Feldman.

  5. Both things are possible if you carry Michael Kors Handbags Wholesale. If you are a woman who goes for innovative designs, a designer Michael Kors Bags On Sale is perfect for you. Offering a huge selection of chic purses, handbags, shoes and accessories, Michael Kors Outlet Online Store celebrates womanhood in an entirely unique way. Michael Kors Factory Outlet Online Store At Wholesale Price are one of the most sought-after handbags worldwide. We all agree that diamonds are a woman's best friend; however Official Coach Factory Outlet Online are absolutely next in line. To Coach Outlet Sale aficionados, don't fret because we have great news: a discount Official Coach Outlet Online isn't hard to find. If you are a smart shopper looking for a good buy and great deals on your next handbag purchase, you can go to Official Coach Outlet Online.

    Friendly Links: Toms Shoes Womens | Toms Clearance

  6. obat kuat terbaru viagra asli yang sudah memiliki izin resmi dari bpom kini banyak diburu oleh pria dewasa untuk memelihara stamina pria saat bercinta bersama istrinya. kapsul ajaib dari erogan asli kapsul obat kuat dapat menambah stamina pria sekaligus dapat memperbaiki ukuran alat vital pria yang dapat membantu masalah biologis secara sempurna. obat dari cina seperti nangen asli zengzhangsu obat kuat impotensi dapat mengobati impotensi jika anda konsumsi secara rutin dalam 2x sehari dapat menyembuhkan secara total. levitra asli 100 mg obat disfungsi ereksi yang banyak dicari oleh kalangan pria yang ingin mendapatkan ereksi keras, kencang dan tahan lama hingga mampu klimaks secara berulang-ulang. vimax pills adalah ramuan khusus sebagai obat pembesar alat kelamin yang terbuat dari ramuan herbal yang sudah diracik dengan teknologi modern ala canada klik tautan .