• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import re
2from numpy import array
3
4TIME = 'time'
5VALUE = 'value'
6AXIS = 'axis'
7
8re_xy = re.compile(r'.*time (?P<time>\d+\.\d+), type \d+ \(EV_ABS\), code \d+ \(ABS_(?P<axis>[XY])\), value (?P<value>\d+)')
9re_tap = re.compile(r'.*time (?P<time>\d+\.\d+), type \d+ \(EV_KEY\), code \d+ \(BTN_TOUCH\), value (?P<value>\d+)')
10
11
12def 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
26def 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