Image

Image

Search This Blog

Monday, July 11, 2011

rotate kde cube using the accelerometer

ain't that fun? tilt the laptop and the cube rotates :) all thanks to the ST LIS3LV02DL Accelerometer
#!/bin/bash
# kde-cube-rotate
#

while true ; do
# vertical axis
#POS1=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$2}'`
#sleep .1
#POS2=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$2}'`
#horizontal axis
POS1=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$1}' | awk -F "(" '{print$2}'`
#sleep .1
POS2=`cat /sys/devices/platform/lis3lv02d/position | awk -F , '{print$1}' | awk -F "(" '{print$2}'`

DIS=$( wmctrl -d | grep "*" | awk '{sub(/x[0-9]+/, "", $1); print $1}'| tail -n1)
((POS=$POS1-$POS2))

#echo "pos1=$POS1 pos2=$POS2 pos=$POS display=$DIS"

if [ $POS -ge 20 ]; then
wmctrl -s $(( ${DIS} - 1 )) 2>/dev/null
sleep 1

elif [ $POS -le -20 ]; then
wmctrl -s $(( ${DIS} + 1 )) 2>/dev/null
sleep 1

fi
done

Blog Archive