disconnect

This commit is contained in:
Frank DeMarco 2018-09-21 13:09:23 -04:00
parent eec39049fa
commit 090a41549d
2 changed files with 27 additions and 0 deletions

16
NS.py
View File

@ -7,6 +7,7 @@ from glob import iglob
from os.path import basename, join from os.path import basename, join
from threading import Thread from threading import Thread
from serial import Serial from serial import Serial
from serial.tools import list_ports
from pygame import Surface, Color from pygame import Surface, Color
from pygame.event import clear from pygame.event import clear
@ -75,6 +76,12 @@ class NS(Game, Animation):
self.serial_kill = False self.serial_kill = False
self.serial_data = 0 self.serial_data = 0
self.serial_reader = Serial(self.get_configuration("input", "arduino-port"), timeout=.1) 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 = Thread(target=self.read_serial)
self.serial_thread.start() self.serial_thread.start()
self.last_press = get_ticks() self.last_press = get_ticks()
@ -94,6 +101,9 @@ class NS(Game, Animation):
def read_serial(self): def read_serial(self):
while not self.serial_kill: 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() output = self.serial_reader.readline().strip()
if output: if output:
self.serial_data = int(output, 2) self.serial_data = int(output, 2)
@ -103,6 +113,7 @@ class NS(Game, Animation):
def end(self, evt): def end(self, evt):
if evt.type == QUIT or self.delegate.compare(evt, "quit"): if evt.type == QUIT or self.delegate.compare(evt, "quit"):
print "kill serial"
self.serial_kill = True self.serial_kill = True
Game.end(self, evt) Game.end(self, evt)
@ -804,6 +815,10 @@ class Platform(GameChild):
def __init__(self, parent): def __init__(self, parent):
GameChild.__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 = [ self.lights = [
Light(self, "cyan", NS.LNW), Light(self, "cyan", NS.LNW),
Light(self, "magenta", NS.LNE), Light(self, "magenta", NS.LNE),
@ -931,6 +946,7 @@ class Platform(GameChild):
if self.active: if self.active:
for light in self.lights: for light in self.lights:
light.update() light.update()
# self.border.update()
for light in self.lights: for light in self.lights:
light.draw_glow() light.draw_glow()

View File

@ -15,3 +15,14 @@
171204 171204
256769 256769
312561 312561
242763
230604
234298
335281
156682
234931
184682
237113
254185
209634
150791