add activity test to gpio
This commit is contained in:
parent
fa481631f2
commit
bccc8bb6f0
5
NS.py
5
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):
|
||||
|
|
24
gpio.py
24
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])}")
|
||||
|
|
Loading…
Reference in New Issue