Feeds:
Posts
Comments

Posts Tagged ‘thinkpad’

Its a common knowledge that Thinkpads have HDAPS feature (IBM Active Protection System). Its primary purpose, in Windows at least, is to detect falling motion (laptop about to crash into the ground) so that it can immediately park the hard disk heads to prevent data loss. How cool is that?
In Linux, are are available drivers that you can install in order for you to make use or access the built-in accelerometer. Users on YouTube have already posted demos of fun things you can do with it, from useful features such as tapping your laptop to switch workspaces, or changing the display orientation to silly ones like playing games by tilting the laptop itself and making it hum like Jedi swords. So what do you need to get started hacking? First, you’ll need the TP_SMAPI. Second? Imagination. Here’s a java port to get you started:

int threshold = 2;
long numMillisecondsToSleep = 1000; // 1 second
int oldx=0, oldy=0, x, y;
boolean doupdate;

try {
    do {
        FileReader fr = new FileReader("/sys/devices/platform/hdaps/position");
        BufferedReader br = new BufferedReader(fr);
        String s = br.readLine();

        StringTokenizer st = new StringTokenizer(s, "(,)");
        x = Integer.parseInt(st.nextToken());
        y = Integer.parseInt(st.nextToken());

        doupdate = false;

        if ((oldx != x) || (oldy != y)) {

            if (Math.abs(oldx - x) > threshold) {
                oldx = (oldx != x) ? x : oldx;
                doupdate = true;
            }

            if (Math.abs(oldy - y) > threshold) {
                oldy = (oldy != y) ? y : oldy;
                doupdate = true;
            }

            if (doupdate) {
                System.out.println("x = " + oldx + " | " + "y = " + oldy);
            }

        }

        try {
            Thread.sleep(numMillisecondsToSleep);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } while(true);

} catch (IOException e) {
    e.printStackTrace();
}

Ported from the original C code written by Jeff Molofee.

Advertisements

Read Full Post »