From bccc8bb6f0d8322a8d826a2440b7f854ba0cee4c Mon Sep 17 00:00:00 2001 From: frank Date: Sat, 5 Nov 2022 01:33:05 -0400 Subject: [PATCH] add activity test to gpio --- NS.py | 5 ++++- gpio.py | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/NS.py b/NS.py index 4c8240f..48b577a 100644 --- a/NS.py +++ b/NS.py @@ -244,6 +244,7 @@ class NS(Game, Animation): gpio.initialize_gpio() # 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.start() @@ -337,7 +338,8 @@ class NS(Game, Animation): """ Test all connections of GPIO input pins. """ - pass + while not self.gpio_kill: + self.gpio_data = gpio.activity() def read_serial(self): while not self.serial_kill: @@ -379,6 +381,7 @@ class NS(Game, Animation): 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): diff --git a/gpio.py b/gpio.py index 93a1e8b..666fcf9 100644 --- a/gpio.py +++ b/gpio.py @@ -11,7 +11,7 @@ # # 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 # These represent the game pads and the GPIO pins they're connected to @@ -103,12 +103,22 @@ def activity(): return state 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() while True: - # Try all connections once each frame - for connection_ids, connection_state in connections().items(): - # Only print connected combinations of pins - if connection_state: - pin_id_a, pin_id_b = connection_ids - print(f"{pin_id_a} ({pins[pin_id_a]}) <-> {pin_id_b} ({pins[pin_id_b]})") + if arguments.connections or not arguments.activity: + # Try all connections once each frame + for connection_ids, connection_state in connections().items(): + # Only print connected combinations of pins + if connection_state: + 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])}")