quickstep: make code Python3 compatible

Most changes were done automatically by `2to3`. Extraneous parentheses
were then removed from some `print` calls, and string encoding/decoding
was added for serial communication.

TEST=`python -m quickstep.qstep /dev/input/event4` with WALT device
BUG=b:233756427

Change-Id: Id73d52fcc503c64003d921ac97738f1892da583a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/touchbot/+/3688036
Tested-by: Sean O'Brien <[email protected]>
Owners-Override: Jeffrey Kardatzke <[email protected]>
Commit-Queue: Sean O'Brien <[email protected]>
Reviewed-by: Kenneth Albanowski <[email protected]>
diff --git a/OWNERS b/OWNERS
index 454dd93..1e4c307 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,2 +1,9 @@
 set noparent
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
\ No newline at end of file
diff --git a/quickstep/latency_measurement.py b/quickstep/latency_measurement.py
index e216a6d..23b6bc1 100644
--- a/quickstep/latency_measurement.py
+++ b/quickstep/latency_measurement.py
@@ -27,14 +27,14 @@
 #   5.) Crunch the numbers by passing both file names to this script
 #           python latency_measurement.py evtest_log.txt quickstep_log.txt
 
-import commands
+import subprocess
 import json
 import numpy as np
 import re
 import sys
 from collections import namedtuple
 
-import ppm
+from . import ppm
 
 
 FingerPosition = namedtuple('FingerPosition', ['timestamp', 'x', 'y'])
@@ -88,7 +88,7 @@
     """
     QUICKSTEP_LOG_REGEX = '^\s*([\d.]+)\s+(\d)\s*$'
 
-    status, raw_log = commands.getstatusoutput('cat %s' % filename)
+    status, raw_log = subprocess.getstatusoutput('cat %s' % filename)
     if status:
         return None
 
@@ -211,7 +211,7 @@
     positions, laser_crossings = \
                         clip_timeframes(finger_positions, laser_crossings)
     if not positions or not laser_crossings:
-        print 'ERROR: There are no overlapping events in the input'
+        print('ERROR: There are no overlapping events in the input')
         return []
 
     # Find the points where the laser was crossed
@@ -276,19 +276,19 @@
 
     latencies = measure_latencies(positions, laser_crossings, 'out.ppm')
     if not latencies:
-        print 'ERROR: Unable to compute any latencies'
+        print('ERROR: Unable to compute any latencies')
         return
 
     # Display the results
-    print 'Average', 'Maximum', 'Minimum'
-    print np.average(latencies), max(latencies), min(latencies)
-    print
-    print 'Latency result: %f ms' % (np.average(latencies) * 1000.0)
+    print('Average', 'Maximum', 'Minimum')
+    print(np.average(latencies), max(latencies), min(latencies))
+    print()
+    print('Latency result: %f ms' % (np.average(latencies) * 1000.0))
 
 
 if __name__ == '__main__':
     if len(sys.argv) != 3:
-        print 'Usage: %s evtest_log.txt quickstep_log.txt' % sys.argv[0]
+        print('Usage: %s evtest_log.txt quickstep_log.txt' % sys.argv[0])
         sys.exit(1)
     evtest_log_filename = sys.argv[1]
     quickstep_log_filename = sys.argv[2]
diff --git a/quickstep/minimization.py b/quickstep/minimization.py
index ab6c495..eeff59a 100644
--- a/quickstep/minimization.py
+++ b/quickstep/minimization.py
@@ -6,7 +6,7 @@
 # QuickStep laser crossing timestamps
 
 import numpy
-import latency_measurement as lm
+from . import latency_measurement as lm
 
 
 debug_mode = False
diff --git a/quickstep/qstep.py b/quickstep/qstep.py
index a9ee6fc..f738a0f 100644
--- a/quickstep/qstep.py
+++ b/quickstep/qstep.py
@@ -29,8 +29,8 @@
 import serial
 import numpy
 
-import latency_measurement as lm
-import minimization
+from . import latency_measurement as lm
+from . import minimization
 
 
 # Teensy commands (always singe char). Defined in QuickStep.ino
@@ -56,8 +56,8 @@
 
     """
     t0 = time.time()
-    ser.write(data)
-    reply = ser.readline()
+    ser.write(data.encode())
+    reply = ser.readline().decode()
     t1 = time.time()
     dt = (t1 - t0) * 1000
     log('sndrcv(): round trip %.3fms, reply=%s' % (dt, reply.strip()))
@@ -202,7 +202,7 @@
         trigger_count = 0
         while trigger_count < args.n:
             # The following line blocks until a message from QuickStep arrives
-            trigger_line = ser.readline()
+            trigger_line = ser.readline().decode()
             trigger_count += 1
             log('#%d/%d - ' % (trigger_count, args.n) +
                 trigger_line.strip())
@@ -220,5 +220,5 @@
     # Send SIGTERM to evtest process
     evtest.terminate()
 
-    print "\nProcessing data, may take a minute or two..."
+    print("\nProcessing data, may take a minute or two...")
     lm.main(evtest_file_name, laser_file_name)