-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptt_remote_tx.py
More file actions
executable file
·65 lines (53 loc) · 2.02 KB
/
Copy pathptt_remote_tx.py
File metadata and controls
executable file
·65 lines (53 loc) · 2.02 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
#
# Python PTT remote (TX) by barf <stuart@macintosh>
#
import os
import sys
stdout_parking = sys.stdout
sys.stdout = open(os.devnull, 'w')
import pygame
sys.stdout = stdout_parking
import time
import zmq
import pickle
import argparse
DEBUG = False
if DEBUG: from IPython import embed
if __name__=='__main__':
parser = argparse.ArgumentParser(description='Push-to-talk remote control by barf <[email protected]>')
parser.add_argument('HOST', help='FQDN or IP address of PTT remote RX host')
parser.add_argument('PORT', help='port number of PTT remote RX host')
args = parser.parse_args()
host_ip = args.HOST
host_port = args.PORT
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.sndhwm = 8
print("Connecting…")
socket.connect("tcp://%s:%s" % (host_ip, host_port))
print("Connected")
pygame.init()
clock = pygame.time.Clock()
joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
for stick in joysticks:
stick.init()
done = False
while not done:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done=True # Flag that we are done so we exit this loop
# Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION
if event.type == pygame.JOYBUTTONDOWN:
print('type: %s\tdict: %s' % (event.type, event.dict))
if DEBUG: embed()
socket.send(pickle.dumps([event.type, event.dict, time.time()]))
if event.type == pygame.JOYBUTTONUP:
print('type: %s\tdict: %s' % (event.type, event.dict))
if DEBUG: embed()
socket.send(pickle.dumps([event.type, event.dict, time.time()]))
if DEBUG: print('type: %s\tdict: %s' % (event.type, event.dict))
# time.sleep(10)
clock.tick(30)
# if DEBUG: embed()
pygame.quit()