Wednesday, March 27, 2013

Leap Motion in Gentoo Linux

Great news for those of you with Leap Motion developer kits, today's 0.7.6 release of the SDK adds linux support. Their package targets ubuntu specifically but I was able to get it working on a gentoo system as well. Here's a preliminary write up of what I did:
  1. Download the 0.7.6 SDK (if you're a Leap developer you know how to get it)
  2. move the developer kit tarball to a convenient temp directory
  3. tar xvzf Leap_Developer_Kit_0.7.6_3012_Linux.tar.gz
  4. this will extract the debian packages- for gentoo we can convert to tarball in the next step using alien.
  5. alien -t Leap-0.7.6-x64.deb
  6. Note: if you're on a 32-bit system use Leap-0.7.6-x86.deb
  7. tar xvzf leap-0.7.6.tgz
  8. the previous step extracted usr and etc directories so now we copy the files from these directories into place:
    sudo cp -ir usr/local/* /usr/local/
    Note that I use -i flag to avoid accidentally overwriting existing files. I wound up just copying all the files into place rather than just the leap-specific ones because the Leap installer has bundled versions of QT libraries and trying to use my system QT libraries was causing a segfault.
  9. sudo cp -ir etc/udev/rules.d/* /etc/udev/rules.d/
    Copying those udev rules should in theory allow you to run the Leap application without superuser privileges, but that did not work for me- I will try to figure this out later.
  10. I'm not sure if these next 3 steps are necessary on gentoo, but just in case- they create the plugdev group if it does not exist, add you to that group, and then reload your session so your group membership is updated without having to logout/login.
  11. groupadd plugdev
  12. sudo usermod -a -G plugdev $USER
  13. exec su-l $USER #refresh group membership
  14. sudo Leap

  15. Assuming that /usr/local/bin/ is in your path- you should just be able to run the Leap command in your shell. You need the Leap application running in the background for any other interactions with the leap device to work. Notice that I had to run the command as root even though I copied in the udev rules. In my case, running LeapPipeline(ostensibly the command line alternative to Leap) without root privileges will give an error like: [00:54:08] [Critical] [EC_NO_DEVICE] Please make sure your Leap device is plugged in.
    Running LeapPipeline with root privileges does not give me any error message, just some debug output and then it quits without doing anything. Running Leap without without root privileges in my case will not give any error messages- everything will simply fail silently, i.e. if you run the visualizer you will get no tracking data.
  16. Visualizer
    Test the cool new gesture features with the visualizer by running the Visualizer command and pressing the letter 'o' to enable drawing gestures. In this screenshot I have traced out a counter-clockwise circle with my finger- which is one of the supported gestures so it is drawn as light blue circular arrow. You can do multi-finger swipes, taps, and circles. See this part of the documentation for more details:

Play with the samples

At the top level of the directory where you unpacked Leap_Developer_Kit_0.7.6_3012_Linux.tar.gz you will see an examples directory. Here is what they look like.

FingerVisualizer

MotionVisualizer

UnitySandbox

Some caveats

At some point a .Leap Motion directory needs to be created in your home directory (note the space between the two words and the leading "."). I'm not sure if this is done by the installer or by the first run of the Leap application. In my case I actually copied the contents of the .Leap Motion folder on my ubuntu system to my gentoo system. In particular, there should be two files in this folder a leapid file and a file that is named something like DEV-12345 (yours will be different). The Leap application is actually a GUI app which resides in your dock/panel, if you use one, but it's not necessary- Leap will run without a panel. I've confirmed that it works with xfce4-panel if you want to see it, but you can access almost all the executables directly from the commandline anyway:
  • /usr/local/bin/Visualizer
  • /usr/local/bin/ScreenLocator
  • /usr/local/bin/Recalibrate
  • /usr/local/bin/LeapPipeline
  • /usr/local/bin/Leap
Post questions if you have any problems.

Friday, January 4, 2013

TI MSP430 Launchpad in gentoo linux

Getting started with the MSP430 launchpad in gentoo is pretty straightforward, once you've dug through some documentation. Here's some instructions that should get you up and running.
  1. emerge crossdev

  2. NOTE: Only perform steps 2 and 3 if you do not already have an overlay setup

  3. mkdir /usr/local/portage

  4. add PORTDIR_OVERLAY="/usr/local/portage" to /etc/make.conf

  5. NOTE: Only perform steps 4-6 if /etc/portage/package.env is a file rather than a directory on your system. Also note that the string "x86_64-pc-linux-gnu" needs to match the architecture of your system, which you can find by running gcc -v and checking the string labeled "Target"

  6. mv /etc/portage/package.env /etc/portage/package.env.bak

  7. mkdir /etc/portage/package.env

  8. mv /etc/portage/package.env.bak /etc/portage/package.env/x86_64-pc-linux-gnu

  9. crossdev -s4 -t msp430

  10. -s4 means stage 4 which will build a full gcc, libc,kernel header, and binutils This command will also create /usr/msp430/etc/portage/make.conf which I believe will control how any future msp430 specific packages get emerged.

  11. crossdev --ex-only --ex-gdb -t msp430

  12. Now that you have got gcc going, this command will build just gdb without redoing all the other 4 stages(libc,gcc,etc.)

  13. emerge mspdebug

  14. msp430-gcc -mmcu=msp430g2553 blink.c

  15. Scroll down to the end of this post to find the source code for blink.c Note that my launchpad came prepopulated with a msp430g2553 in the DIP socket, you will want to check what yours came with and set the -mmcu parameter accordingly. The model number is printed on the top of the microcontroller.

  16. sudo mspdebug rf2500

  17. This command will start the debugger which will spew out a bunch of output before displaying a prompt that looks like this:
    (mspdebug)

  18. (mspdebug) prog a.out
  19. Note that you only type the text in bold in the command above, (mspdebug) is just the prompt that is displayed on screen.
  20. hit Ctrl+D to quit the debugger
  21. The microcontroller will start executing code, in this case blinking LED1, LED2 is attached to P1.6