-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraScript.py
48 lines (37 loc) · 1.02 KB
/
CameraScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import struct
import time
import pyautogui
import sock as sock
import win32api, win32con
import serial as com
import socket
hw, hh = 1920 // 2, 1080 // 2
dd = 0.1 # joystick dead zone
speed = 3 # xplane camera speed
cx, cy, d = hw, hh, 0
hostname = socket.gethostname()
UDP_IP = socket.gethostbyname(hostname)
print(UDP_IP)
time.sleep(10)
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.settimeout(1)
sock.bind((UDP_IP, UDP_PORT))
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, cx, cy, 0, 0)
while True:
try:
data, addr = sock.recvfrom(41)
rx = -struct.unpack('f', data[9:13])[0]
speed_mul = abs(rx) * 2
if rx > dd: # turn
d = min(d + speed * speed_mul, hw)
elif rx < -dd:
d = max(d - speed * speed_mul, -hw)
else:
pass
#d = d / 1.05
win32api.SetCursorPos((int(cx + d), int(cy)))
except Exception as e:
time.sleep(1)
print(e)