May
16
First of all I installed a kernel module that will make the tilt sensor work, as well as a perl module using CPAN:
sudo modprobe applesmc; sudo cpan -i Linux::Joystick
Then, use this script to see the tilt sensor in action:
use Linux::Joystick;
my $js = new Linux::Joystick;
my $event;
print “Joystick has ” . $js->buttonCount() . ” buttons and ” . $js->axisCount() . ” axes.”;
# blocking reads:
while( $event = $js->nextEvent ) {
print “Event type: ” . $event->type . “, “;
if($event->isButton) {
print “Button ” . $event->button;
if($event->buttonDown) {
print ” pressed”;
} else {
print ” released”;
}
} elsif($event->isAxis) {
print “Axis ” . $event->axis . “, value ” . $event->axisValue . “, “;
print “UP” if $event->stickUp;
print “DOWN” if $event->stickDown;
print “LEFT” if $event->stickLeft;
print “RIGHT” if $event->stickRight;
} else {
# should never happen
print “Unknown event ” . $event->hexDump;
}
print “”;
}
# if the while loop terminates, we got a false (undefined) event:
die “Error reading joystick: ” . $js->errorString;
my $js = new Linux::Joystick;
my $event;
print “Joystick has ” . $js->buttonCount() . ” buttons and ” . $js->axisCount() . ” axes.”;
# blocking reads:
while( $event = $js->nextEvent ) {
print “Event type: ” . $event->type . “, “;
if($event->isButton) {
print “Button ” . $event->button;
if($event->buttonDown) {
print ” pressed”;
} else {
print ” released”;
}
} elsif($event->isAxis) {
print “Axis ” . $event->axis . “, value ” . $event->axisValue . “, “;
print “UP” if $event->stickUp;
print “DOWN” if $event->stickDown;
print “LEFT” if $event->stickLeft;
print “RIGHT” if $event->stickRight;
} else {
# should never happen
print “Unknown event ” . $event->hexDump;
}
print “”;
}
# if the while loop terminates, we got a false (undefined) event:
die “Error reading joystick: ” . $js->errorString;
Now I just have to figure out what to do with this newly gained information. By the way, you can play neverball using the tilt sensor.
Related posts:
- Forcing a macbook to eject a CD
- Cracking md5 hashes just got easier – with perl
- Controlling transmission using json-rpc in perl
- LWP::UserAgent and HTTPS
- How to make plenty of $$$ on twitter
Tags: macbook, perl, tiltsensor




