Skip to content

Commit 038fa76

Browse files
committed
autopep8 & comments
1 parent c089e5b commit 038fa76

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

client_win-mac-nix/main.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,31 @@ class POINT(ctypes.Structure):
4040

4141

4242
# initialize networking
43-
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Read datagrams over UDP
44-
sock.settimeout(1) # Without a timeout, this script will "hang" if nothing is received
43+
# Read datagrams over UDP
44+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
45+
# Without a timeout, this script will "hang" if nothing is received
46+
sock.settimeout(1)
4547
sock.bind((args.host, args.port)) # Register our socket
4648

4749
# How to get local IP address?
4850
# Doesn't work for me: socket.gethostbyname(socket.gethostname())
49-
# For now, just manually go to settings -> Wi-fi and look up your *local* IP address.
50-
# It will be something like 192.x.x.x or 10.x.x.x
51-
# This is not your public Internet address. This is your local area network address.
52-
# On Windows, make sure it's set to a private network to allow discovery.
53-
# You'd think public would allow discovery, but when you are *in public* - like at a coffee shop - you don't want strangers to access your PC.
51+
# For now, just manually go to settings -> Wi-fi and look up your *local* IP
52+
# address. It will be something like 192.x.x.x or 10.x.x.x This is not your
53+
# public Internet address. This is your local area network address. On Windows,
54+
# make sure it's set to a private network to allow discovery. You'd think public
55+
# would allow discovery, but when you are *in public* - like at a coffee shop -
56+
# you don't want strangers to access your PC.
5457
text_listening = (
55-
f"Listening on {sock.getsockname()} for mouse data from Raspberry Pi server..."
58+
f"Listening on {
59+
sock.getsockname()} for mouse data from Raspberry Pi server..."
5660
)
5761
print(ctime() + " - " + text_listening)
5862
print("\nPress Ctrl-C to exit\n")
5963

6064

61-
# Stats for debugging & performance.
62-
# The goal is 60 frames per second, or 16.67ms per frame.
63-
# That leads to a very smooth mouse cursor. (SmartNav was 100 fps)
64-
# A standard non-gaming monitor is also 60Hz. (TV is 30 fps)
65+
# Stats for debugging & performance. The goal is 60 frames per second, or
66+
# 16.67ms per frame. That leads to a very smooth mouse cursor. (SmartNav was 100
67+
# fps) A standard non-gaming monitor is also 60Hz. (TV is 30 fps)
6568
@dataclass
6669
class PhilNavDebug:
6770
time_start = time()
@@ -78,9 +81,11 @@ class PhilNavDebug:
7881
# 3. Repeat forever until Ctrl-C
7982
while True:
8083
try:
81-
# 48 bytes of 6 doubles in binary C format. Why? Because it's OpenTrack's protocol.
84+
# 48 bytes of 6 doubles in binary C format. Why? Because it's
85+
# OpenTrack's protocol.
8286
# x, y, z, pitch, yaw, roll = struct.unpack('dddddd', data)
83-
# PhilNav uses x, y as x_diff, y_diff and moves the mouse relative to its current position.
87+
# PhilNav uses x, y as x_diff, y_diff and moves the mouse relative to
88+
# its current position.
8489
# https://github.com/opentrack/opentrack/issues/747
8590
data, addr = sock.recvfrom(48)
8691
except TimeoutError:
@@ -101,13 +106,17 @@ class PhilNavDebug:
101106
ctypes.windll.user32.GetCursorPos(
102107
ctypes.byref(pt)
103108
) # get current mouse position by reference (C++ thing)
104-
# I'm moving the Y axis slightly faster because looking left and right is easier than nodding up and down.
105-
# Also, monitors are wider than they are tall.
109+
# I'm moving the Y axis slightly faster because looking left and right
110+
# is easier than nodding up and down. Also, monitors are wider than they
111+
# are tall.
106112
x_new = round(pt.x + x * args.speed)
107113
y_new = round(pt.y + y * args.speed * 1.33)
108114
ctypes.windll.user32.SetCursorPos(x_new, y_new) # move mouse cursor
109115

110-
# I'm trying to measure the total time from capturing the frame on the camera to moving the mouse cursor on my PC. This isn't super accurate. It's sometimes negative (TIME TRAVEL!!!). The clock difference between the Raspberry Pi and my PC seems to be around 10-20ms?
116+
# I'm trying to measure the total time from capturing the frame on the
117+
# camera to moving the mouse cursor on my PC. This isn't super accurate.
118+
# It's sometimes negative (TIME TRAVEL!!!). The clock difference between
119+
# the Raspberry Pi and my PC seems to be around 10-20ms?
111120
time_diff_ms = int((time() - roll) * 1000)
112121

113122
# it's 60 FPS, so only debug once per second
@@ -117,8 +126,10 @@ class PhilNavDebug:
117126
# display legend every 5 seconds
118127
if PhilNavDebug.debug_num % 5 == 1:
119128
logging.info(
120-
f" {ctime()} - Received: ({'x_diff':>8},{'y_diff':>8},{'n/a':>8},{'n/a':>8},{'loc ns':>8},{'net ms':>8} )"
129+
f" {ctime()} - Received: ({'x_diff':>8},{'y_diff':>8},{
130+
'n/a':>8},{'n/a':>8},{'loc ns':>8},{'net ms':>8} )"
121131
)
122132
logging.info(
123-
f" {ctime()} - Received: ({x:> 8.2f},{y:> 8.2f},{z:> 8.2f},{pitch:> 8.2f},{(time() - PhilNavDebug.msg_time_start)*1000:> 8.2f},{time_diff_ms:> 8} )"
133+
f" {ctime()} - Received: ({x:> 8.2f},{y:> 8.2f},{z:> 8.2f},{pitch:> 8.2f},{
134+
(time() - PhilNavDebug.msg_time_start)*1000:> 8.2f},{time_diff_ms:> 8} )"
124135
)

0 commit comments

Comments
 (0)