From b180fe1d6f07d9ff524dbc9befe65d1565be2d89 Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sun, 24 Jul 2016 21:37:11 -0500 Subject: [PATCH] Adding my test code for Issue #14 --- test/spwmtest.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 test/spwmtest.py diff --git a/test/spwmtest.py b/test/spwmtest.py new file mode 100755 index 0000000..7e89595 --- /dev/null +++ b/test/spwmtest.py @@ -0,0 +1,57 @@ +import CHIP_IO.SOFTPWM as SPWM +import CHIP_IO.GPIO as GPIO +import time +import datetime +import threading + +class SPWMReceiver(threading.Thread): + def __init__(self,gpio,key,maxcount=20,sleeptime=0.5): + self.gpio = gpio + self.key = key + self.counter = 0 + self.maxcount = maxcount + self.sleeptime = sleeptime + threading.Thread.__init__(self) + + def run(self): + print("SETTING UP RECEIVER GPIO") + self.gpio.cleanup() + self.gpio.setup(self.key, self.gpio.IN) + print("STARTING RECEIVE LOOP") + try: + while self.counter < self.maxcount: + pwmval = self.gpio.input(self.key) + print("SPWM VALUE: {0} @ {1}".format(pwmval, datetime.datetime.now())) + time.sleep(self.sleeptime) + self.counter += 1 + except KeyboardInterrupt: + self.gpio.cleanup(self.key) + +if __name__ == "__main__": + # SETUP VARIABLES + SPWMGPIO = "XIO-P7" + RECEIVERGPIO = "CSID0" + COUNT = 200 + SLEEPTIME = 0.01 + + # CLEANUP THE GPIO + GPIO.cleanup() + SPWM.cleanup() + + # SETUP SOFTPWM + SPWM.start(SPWMGPIO, 50, 1) + #SPWM.set_frequency(SPWMGPIO, 2) + + # SETUP SOFTPWM RECEIVER + rcvr = SPWMReceiver(GPIO, RECEIVERGPIO, COUNT, SLEEPTIME) + rcvr.start() + + time.sleep(COUNT*SLEEPTIME + 1) + + # CLEANUP + print("CLEANUP") + SPWM.stop(SPWMGPIO) + SPWM.cleanup() + GPIO.cleanup() + +