add activity test to gpio

This commit is contained in:
ohsqueezy 2022-11-05 01:33:05 -04:00
parent fa481631f2
commit bccc8bb6f0
2 changed files with 21 additions and 8 deletions

5
NS.py
View File

@ -244,6 +244,7 @@ class NS(Game, Animation):
gpio.initialize_gpio() gpio.initialize_gpio()
# Launch a separate thread for reading the GPIO (and allowing its custom delays/sleeps) # Launch a separate thread for reading the GPIO (and allowing its custom delays/sleeps)
self.gpio_kill = False
self.gpio_thread = Thread(target=self.read_gpio) self.gpio_thread = Thread(target=self.read_gpio)
self.gpio_thread.start() self.gpio_thread.start()
@ -337,7 +338,8 @@ class NS(Game, Animation):
""" """
Test all connections of GPIO input pins. Test all connections of GPIO input pins.
""" """
pass while not self.gpio_kill:
self.gpio_data = gpio.activity()
def read_serial(self): def read_serial(self):
while not self.serial_kill: while not self.serial_kill:
@ -379,6 +381,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"):
self.serial_kill = True self.serial_kill = True
self.gpio_kill = True
Game.end(self, evt) Game.end(self, evt)
def apply_serial(self): def apply_serial(self):

24
gpio.py
View File

@ -11,7 +11,7 @@
# #
# When run as a script, it prints connections detected between the input GPIO pins. # When run as a script, it prints connections detected between the input GPIO pins.
import time, itertools import time, itertools, argparse
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
# These represent the game pads and the GPIO pins they're connected to # These represent the game pads and the GPIO pins they're connected to
@ -103,12 +103,22 @@ def activity():
return state return state
if __name__ == "__main__": if __name__ == "__main__":
# Set up and parse CLI
parser = argparse.ArgumentParser()
parser.add_argument("--connections", action="store_true")
parser.add_argument("--activity", action="store_true")
arguments = parser.parse_args()
initialize_gpio() initialize_gpio()
while True: while True:
# Try all connections once each frame if arguments.connections or not arguments.activity:
for connection_ids, connection_state in connections().items(): # Try all connections once each frame
# Only print connected combinations of pins for connection_ids, connection_state in connections().items():
if connection_state: # Only print connected combinations of pins
pin_id_a, pin_id_b = connection_ids if connection_state:
print(f"{pin_id_a} ({pins[pin_id_a]}) <-> {pin_id_b} ({pins[pin_id_b]})") pin_id_a, pin_id_b = connection_ids
print(f"{pin_id_a} ({pins[pin_id_a]}) <-> {pin_id_b} ({pins[pin_id_b]})")
else:
pin_activity = activity()
print(f"LNW {int(pin_activity[LNW])} LNE {int(pin_activity[LNE])} LSE {int(pin_activity[LSE])} LSW {int(pin_activity[LSW])}")