Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Sun Dec 4 23:16:26 2016
  5.  
  6. @author: sheldom
  7.  
  8.  
  9. mouse = file('/dev/input/mouse0')
  10. while True:
  11. status, dx, dy = tuple(ord(c) for c in mouse.read(3))
  12.  
  13. def to_signed(n):
  14. return n-((0x80 & n) << 1)
  15.  
  16. dx = to_signed(dx)
  17. dy = to_signed(dy)
  18. print "%#02x %d %d" % (status, dx, dy)
  19.  
  20. """
  21.  
  22. import struct
  23. #import numpy as np
  24. import time
  25. import csv
  26.  
  27.  
  28. file = open( "/dev/input/mice", "rb" );
  29.  
  30. def getMouseEvent():
  31. buf = file.read(3);
  32. # button = ord( buf[0] );
  33. # bLeft = button & 0x1;
  34. # bMiddle = ( button & 0x4 ) > 0;
  35. # bRight = ( button & 0x2 ) > 0;
  36. x,y = struct.unpack( "bb", buf[1:] );
  37. print ("x: %d, y: %d\n" % (x, y) );
  38. return int(x), int(y)
  39. # return stuffs
  40.  
  41. def int_aprox_trap(f,xMin,xMax,numDiv):
  42.  
  43. deltaX=(xMax -xMin)/float(numDiv)
  44.  
  45. inte=(f(xMin) + f(xMax))/2.0
  46.  
  47. k=1
  48.  
  49. while k < numDiv:
  50.  
  51. inte += f(xMin + k*deltaX)
  52.  
  53. k += 1
  54.  
  55. return inte * deltaX
  56. i=0
  57. lista = []
  58. while( i<2000 ):
  59. i=i+1
  60. dx,dy=getMouseEvent();
  61.  
  62. lista.extend([[i,dx,dy]])
  63. time.sleep(0.001)
  64. print(i)
  65.  
  66. file.close();
  67. print(lista)
  68.  
  69. #f = open('datos.csv','w')
  70. #f.write('i,Dx,Dy\n')
  71. with open("output.csv", "wb") as f:
  72. writer = csv.writer(f)
  73. writer.writerows(lista)
  74.  
  75.  
  76.  
  77.  
  78. f.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement