IBM Active Protection System

Playing around on my thinkpad, I discovered that the HDAPS system can be used to do more than just protect your hard drive in case of a fall.

The following application displays a 3D model of a cube representing the monitored laptop, a server running on that laptop is sending real-time updates using information it gets from the IBM Hard Drive Active Protection System (HDAPS). This allows a remote client to monitor the movement of the laptop. The application itself is not very impressive, but I included a screenshot anyway.

Hooking up to the input subsystem through JNI

Making raw input data available to Java3D through the use of JNI. The device is a 3dConnexion Space Navigator, it registers itself as an event device through the input subsystem.

Our Java class

class ReadFile {
    native static int[] readEvent();
    //Load the library
    static {
    public static void main(String args[]) {
            int event[] = new ReadEvents().readEvent();
            System.out.print("Event: ("+event.length+" bytes): ");
            for(int b: event)
                System.out.print(new Integer(b) + " ");

The Makefile used to build the shared library

CFLAGS= -shared -Wall
     -I/usr/lib/jvm/java-6-sun- \
$(JH) ReadEvents
$(CC) $(CFLAGS) -o $(INCLUDEPATH) events.c

This is really all the C code we need to pass the axes array

#define EVENTNODE "/dev/input/event6"
int axes[6] = {0,0,0,0,0,0};
int btns[2] = {0,0};
int fd = 0;
JNIEXPORT jintArray JNICALL Java_ReadEvents_readEvent(
    JNIEnv* env, jclass cl)
        if(fd == 0){
                fd = open(EVENTNODE , O_RDONLY);
        struct input_event ev;
        read(fd, &ev, sizeof(struct input_event));
        switch (ev.type){
                        case EV_KEY:
                                btns[ev.code] = ev.value;
                        case EV_REL:
                                axes[ev.code] = ev.value;
        jintArray jb;
        jb = (*env)->NewIntArray(env, 6);
        (*env)->SetIntArrayRegion(env, jb, 0, 6, (jint *)axes);
        return (jb);