sample
This commit is contained in:
parent
fe8156c1a7
commit
323b3bc45a
1 changed files with 12 additions and 8 deletions
20
main.py
20
main.py
|
@ -6,6 +6,14 @@ import sys
|
|||
import libevdev
|
||||
#from libevdev import ecodes
|
||||
MULTICAST_TTL = 4
|
||||
def send(socket,x,y):
|
||||
|
||||
packet = struct.pack('<HH', int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080))
|
||||
|
||||
# Send the packet over UDP
|
||||
sock.sendto(packet, (dest_ip, dest_port))
|
||||
print(f"Sent {len(packet)} bytes.")
|
||||
|
||||
def main(device_path, dest_ip, dest_port):
|
||||
"""
|
||||
Reads absolute X and Y coordinates from an evdev device and sends them
|
||||
|
@ -34,7 +42,8 @@ def main(device_path, dest_ip, dest_port):
|
|||
# Variables to store the latest coordinates
|
||||
x_coor = None
|
||||
y_coor = None
|
||||
|
||||
send(69,69)
|
||||
send(69,69)
|
||||
# Loop indefinitely to read events
|
||||
while True:
|
||||
for e in d.events():
|
||||
|
@ -53,13 +62,8 @@ def main(device_path, dest_ip, dest_port):
|
|||
# The format string 'HH' specifies two unsigned short integers (u16).
|
||||
# The '<' character ensures little-endian byte order.
|
||||
try:
|
||||
packet = struct.pack('<HH', int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080))
|
||||
|
||||
# Send the packet over UDP
|
||||
sock.sendto(packet, (dest_ip, dest_port))
|
||||
print(f"Sent {len(packet)} bytes.")
|
||||
|
||||
# Reset coordinates to wait for the next pair of events
|
||||
send(sock,int((float(x_coor)/32767.0)*1920), int((float(y_coor)/32767.0)*1080))
|
||||
# Reset coordinates to wait for the next pair of events
|
||||
x_coor = None
|
||||
y_coor = None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue