"""Watch the gestures ft-hands publishes, live: pinches and grips, begins, ends, and drags. usage: python3 tools/watch_gestures.py [--every S] [--distance] Prints a line when a pinch or a grip (a closed hand) begins or ends on either hand. It goes by the counters, so a quick tap between two reads still shows. While one is held, every --every seconds (default 0.1) it prints how far its point has moved since it began, in the head frame (turning your head moves it too; a real consumer turns both points into the room first, see include/fh_gestures.h). --distance also prints each hand's thumb-to-index distance and finger curl, to see how close a gesture comes to the thresholds. Version 1 files (pinches only) still work. """ import argparse import mmap import os import struct import time HDR = struct.Struct('<8sIIQQQffff8x') # 64 bytes SLOT = struct.Struct('= 2 and len(m) >= HDR.size + 4 * SLOT.size else 1 g = [[SLOT.unpack_from(m, HDR.size + (k * 2 + s) * SLOT.size) for s in range(2)] for k in range(kinds)] if kinds == 1: g.append([(0,) * 14, (0,) * 14]) if struct.unpack_from('= begin_ns else 0 print('%s %s %s after %.2f s' % (SIDES[s], KINDS[k], 'LOST' if flags & LOST else 'END', held), flush=True) seen[k][s] = (begins, ends) if flags & DOWN and now - last_drag >= a.every: d = [point[i] - begin_point[i] for i in range(3)] print('%s %s drag %+6.1f %+6.1f %+6.1f mm (%.0f mm)' % (SIDES[s], KINDS[k], *(1000 * x for x in d), 1000 * sum(x * x for x in d) ** 0.5), flush=True) if any(q[0] & DOWN for kind in g for q in kind) and now - last_drag >= a.every: last_drag = now if a.distance and now - last_dist >= 0.2: last_dist = now print(' ' + ' '.join( '%s %s' % (SIDES[s].strip(), 'd %.3f curl %.2f' % (g[0][s][6], g[1][s][6]) if g[0][s][0] & TRACKED else '-') for s in range(2)), flush=True) time.sleep(0.005) if __name__ == '__main__': main()