"""Watch the pinch gestures fh-tracker publishes, live: begins, ends, and drags. usage: python3 tools/watch_gestures.py [--every S] [--distance] Prints a line when a pinch begins or ends on either hand. It goes by the counters, so a quick tap between two reads still shows. While a pinch is held, every --every seconds (default 0.1) it prints how far the pinch 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, to see how close a pinch comes to the thresholds. """ import argparse import mmap import os import struct import time HDR = struct.Struct('<8sIIQQQff16x') # 64 bytes PINCH = struct.Struct('= begin_ns else 0 print('%s pinch %s after %.2f s' % (SIDES[k], 'LOST' if flags & LOST else 'END', held), flush=True) seen[k] = (begins, ends) if flags & DOWN and now - last_drag >= a.every: d = [point[i] - begin_point[i] for i in range(3)] print('%s drag %+6.1f %+6.1f %+6.1f mm (%.0f mm)' % (SIDES[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 q in p) 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[k].strip(), 'd %.3f s %.2f' % (q[6], q[7]) if q[0] & TRACKED else '-') for k, q in enumerate(p)), flush=True) time.sleep(0.005) if __name__ == '__main__': main()