Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 20 Oct 2014, 09:31
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Mouse movement identification using RAW data from ports
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
matiasbatero


Joined: 11 Oct 2012
Posts: 60
Location: Mar del Plata, Argentina

PostPosted: Fri 22 Nov 2013, 12:29    Post subject:  Mouse movement identification using RAW data from ports
Subject description: A bash script to process raw data from PS2/USB ports to detect mouse movements (low level)
 

Hi people,

Months ago, i wanted to build a movement sensor using my mouse as main device. The main idea was do a device that allow detect displacements < 1mm, if function of the time. In mechanical, it's common to do stress-strain curves as a function of time to characterize materials. The project is now on stand-by, but this script allows you to do a lot of things.

Code:

#!/bin/bash

rm /tmp/raw2 &> /dev/null
rm /tmp/result &> /dev/null

hexcat /dev/psaux > /tmp/raw2 &

basetime=$(date +%s%N)

value(){

r=($(tail -1 /tmp/result | cut -d\  -f1\ 2))

case "$(tail -1 /tmp/raw2 | cut -b 12-19)" in
   
   "08 00 01")
   x=$((${r[0]}+0))
   y=$((${r[1]}+1))
   state="↑"
   ;;
   
   "28 00 ff")
   x=$((${r[0]}+0))
   y=$((${r[1]}-1))
   state="↓"
   ;;
   
   "18 ff 00")
   x=$((${r[0]}-1))
   y=$((${r[1]}+0))
   state="←"
   ;;
   
   "08 01 00")
   x=$((${r[0]}+1))
   y=$((${r[1]}+0))
   state="→"
   ;;
   
   "38 ff ff")
   x=$((${r[0]}-1))
   y=$((${r[1]}-1))
   state="↙"
   ;;
   
   "18 ff 01")
   x=$((${r[0]}-1))
   y=$((${r[1]}+1))
   state="↖"
   ;;
   
   "08 01 01")
   x=$((${r[0]}+1))
   y=$((${r[1]}+1))
   state="↗"
   ;;
   
   "28 01 ff")
   x=$((${r[0]}+1))
   y=$((${r[1]}-1))
   state="↘"
   ;;
      
esac

}


while :
   do
      ( cat /dev/psaux > /dev/full ) 2> /dev/null
      value
      echo "$state $x $y $(echo "scale=2;($(date +%s%N) - ${basetime})/(1*10^09)" | bc)s"
      echo "$x $y $(echo "scale=2;($(date +%s%N) - ${basetime})/(1*10^09)" | bc)s" >> /tmp/result
      
done



Script make a 0,0 (x,y) reference when it's launched. And then for further movements, a units +1 are added on corresponding direction.
Direction is detected looking some particular hexadecimal values from port.

TIPS:

psaux : ps2 port, you cant change it if your mouse is USB.
This is a detector, you can do a lot of things, for example you can change the "echo ouput" to detone a TNT in a mountain.

OUPUT (in action):


Code:

↗ 0 6 2.28s
→ 1 6 2.44s
↗ 2 7 2.49s
↗ 3 8 2.95s
↗ 4 9 3.21s
↑ 4 10 3.33s
↑ 4 11 3.41s
↑ 4 12 3.65s
↑ 4 12 4.61s
↗ 5 13 4.68s
↑ 5 14 4.76s
↑ 5 15 4.97s
↗ 6 16 5.48s


References:

4 columns of data:
(Direction arrow, x, y, time in seconds)

DEPENDENCIES: hexcat

you can download source code 51k:
http://archive.debian.org/debian/pool/main/h/hexcat/hexcat_0.0.3.2+nmu1.tar.gz

hope you like it!
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0514s ][ Queries: 11 (0.0068s) ][ GZIP on ]