try all detected devices when auto detecting Arduino; restore the end function's behavior which kills serial threads before quitting
This commit is contained in:
parent
d1fe534c9f
commit
66043aa393
38
NS.py
38
NS.py
|
@ -265,20 +265,33 @@ class NS(Game, Animation):
|
||||||
|
|
||||||
# If a list of serial ports was requested, print detected ports and exit.
|
# If a list of serial ports was requested, print detected ports and exit.
|
||||||
if arguments.list_serial_ports:
|
if arguments.list_serial_ports:
|
||||||
for port in list_ports.comports():
|
if list_ports.comports():
|
||||||
print(f"Detected serial port: {port.device}")
|
for port in list_ports.comports():
|
||||||
|
print(f"Detected serial port: {port.device}")
|
||||||
|
else:
|
||||||
|
print("No serial ports detected")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# Open the port specified by the configuration or command line if it is found. If the specified port is not
|
# Open the port specified by the configuration or command line if it is found. If the specified port is not
|
||||||
# found, open the first found serial port. If no serial ports are found, raise an exception.
|
# found, iterate through the com ports, and try to open each. If no serial port can be opened, raise an
|
||||||
|
# exception.
|
||||||
requested_port = self.get_configuration("input", "arduino-port")
|
requested_port = self.get_configuration("input", "arduino-port")
|
||||||
devices = [port.device for port in list_ports.comports()]
|
devices = [port.device for port in list_ports.comports()]
|
||||||
if requested_port in devices:
|
if requested_port in devices:
|
||||||
self.serial_reader = Serial(requested_port, timeout=.3)
|
self.serial_reader = Serial(requested_port, timeout=.3)
|
||||||
elif devices:
|
|
||||||
self.serial_reader = Serial(devices[0], timeout=.3)
|
|
||||||
else:
|
else:
|
||||||
raise SerialException("No serial port devices were detected. Use --no-serial for keyboard-only mode.")
|
if requested_port:
|
||||||
|
print(f"Could not connect with requested port {requested_port}. Searching for other ports.")
|
||||||
|
found = False
|
||||||
|
for device in devices:
|
||||||
|
try:
|
||||||
|
self.serial_reader = Serial(device, timeout=.3)
|
||||||
|
found = True
|
||||||
|
except SerialException:
|
||||||
|
print(f"Tried and failed to open connection with serial device {device}")
|
||||||
|
if not found:
|
||||||
|
raise SerialException("No usable serial port devices found. Use --no-serial for keyboard-only mode.")
|
||||||
|
print(f"Using serial device at port {self.serial_reader.port}")
|
||||||
self.serial_kill = False
|
self.serial_kill = False
|
||||||
self.serial_data = 0
|
self.serial_data = 0
|
||||||
self.reset_arduino()
|
self.reset_arduino()
|
||||||
|
@ -383,12 +396,6 @@ class NS(Game, Animation):
|
||||||
self.serial_reader.dtr = False
|
self.serial_reader.dtr = False
|
||||||
self.serial_reader.reset_input_buffer()
|
self.serial_reader.reset_input_buffer()
|
||||||
self.serial_reader.dtr = True
|
self.serial_reader.dtr = True
|
||||||
|
|
||||||
def end(self, evt):
|
|
||||||
if evt.type == QUIT or self.delegate.compare(evt, "quit"):
|
|
||||||
self.serial_kill = True
|
|
||||||
self.gpio_kill = True
|
|
||||||
Game.end(self, evt)
|
|
||||||
|
|
||||||
def apply_serial(self):
|
def apply_serial(self):
|
||||||
for ii, light in enumerate(self.platform.lights):
|
for ii, light in enumerate(self.platform.lights):
|
||||||
|
@ -558,6 +565,11 @@ class NS(Game, Animation):
|
||||||
"""
|
"""
|
||||||
if event.type == QUIT or self.delegate.compare(event, "quit"):
|
if event.type == QUIT or self.delegate.compare(event, "quit"):
|
||||||
if self.confirming_quit or not self.get_configuration("input", "confirm-quit"):
|
if self.confirming_quit or not self.get_configuration("input", "confirm-quit"):
|
||||||
|
|
||||||
|
# Kill serial threads
|
||||||
|
self.serial_kill = True
|
||||||
|
self.gpio_kill = True
|
||||||
|
|
||||||
# If SHIFT is pressed, try permanently stopping the systemd service to get a console back in case this is running on
|
# If SHIFT is pressed, try permanently stopping the systemd service to get a console back in case this is running on
|
||||||
# Raspbian Lite
|
# Raspbian Lite
|
||||||
if pygame.key.get_mods() & pygame.KMOD_SHIFT:
|
if pygame.key.get_mods() & pygame.KMOD_SHIFT:
|
||||||
|
@ -566,6 +578,8 @@ class NS(Game, Animation):
|
||||||
print("Killing with permanent stop sent to systemd scrapeboard service")
|
print("Killing with permanent stop sent to systemd scrapeboard service")
|
||||||
except:
|
except:
|
||||||
print("No scrapeboard system service detected, so permanent quit either failed or was unnecessary")
|
print("No scrapeboard system service detected, so permanent quit either failed or was unnecessary")
|
||||||
|
|
||||||
|
# Call parent to complete quit
|
||||||
super().end(event)
|
super().end(event)
|
||||||
|
|
||||||
|
|
||||||
|
|
4
config
4
config
|
@ -93,8 +93,8 @@ level_2 = bgm/level_2.ogg, .65
|
||||||
end = bgm/end.ogg, .65
|
end = bgm/end.ogg, .65
|
||||||
|
|
||||||
[pads]
|
[pads]
|
||||||
ne_color = #E4B80C
|
|
||||||
nw_color = #FF88FF
|
nw_color = #FF88FF
|
||||||
sw_color = #2222FF
|
ne_color = #E4B80C
|
||||||
se_color = #FF2222
|
se_color = #FF2222
|
||||||
|
sw_color = #2222FF
|
||||||
center_y = 376
|
center_y = 376
|
||||||
|
|
Loading…
Reference in New Issue