Advertisement
Guest User

Untitled

a guest
Jan 18th, 2015
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.74 KB | None | 0 0
  1. #!/bin/bash
  2. #January 2015
  3. #path="/sys/bus/iio/devices/iio:device0" #Path is not fixed! So use workaround below, which is correct
  4. path="/sys/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/*0483:91D1*/HID-SENSOR-200073.1.auto/iio:device?"
  5. margin=500000
  6. current_case=0
  7. counter=0
  8. num_iterations=2
  9.  
  10. function increase_counter
  11. {
  12.     c=$1
  13.     if [[ $c -eq $current_case ]]; then
  14.         counter=$((counter + 1))
  15.     else
  16.         current_case=$c
  17.         counter=1
  18.     fi
  19. }
  20.  
  21. sleep 1
  22.  
  23. while true; do
  24.  
  25.   y=`cat $path/in_accel_y_raw`
  26.   z=`cat $path/in_accel_z_raw`
  27.   x=`cat $path/in_accel_x_raw`
  28.  
  29. #   echo $x $y $z
  30.  
  31. if [[ $x -gt -$margin ]] && [[ $x -lt $margin ]]; then
  32.     if [[ "$y" -gt "$margin" ]]; then
  33.         increase_counter 2  
  34.         if [[ $counter -gt $num_iterations ]]; then
  35.             xrandr -o inverted
  36.             xinput set-prop 'ELAN Touchscreen' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
  37.         fi
  38.     elif [[ "$y" -lt "-$margin" ]]; then
  39.         increase_counter 0
  40.         if [[ $counter -gt $num_iterations ]]; then
  41.             xrandr -o normal
  42.             xinput set-prop 'ELAN Touchscreen' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
  43.         fi
  44.     # else, x e y intorno a 0, quindi lascia l'orientazione corrente
  45.     fi
  46. elif [[ "$x" -gt "0" ]]; then
  47.     increase_counter 3
  48.     if [[ $counter -gt $num_iterations ]]; then
  49.         xrandr -o left
  50.         xinput set-prop 'ELAN Touchscreen' 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1
  51.     fi
  52. else
  53.     increase_counter 1
  54.     if [[ $counter -gt $num_iterations ]]; then
  55.         xrandr -o right
  56.         xinput set-prop 'ELAN Touchscreen' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
  57.     fi
  58. fi
  59.  
  60.   sleep 0.02
  61. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement