diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2ff7c94..749e32e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,11 @@ - Support for a custom DTB Overlay * Fixes to the pwm unit test, all but 2 now pass :) +0.1.2 +---- +* SoftPWM Fix by aninternetof +* Added a verification test for SoftPWM + 0.1.1 ---- * Some refactoring of the edge detection code, made it function better diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..50b245a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include distribute_setup.py +include README.rst +include CHANGELOG.rst +recursive-include source *.h +recursive-include overlays *.dts *.py diff --git a/source/c_softpwm.c b/source/c_softpwm.c index c794770..08fb10e 100644 --- a/source/c_softpwm.c +++ b/source/c_softpwm.c @@ -101,7 +101,7 @@ int softpwm_set_frequency(const char *key, float freq) { pwm->params.freq = freq; pthread_mutex_unlock(pwm->params_lock); - return 1; + return 0; } int softpwm_set_polarity(const char *key, int polarity) { @@ -274,11 +274,13 @@ int softpwm_start(const char *key, float duty, float freq, int polarity) pwm = pwm->next; pwm->next = new_pwm; } + pthread_mutex_unlock(new_params_lock); ASSRT(softpwm_set_duty_cycle(new_pwm->key, duty) == 0); ASSRT(softpwm_set_frequency(new_pwm->key, freq) == 0); ASSRT(softpwm_set_polarity(new_pwm->key, polarity) == 0); + pthread_mutex_lock(new_params_lock); // create thread for pwm ret = pthread_create(&new_thread, NULL, softpwm_thread_toggle, (void *)new_pwm); ASSRT(ret == 0); diff --git a/test/spwmtest.py b/test/spwmtest.py new file mode 100755 index 0000000..3c2af43 --- /dev/null +++ b/test/spwmtest.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +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() + +