You are not logged in.

#1 2009-08-14 18:03:36

samoturk
Member
From: Ljubljana, Slovenia
Registered: 2007-02-12
Posts: 86

HP accelerometer and compiz rotating cube

I just found out, that I have an accelerometer (lis3lv02d) in my HP laptop. So I wrote a simple bash script that rotates compiz cube in direction the laptop is tilted.

Video of script in action:
http://www.youtube.com/watch?v=CtWywn1zbjA

I would post the script, but I'm a bit ashamed of my programming skills..

Offline

#2 2009-08-14 18:31:27

flamelab
Member
From: Athens, Hellas (Greece)
Registered: 2007-12-26
Posts: 2,160

Re: HP accelerometer and compiz rotating cube

Ohhh, that's good !

Please post the script smile

Offline

#3 2009-08-14 19:42:53

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: HP accelerometer and compiz rotating cube

As long as you don't share it, it's hardly a contribution wink. Every effort is appreciated, and I'm sure people will gladly (and politely) point out possible improvements. If not: there's always a report button wink.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#4 2009-08-14 21:44:57

samoturk
Member
From: Ljubljana, Slovenia
Registered: 2007-02-12
Posts: 86

Re: HP accelerometer and compiz rotating cube

I'll post the script here as soon as I improve it a bit..

Offline

#5 2009-08-14 22:09:28

samoturk
Member
From: Ljubljana, Slovenia
Registered: 2007-02-12
Posts: 86

Re: HP accelerometer and compiz rotating cube

OK, it is realy two scripts. This one is for rotating the cube with help of wmctrl (you should install wmctrl in order for it to work). I found it on the internet and shoud work on any desktop. It would be probably a better idea to do it via dbus but it doesn't seem to work for me..

#!/bin/bash
#
# compiz-rotate-wmctrl - Rotate the cube using wmctrl
#
# Author: Shang-Feng Yang
# Released under GPLv3

VER="1.0"


function rotate() {
  # The target face number (begins with 0)
  TVPN=$(( $1 % ${NF} ))

  # The X coordinate of the target viewport
  TVPX=$(( ${TVPN} * ${WW} ))

  # Change to the target viewport
  wmctrl -o ${TVPX},0
}

function usage() {
  echo -e "$(basename $0) v${VER}\n"
  echo -e "Usage:\n"
  echo -e "\t$(basename $0) {left|right|#}\n"
  echo -e "\tWhere:\n"
  echo -e "\t\tleft - rotate the cube to the left"
  echo -e "\t\tright - rotate the cube to the right"
  echo -e "\t\t# - rotate to #th face (begins with 0)\n\n"
  echo -e "Author: Shang-Feng Yang <storm dot sfyang at gmail dot com>"
  echo -e "Released under GPLv3"
}

# The action to be performed. $ACT could be 'left' or 'right' to rotate
# left or right, accordingly. $ACT could also be the number of the face
# to rotate into.
ACT=$(echo $1 |tr '[A-Z]' '[a-z]')

[ "x$ACT" == "x" ] && { usage; exit 1; } || {
  case $ACT in
    left|right|[0-9]|[0-9][0-9])
      ;;
    *)
      usage
      exit 1
      ;;
  esac
}


# The informations about the desktop
INFO=$(wmctrl -d)
# The width of the desktop
DW=$(echo "${INFO}"| awk '{sub(/x[0-9]+/, "", $4); print $4}')
# The width of the workarea
WW=$(echo "${INFO}"| awk '{sub(/x[0-9]+/, "", $9); print $9}')
# The number of faces on the cube
NF=$(($DW/$WW))
# The X coordinate of the viewport
CVPX=$(echo "${INFO}" |awk '{sub(/,[0-9]+/, "", $6); print $6}')
# Current number of the face in all faces (begins with 0)
CVPN=$(( ${CVPX} / ${WW} ))

[ "$ACT" == "right" ] && {
  ACT=$(( ${CVPN} + 1 ))
} || {
  [ "$ACT" == "left" ] && {
    ACT=$(( ${CVPN} - 1 ))
  }
}

rotate ${ACT}

Next script monitors /sys/devices/platform/lis3lv02d/position. If you look at /sys/devices/platform/lis3lv02d/position you get something like: (3,6,51). First number is left/right tilt, second back/forward and last upside/downside. The script reads position value every 2 seconds and quits after 200 seconds..

#!/bin/bash
# lis3lv02d-rotate
#
# Author: Samo Turk
#
# Released under GPLv3

COUNTER=0

while [  $COUNTER -lt 100 ]; do
    sleep 2
    POS=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$1}' | awk -F "(" '{print$2}'`
    echo $POS
        if [ $POS -ge 12 ]; then
            ./compiz-rotate-wmctrl left
        elif [ $POS -le -12 ]; then
            ./compiz-rotate-wmctrl right
        
            
        fi
    let COUNTER=COUNTER+1
done

So you need to have 2 scripts, the first is compiz-rotate-wmctrl and second lis3lv02d-rotate. Put them in the same folder and chmod +x for both of them and then just run ./lis3lv02d-rotate

Everything should probably be written in C and use dbus for comunicating with compiz but I don't know C...

Offline

#6 2009-08-15 01:47:51

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: HP accelerometer and compiz rotating cube

This is cool! cool Just checked my HP laptop and it has an accelorometer as well. Might have to find a use for it now.

Offline

#7 2009-08-15 02:07:14

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: HP accelerometer and compiz rotating cube

Yeah, that's really something that will improve usability...tilting the laptop to change workspaces wink


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#8 2009-08-15 02:30:43

koch
Member
From: Germany
Registered: 2008-01-26
Posts: 369

Re: HP accelerometer and compiz rotating cube

it is not about usability, it is about health and money.
people can be forced to do some training while working on their machines which improves their workflow which is better for the company they work for which is better for the money people get from their bosses which is good for the companies who sell laptops with accelorometers because people can buy them which is good for...oh, wait, this sounds kind of familiar...

or they could go outside and have some fun with sports and their friends... wink

Offline

#9 2009-08-15 08:10:32

Heller_Barde
Member
Registered: 2008-04-01
Posts: 245

Re: HP accelerometer and compiz rotating cube

its not _not_ usable...

Offline

#10 2009-08-15 11:13:59

samoturk
Member
From: Ljubljana, Slovenia
Registered: 2007-02-12
Posts: 86

Re: HP accelerometer and compiz rotating cube

Just discovering some interesting things that can be done with accelerometer. Because it registers itself as a joystick device "/dev/input/js0" it can be used for exemple in google-earths flight simulator for controlling the plane..

Offline

#11 2009-08-15 12:45:07

Heller_Barde
Member
Registered: 2008-04-01
Posts: 245

Re: HP accelerometer and compiz rotating cube

samoturk wrote:

Just discovering some interesting things that can be done with accelerometer. Because it registers itself as a joystick device "/dev/input/js0" it can be used for exemple in google-earths flight simulator for controlling the plane..

it's awesome isn't it ^^ as soon as i have some spare time on my hand, i'm gonna build a model car that i can control with my laptop's accelerometer

Offline

#12 2009-08-17 19:35:50

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,221
Website

Re: HP accelerometer and compiz rotating cube

(Ab)Using morse code, the possibilities are endless ;-)

I have seen 1 cool application for such an accelerometer (outside the scope of safeguarding your hard disk platters if your laptop should fall of course), and that is the usage of it in combination with google street view. You could see the real life environment around the mobile's screen and the virtual environment was sort of a layer above the real life environment. So if you moved the mobile to the left, the layer followed along nicely...

Offline

#13 2009-08-17 22:41:15

dunc
Member
From: Glasgow, UK
Registered: 2007-06-18
Posts: 559

Re: HP accelerometer and compiz rotating cube

moljac024 wrote:

Yeah, that's really something that will improve usability...tilting the laptop to change workspaces wink

I remember seeing a video way back in the early days of Compiz of a guy tapping the sides of his laptop to get the accelerometer to turn the cube. That was cool - and slightly more practical.


0 Ok, 0:1

Offline

#14 2009-08-18 05:53:12

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: HP accelerometer and compiz rotating cube

zenlord wrote:

(Ab)Using morse code, the possibilities are endless ;-)

I have seen 1 cool application for such an accelerometer (outside the scope of safeguarding your hard disk platters if your laptop should fall of course), and that is the usage of it in combination with google street view. You could see the real life environment around the mobile's screen and the virtual environment was sort of a layer above the real life environment. So if you moved the mobile to the left, the layer followed along nicely...

This is also known as Augmented reality, and it's totally awesome big_smile

Offline

#15 2009-08-18 09:59:06

veox
Member
Registered: 2008-10-28
Posts: 48
Website

Re: HP accelerometer and compiz rotating cube

There's a BOINC project called Quake Catcher Network, they (intend to) use computers with accelerometers for early warnings about earthquakes. I'm not sure their Linux client is up-to-date, though, and whether it supports this HP accelerometer.

Offline

Board footer

Powered by FluxBB