Home | History | Annotate | Download | only in pywalt
      1 import re
      2 from numpy import array
      3 
      4 TIME = 'time'
      5 VALUE = 'value'
      6 AXIS = 'axis'
      7 
      8 re_xy = re.compile(r'.*time (?P<time>\d+\.\d+), type \d+ \(EV_ABS\), code \d+ \(ABS_(?P<axis>[XY])\), value (?P<value>\d+)')
      9 re_tap = re.compile(r'.*time (?P<time>\d+\.\d+), type \d+ \(EV_KEY\), code \d+ \(BTN_TOUCH\), value (?P<value>\d+)')
     10 
     11 
     12 def load_xy(fname):
     13     with open(fname, 'rt') as f:
     14         match_iter = (re_xy.search(line) for line in f)
     15         events = [m.groupdict() for m in match_iter if m]
     16 
     17     x = array([int(e[VALUE]) for e in events if e[AXIS] == 'X'])
     18     tx = array([float(e[TIME]) for e in events if e[AXIS] == 'X'])
     19 
     20     y = array([int(e[VALUE]) for e in events if e[AXIS] == 'Y'])
     21     ty = array([float(e[TIME]) for e in events if e[AXIS] == 'Y'])
     22 
     23     return (tx, x, ty, y)
     24 
     25 
     26 def parse_tap_line(line):
     27     m = re_tap.search(line)
     28     if not m:
     29         return None
     30 
     31     t = float(m.group(TIME))
     32     val = int(m.group(VALUE))
     33     return (t, val)
     34