Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- # -*- coding: utf-8 -*-
- """
- Created on Sun Dec 4 23:16:26 2016
- @author: sheldom
- mouse = file('/dev/input/mouse0')
- while True:
- status, dx, dy = tuple(ord(c) for c in mouse.read(3))
- def to_signed(n):
- return n-((0x80 & n) << 1)
- dx = to_signed(dx)
- dy = to_signed(dy)
- print "%#02x %d %d" % (status, dx, dy)
- """
- import struct
- #import numpy as np
- import time
- import csv
- file = open( "/dev/input/mice", "rb" );
- def getMouseEvent():
- buf = file.read(3);
- # button = ord( buf[0] );
- # bLeft = button & 0x1;
- # bMiddle = ( button & 0x4 ) > 0;
- # bRight = ( button & 0x2 ) > 0;
- x,y = struct.unpack( "bb", buf[1:] );
- print ("x: %d, y: %d\n" % (x, y) );
- return int(x), int(y)
- # return stuffs
- def int_aprox_trap(f,xMin,xMax,numDiv):
- deltaX=(xMax -xMin)/float(numDiv)
- inte=(f(xMin) + f(xMax))/2.0
- k=1
- while k < numDiv:
- inte += f(xMin + k*deltaX)
- k += 1
- return inte * deltaX
- i=0
- lista = []
- while( i<2000 ):
- i=i+1
- dx,dy=getMouseEvent();
- lista.extend([[i,dx,dy]])
- time.sleep(0.001)
- print(i)
- file.close();
- print(lista)
- #f = open('datos.csv','w')
- #f.write('i,Dx,Dy\n')
- with open("output.csv", "wb") as f:
- writer = csv.writer(f)
- writer.writerows(lista)
- f.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement