disconnect
This commit is contained in:
parent
eec39049fa
commit
090a41549d
16
NS.py
16
NS.py
|
@ -7,6 +7,7 @@ from glob import iglob
|
|||
from os.path import basename, join
|
||||
from threading import Thread
|
||||
from serial import Serial
|
||||
from serial.tools import list_ports
|
||||
|
||||
from pygame import Surface, Color
|
||||
from pygame.event import clear
|
||||
|
@ -75,6 +76,12 @@ class NS(Game, Animation):
|
|||
self.serial_kill = False
|
||||
self.serial_data = 0
|
||||
self.serial_reader = Serial(self.get_configuration("input", "arduino-port"), timeout=.1)
|
||||
# for port in list_ports.comports():
|
||||
# print port.device
|
||||
# print "---"
|
||||
# ports = list_ports.grep(self.get_configuration("input", "arduino-port"))
|
||||
# for port in ports:
|
||||
# print port.device
|
||||
self.serial_thread = Thread(target=self.read_serial)
|
||||
self.serial_thread.start()
|
||||
self.last_press = get_ticks()
|
||||
|
@ -94,6 +101,9 @@ class NS(Game, Animation):
|
|||
|
||||
def read_serial(self):
|
||||
while not self.serial_kill:
|
||||
name = self.get_configuration("input", "arduino-port")
|
||||
if name not in (port.device for port in list_ports.comports()):
|
||||
print "%s disconnected" % name
|
||||
output = self.serial_reader.readline().strip()
|
||||
if output:
|
||||
self.serial_data = int(output, 2)
|
||||
|
@ -103,6 +113,7 @@ class NS(Game, Animation):
|
|||
|
||||
def end(self, evt):
|
||||
if evt.type == QUIT or self.delegate.compare(evt, "quit"):
|
||||
print "kill serial"
|
||||
self.serial_kill = True
|
||||
Game.end(self, evt)
|
||||
|
||||
|
@ -804,6 +815,10 @@ class Platform(GameChild):
|
|||
|
||||
def __init__(self, parent):
|
||||
GameChild.__init__(self, parent)
|
||||
dsr = self.get_display_surface().get_rect()
|
||||
self.border = Sprite(self)
|
||||
self.border.load_from_path(self.get_resource("DancePadClear.png"), True)
|
||||
self.border.location.midbottom = dsr.centerx, dsr.bottom
|
||||
self.lights = [
|
||||
Light(self, "cyan", NS.LNW),
|
||||
Light(self, "magenta", NS.LNE),
|
||||
|
@ -931,6 +946,7 @@ class Platform(GameChild):
|
|||
if self.active:
|
||||
for light in self.lights:
|
||||
light.update()
|
||||
# self.border.update()
|
||||
for light in self.lights:
|
||||
light.draw_glow()
|
||||
|
||||
|
|
|
@ -15,3 +15,14 @@
|
|||
171204
|
||||
256769
|
||||
312561
|
||||
242763
|
||||
230604
|
||||
234298
|
||||
335281
|
||||
156682
|
||||
234931
|
||||
184682
|
||||
237113
|
||||
254185
|
||||
209634
|
||||
150791
|
||||
|
|
Loading…
Reference in New Issue