This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTestUI_BT.py
executable file
·68 lines (55 loc) · 1.67 KB
/
TestUI_BT.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
import pygame, sys,os
from pygame.locals import *
import socket
import time
from bluetooth import *
class TestUI():
def __init__(self):
pygame.init()
window = pygame.display.set_mode((60, 60))
pygame.display.set_caption('Roombot controller')
screen = pygame.display.get_surface()
pygame.display.flip()
self.state = [0,0,0,0,0,0,0,0]
self.keyList = [K_UP, K_LEFT, K_RIGHT, K_PERIOD, K_SLASH, K_RETURN, K_RSHIFT, K_SPACE]
uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
service_matches = find_service( uuid = uuid, address = "00:15:83:07:D2:54" )
if len(service_matches) == 0:
print "couldn't find the SampleServer service =("
sys.exit(0)
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
print "connecting to \"%s\" on %s" % (name, host)
# Create the client socket
self.s=BluetoothSocket( RFCOMM )
self.s.connect((host, port))
def refreshState(self):
for event in pygame.event.get():
if event.type == QUIT:
print event
sys.exit(0)
elif event.type == KEYDOWN:
try:
bit = self.keyList.index(event.key)
self.state[bit] = 1
print "set bit on: " + str(bit)
except ValueError:
#Nothing happens here cause we dont care about that key
pass
elif event.type == KEYUP:
try:
bit = self.keyList.index(event.key)
self.state[bit] = 0
print "set bit off: " + str(bit)
except ValueError:
pass
#Nothing happens here cause we dont care about that key
self.s.send(bytearray(self.state))
return
ui = TestUI()
while True:
ui.refreshState()
time.sleep(0.05) #set our loop rate// 20Hz