So for some reason, we got a little USB missile launcher at work, which of course I wanted to be able to shoot at my coworkers. So it was time to start ‘vestigating!
Quickly, I found that Codedance wrote a nice little python script to hook up to Jenkins in order to launch an onslaught on whoever broke the build. It seems that everyone that used this had no issues, but me. I could not get this working on my mac for the life of me. Then, LIGHTNING BOLTZ!
I write iOS software. I’m also somewhat familiar with the OS X frameworks.
I should just write a mac app that controls this stupid thing!
This proved to be a fun little challenge of getting familiar with Apple’s HID/USB classes. Which it seems changed greatly in OS X 10.5, and they introduced this concept of a HID manager. Using this HID manager greatly simplifies dealing with the USB devices entirely. You basically just pass it in a dictionary as a query, and wait for the callbacks for when devices are plugged in or unplugged and handle them as you wish.
The second challenge, making a UI that worked on the desktop. I must say that the AppKit framework and patterns are much more…dense, than the UIKit framework, at least in my opinion. So I ended up with something that was simple, functional, and ugly.
The third (and most fun) challenge. Making this thing broadcast a service that anyone on the same wireless network could tune into with an iPhone and start controlling a given missile launcher. This involved the NSNetService classes as well as the really awesome Cocoa AsyncSocket class. This class greatly simplifies dealing with the opening of sockets, input/output streams, and the like. I would highly recommend taking a look at these if you need to do any socket programming (they offer a runloop and a gcd based variant of the class).
Everything in the applications works - to an extent. The iPhone app is a little flakey still, which I’m working on. Some weirdness with the socket dying, that I’m sure I’m just not handling right, and of course making the apps a little more pretty.
That’s about it, feel free to take a look at the source on Github, available here.