1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 12:53:22 +00:00

Merging in the latest master for Issue #10, PR #12

This commit is contained in:
Robert Wolterman
2016-07-25 19:47:05 -05:00
4 changed files with 72 additions and 1 deletions

View File

@ -12,6 +12,11 @@
- Support for a custom DTB Overlay - Support for a custom DTB Overlay
* Fixes to the pwm unit test, all but 2 now pass :) * 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 0.1.1
---- ----
* Some refactoring of the edge detection code, made it function better * Some refactoring of the edge detection code, made it function better

5
MANIFEST.in Normal file
View File

@ -0,0 +1,5 @@
include distribute_setup.py
include README.rst
include CHANGELOG.rst
recursive-include source *.h
recursive-include overlays *.dts *.py

View File

@ -101,7 +101,7 @@ int softpwm_set_frequency(const char *key, float freq) {
pwm->params.freq = freq; pwm->params.freq = freq;
pthread_mutex_unlock(pwm->params_lock); pthread_mutex_unlock(pwm->params_lock);
return 1; return 0;
} }
int softpwm_set_polarity(const char *key, int polarity) { 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 = pwm->next;
pwm->next = new_pwm; pwm->next = new_pwm;
} }
pthread_mutex_unlock(new_params_lock);
ASSRT(softpwm_set_duty_cycle(new_pwm->key, duty) == 0); ASSRT(softpwm_set_duty_cycle(new_pwm->key, duty) == 0);
ASSRT(softpwm_set_frequency(new_pwm->key, freq) == 0); ASSRT(softpwm_set_frequency(new_pwm->key, freq) == 0);
ASSRT(softpwm_set_polarity(new_pwm->key, polarity) == 0); ASSRT(softpwm_set_polarity(new_pwm->key, polarity) == 0);
pthread_mutex_lock(new_params_lock);
// create thread for pwm // create thread for pwm
ret = pthread_create(&new_thread, NULL, softpwm_thread_toggle, (void *)new_pwm); ret = pthread_create(&new_thread, NULL, softpwm_thread_toggle, (void *)new_pwm);
ASSRT(ret == 0); ASSRT(ret == 0);

59
test/spwmtest.py Executable file
View File

@ -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()