mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 12:53:22 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
4da0812acd | |||
dcd8ea6f40 | |||
29377cf24d |
@ -1,3 +1,20 @@
|
||||
0.5.5
|
||||
---
|
||||
* Fix for Issue #62 where using alternate name of an XIO would cause a segfault due to trying to set pull up/down resistor setting
|
||||
|
||||
0.5.4
|
||||
---
|
||||
* Re-enabled the polarity setting for PWM based upon Issue #61
|
||||
* Fixed a 1 letter bug was trying to write inverted to polarity when it wants inversed (such facepalm)
|
||||
* Cleaned up the polarity setting code to work when PWM is not enabled
|
||||
* Fixed the unit test for pwm to verify we can set polarity
|
||||
|
||||
0.5.3
|
||||
---
|
||||
* Fixes to the PWM pytest
|
||||
* Added pytest for LRADC and Utilities
|
||||
* Makefile updates for all the things
|
||||
|
||||
0.5.2
|
||||
---
|
||||
* Updating Utilties to determine CHIP Pro better
|
||||
|
@ -20,7 +20,8 @@
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import Utilities as UT
|
||||
import sys
|
||||
from .Utilities import is_chip_pro
|
||||
|
||||
DEBUG = False
|
||||
|
||||
@ -162,7 +163,7 @@ def load(overlay, path=""):
|
||||
return 1
|
||||
|
||||
# DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO LOAD PWM0
|
||||
if UT.is_chip_pro() and overlay.upper() == "PWM0":
|
||||
if is_chip_pro() and overlay.upper() == "PWM0":
|
||||
print("CHIP Pro supports PWM0 in base DTB, exiting")
|
||||
return 1
|
||||
|
||||
@ -200,7 +201,7 @@ def unload(overlay):
|
||||
print("UNLOAD OVERLAY: {0}".format(overlay))
|
||||
|
||||
# DETERMINE IF WE ARE A CHIP PRO AND WE ARE COMMANDED TO UNLOAD PWM0
|
||||
if UT.is_chip_pro() and overlay.upper() == "PWM0":
|
||||
if is_chip_pro() and overlay.upper() == "PWM0":
|
||||
print("CHIP Pro supports PWM0 in base DTB, exiting")
|
||||
return
|
||||
|
||||
|
40
Makefile
40
Makefile
@ -1,25 +1,61 @@
|
||||
# PyPi Packaging
|
||||
package: clean
|
||||
@echo " ** PACKAGING FOR PYPI **"
|
||||
python setup.py sdist
|
||||
|
||||
# PyPi Publishing
|
||||
publish: package
|
||||
@echo " ** UPLOADING TO PYPI **"
|
||||
twine upload dist/*
|
||||
|
||||
# Clean all the things
|
||||
clean:
|
||||
@echo " ** CLEANING CHIP_IO **"
|
||||
rm -rf CHIP_IO.* build dist
|
||||
rm -f *.pyo *.pyc
|
||||
rm -f *.egg
|
||||
rm -rf __pycache__
|
||||
rm -rf test/__pycache__/
|
||||
rm -rf debian/python-chip-io*
|
||||
rm -rf debian/python3-chip-io*
|
||||
|
||||
tests:
|
||||
py.test
|
||||
# Run all the tests
|
||||
tests: pytest2 pytest3
|
||||
|
||||
# Run the tests with Python 2
|
||||
pytest2:
|
||||
@echo " ** RUNING CHIP_IO TESTS UNDER PYTHON 2 **"
|
||||
pushd test; python -m pytest; popd
|
||||
|
||||
# Run the tests with Python 3
|
||||
pytest3:
|
||||
@echo " ** RUNING CHIP_IO TESTS UNDER PYTHON 3 **"
|
||||
pushd test; python3 -m pytest; popd
|
||||
|
||||
# Build all the things
|
||||
build:
|
||||
@echo " ** BUILDING CHIP_IO: PYTHON 2 **"
|
||||
python setup.py build --force
|
||||
|
||||
# Install all the things
|
||||
install: build
|
||||
@echo " ** INSTALLING CHIP_IO: PYTHON 2 **"
|
||||
python setup.py install --force
|
||||
|
||||
# Build for Python 3
|
||||
build3:
|
||||
@echo " ** BUILDING CHIP_IO: PYTHON 3 **"
|
||||
python3 setup.py build --force
|
||||
|
||||
# Install for Python 3
|
||||
install3: build3
|
||||
@echo " ** INSTALLING CHIP_IO: PYTHON 3 **"
|
||||
python3 setup.py install --force
|
||||
|
||||
# Install for both Python 2 and 3
|
||||
all: install install3
|
||||
|
||||
# Create a deb file
|
||||
debfile:
|
||||
@echo " ** BUILDING DEBIAN PACKAGES **"
|
||||
dpkg-buildpackage -rfakeroot -uc -b
|
||||
|
11
README.rst
11
README.rst
@ -438,11 +438,12 @@ Install py.test to run the tests. You'll also need the python compiler package f
|
||||
To run the tests, do the following.::
|
||||
|
||||
# If only one version of Python is installed
|
||||
sudo py.test
|
||||
# If more than one version of Python
|
||||
cd test
|
||||
sudo python2 -m pytest
|
||||
sudo python3 -m pytest
|
||||
# Python 2
|
||||
sudo make pytest2
|
||||
# Python 3
|
||||
sudo make pytest3
|
||||
# If more than one version of Python, run through both
|
||||
sudo make test
|
||||
|
||||
**Credits**
|
||||
|
||||
|
23
debian/changelog
vendored
23
debian/changelog
vendored
@ -1,3 +1,26 @@
|
||||
chip-io (0.5.5-1) unstable; urgency=low
|
||||
|
||||
* Fix for Issue #62 where using alternate name of an XIO would cause a segfault due to trying to set pull up/down resistor setting
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Mon, 6 Mar 2017 17:02:00 -0600
|
||||
|
||||
chip-io (0.5.4-1) unstable; urgency=low
|
||||
|
||||
* Re-enabled the polarity setting for PWM based upon Issue #61
|
||||
* Fixed a 1 letter bug was trying to write inverted to polarity when it wants inversed (such facepalm)
|
||||
* Cleaned up the polarity setting code to work when PWM is not enabled
|
||||
* Fixed the unit test for pwm to verify we can set polarity
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Sat, 4 Mar 2017 20:46:00 -0600
|
||||
|
||||
chip-io (0.5.3-1) unstable; urgency=low
|
||||
|
||||
* Fixes to the PWM pytest
|
||||
* Added pytest for LRADC and Utilities
|
||||
* Makefile updates for all the things
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Sun, 26 Feb 2017 20:46:00 -0600
|
||||
|
||||
chip-io (0.5.2-1) unstable; urgency=low
|
||||
|
||||
* Updating Utilities to determine CHIP Pro better
|
||||
|
4
debian/files
vendored
4
debian/files
vendored
@ -1,2 +1,2 @@
|
||||
python-chip-io_0.4.0-1_armhf.deb python optional
|
||||
python3-chip-io_0.4.0-1_armhf.deb python optional
|
||||
python-chip-io_0.5.4-1_armhf.deb python optional
|
||||
python3-chip-io_0.5.4-1_armhf.deb python optional
|
||||
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha',
|
||||
'Topic :: System :: Hardware']
|
||||
|
||||
setup(name = 'CHIP_IO',
|
||||
version = '0.5.2',
|
||||
version = '0.5.5',
|
||||
author = 'Robert Wolterman',
|
||||
author_email = 'robert.wolterman@gmail.com',
|
||||
description = 'A module to control CHIP IO channels',
|
||||
|
@ -246,13 +246,14 @@ int pwm_set_polarity(const char *key, int polarity) {
|
||||
return rtnval;
|
||||
}
|
||||
|
||||
if (pwm->enable) {
|
||||
// THIS ONLY WORKS WHEN PWM IS NOT ENABLED
|
||||
if (pwm->enable == 0) {
|
||||
if (polarity == 0) {
|
||||
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = snprintf(buffer, sizeof(buffer), "%s", "inverted"); BUF2SMALL(buffer);
|
||||
len = snprintf(buffer, sizeof(buffer), "%s", "inversed"); BUF2SMALL(buffer);
|
||||
}
|
||||
ssize_t s = write(pwm->polarity_fd, buffer, len); e_no = errno;
|
||||
if (DEBUG) {
|
||||
@ -271,6 +272,7 @@ int pwm_set_polarity(const char *key, int polarity) {
|
||||
} else {
|
||||
rtnval = 0;
|
||||
}
|
||||
|
||||
return rtnval;
|
||||
}
|
||||
|
||||
@ -527,12 +529,12 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
|
||||
}
|
||||
|
||||
int rtnval = 0;
|
||||
// Always set polarity first
|
||||
if (iscpro == 1) {
|
||||
rtnval = pwm_set_polarity(key, polarity);
|
||||
}
|
||||
rtnval = pwm_set_enable(key, ENABLE);
|
||||
// Fix for issue #53
|
||||
// Always set polarity first
|
||||
rtnval = pwm_set_polarity(key, polarity);
|
||||
if (rtnval != -1) {
|
||||
rtnval = 0;
|
||||
rtnval = pwm_set_enable(key, ENABLE);
|
||||
if (rtnval != -1) {
|
||||
rtnval = 0;
|
||||
rtnval = pwm_set_frequency(key, freq);
|
||||
@ -541,6 +543,7 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
|
||||
rtnval = pwm_set_duty_cycle(key, duty);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rtnval;
|
||||
}
|
||||
|
||||
@ -563,9 +566,7 @@ int pwm_disable(const char *key)
|
||||
pwm_set_frequency(key, 0);
|
||||
pwm_set_duty_cycle(key, 0);
|
||||
pwm_set_enable(key, DISABLE);
|
||||
if (pwm->iscpro == 1) {
|
||||
pwm_set_polarity(key, 0);
|
||||
}
|
||||
|
||||
if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0)
|
||||
{
|
||||
|
@ -263,7 +263,7 @@ int gpio_allowed(int gpio)
|
||||
// We have a CHIP and the pin is for CHIP/BOTH
|
||||
if (((p->sbc_type == CHIP) || (p->sbc_type == BOTH)) && (is_this_chippro() == 0)) {
|
||||
if (DEBUG)
|
||||
printf(" ** gpio_allowed: pin allowed for chip or bth and we're a chip\n");
|
||||
printf(" ** gpio_allowed: pin allowed for chip or both and we're a chip\n");
|
||||
rtnval = 1;
|
||||
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
||||
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
|
||||
@ -296,7 +296,7 @@ int pwm_allowed(const char *key)
|
||||
// We have a CHIP and the pin is for CHIP/BOTH
|
||||
if ((p->sbc_type == BOTH) && (is_this_chippro() == 0)) {
|
||||
if (DEBUG)
|
||||
printf(" ** pwm_allowed: pwm allowed for chip or bth and we're a chip\n");
|
||||
printf(" ** pwm_allowed: pwm allowed for chip or both and we're a chip\n");
|
||||
rtnval = 1;
|
||||
// We have a CHIP Pro and the pin is for CHIPPRO/BOTH
|
||||
} else if (((p->sbc_type == CHIPPRO) || (p->sbc_type == BOTH)) && (is_this_chippro() == 1)) {
|
||||
@ -554,7 +554,7 @@ int compute_port_pin(const char *key, int gpio, int *port, int *pin)
|
||||
if (capable < 0) {
|
||||
capable = lookup_pud_capable_by_name(key);
|
||||
if (capable < 0) {
|
||||
capable = lookup_gpio_by_altname(key);
|
||||
capable = lookup_pud_capable_by_altname(key);
|
||||
if (capable < 0) {
|
||||
capable = 0; // default to false
|
||||
}
|
||||
|
@ -85,6 +85,6 @@ void define_constants(PyObject *module)
|
||||
bcm = Py_BuildValue("i", BCM);
|
||||
PyModule_AddObject(module, "BCM", bcm);
|
||||
|
||||
version = Py_BuildValue("s", "0.5.2");
|
||||
version = Py_BuildValue("s", "0.5.5");
|
||||
PyModule_AddObject(module, "VERSION", version);
|
||||
}
|
||||
|
45
test/integrations/spwmtest2.py
Normal file
45
test/integrations/spwmtest2.py
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import CHIP_IO.SOFTPWM as PWM
|
||||
import CHIP_IO.GPIO as GPIO
|
||||
import CHIP_IO.OverlayManager as OM
|
||||
import time
|
||||
import datetime
|
||||
|
||||
if __name__ == "__main__":
|
||||
# SETUP VARIABLES
|
||||
PWMGPIO = "XIO-P7"
|
||||
#PWMGPIO = "LCD-D4"
|
||||
COUNT = 150
|
||||
SLEEPTIME = 0.01
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
# SETUP PWM
|
||||
try:
|
||||
print("PWM START")
|
||||
#PWM.toggle_debug()
|
||||
PWM.start(PWMGPIO, 50, 45, 1)
|
||||
|
||||
# UNCOMMENT FOR CRASH
|
||||
print("PWM SET FREQUENCY")
|
||||
PWM.set_frequency(PWMGPIO, 10)
|
||||
|
||||
# UNCOMMENT FOR CRASH
|
||||
print("PWM SET DUTY CYCLE")
|
||||
PWM.set_duty_cycle(PWMGPIO, 25)
|
||||
|
||||
#time.sleep(COUNT*SLEEPTIME + 1)
|
||||
raw_input("PRESS ENTER WHEN DONE")
|
||||
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
# CLEANUP
|
||||
print("CLEANUP")
|
||||
PWM.stop(PWMGPIO)
|
||||
PWM.cleanup()
|
||||
#OM.unload("PWM0")
|
||||
#GPIO.cleanup()
|
||||
|
||||
|
14
test/test_lradc.py
Normal file
14
test/test_lradc.py
Normal file
@ -0,0 +1,14 @@
|
||||
import pytest
|
||||
|
||||
import CHIP_IO.LRADC as LRADC
|
||||
|
||||
class TestLRADC:
|
||||
def test_scale_factor(self):
|
||||
assert LRADC.get_scale_factor() == 31.25
|
||||
|
||||
def test_sample_rate_values(self):
|
||||
assert LRADC.get_allowable_sample_rates() == (32.25, 62.5, 125, 250)
|
||||
|
||||
def test_set_sample_rate(self):
|
||||
LRADC.set_sample_rate(32.25)
|
||||
assert LRADC.get_sample_rate() == 32.25
|
@ -4,12 +4,15 @@ import time
|
||||
|
||||
import CHIP_IO.PWM as PWM
|
||||
import CHIP_IO.OverlayManager as OM
|
||||
import CHIP_IO.Utilities as UT
|
||||
|
||||
def setup_module(module):
|
||||
if not UT.is_chip_pro():
|
||||
OM.load("PWM0")
|
||||
|
||||
def teardown_module(module):
|
||||
PWM.cleanup()
|
||||
if not UT.is_chip_pro():
|
||||
OM.unload("PWM0")
|
||||
|
||||
class TestPwmSetup:
|
||||
@ -17,16 +20,6 @@ class TestPwmSetup:
|
||||
def setup_method(self, test_method):
|
||||
time.sleep(0.5)
|
||||
|
||||
#def teardown_method(self, test_method):
|
||||
# PWM.cleanup()
|
||||
#OM.unload("PWM0")
|
||||
|
||||
#def setup_module(self, module):
|
||||
# OM.load("PWM0")
|
||||
|
||||
#def teardown_module(self, module):
|
||||
# OM.unload("PWM0")
|
||||
|
||||
def test_start_pwm(self):
|
||||
PWM.start("PWM0", 0)
|
||||
|
||||
@ -38,27 +31,25 @@ class TestPwmSetup:
|
||||
assert int(duty) == 0
|
||||
assert int(period) == 500000
|
||||
|
||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
||||
def test_start_pwm_with_polarity_one(self):
|
||||
PWM.cleanup()
|
||||
PWM.start("PWM0", 0, 2000, 1)
|
||||
|
||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||
|
||||
#assert os.path.exists(pwm_test) == True
|
||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||
period = open(pwm_test + 'period').readline().strip()
|
||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||
assert int(duty) == 0
|
||||
assert int(period) == 500000
|
||||
assert str(polarity) == "inverted"
|
||||
assert str(polarity) == "inversed"
|
||||
|
||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
||||
def test_start_pwm_with_polarity_default(self):
|
||||
PWM.cleanup()
|
||||
PWM.start("PWM0", 0, 2000, 0)
|
||||
|
||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||
|
||||
#assert os.path.exists(pwm_test) == True
|
||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||
period = open(pwm_test + 'period').readline().strip()
|
||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||
@ -66,13 +57,12 @@ class TestPwmSetup:
|
||||
assert int(period) == 500000
|
||||
assert str(polarity) == "normal"
|
||||
|
||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
||||
def test_start_pwm_with_polarity_zero(self):
|
||||
PWM.cleanup()
|
||||
PWM.start("PWM0", 0, 2000, 0)
|
||||
|
||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||
|
||||
#assert os.path.exists(pwm_test) == True
|
||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||
period = open(pwm_test + 'period').readline().strip()
|
||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||
@ -90,11 +80,14 @@ class TestPwmSetup:
|
||||
|
||||
def test_pwm_start_valid_duty_cycle_min(self):
|
||||
#testing an exception isn't thrown
|
||||
PWM.cleanup()
|
||||
PWM.start("PWM0", 0)
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_start_valid_duty_cycle_max(self):
|
||||
#testing an exception isn't thrown
|
||||
PWM.start("PWM0", 100)
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_start_invalid_duty_cycle_high(self):
|
||||
with pytest.raises(ValueError):
|
||||
@ -143,7 +136,8 @@ class TestPwmSetup:
|
||||
assert int(period) == 500000
|
||||
|
||||
def test_pwm_duty_cycle_non_setup_key(self):
|
||||
with pytest.raises(RuntimeError):
|
||||
with pytest.raises(ValueError):
|
||||
PWM.cleanup()
|
||||
PWM.set_duty_cycle("PWM0", 100)
|
||||
|
||||
def test_pwm_duty_cycle_invalid_key(self):
|
||||
@ -154,26 +148,31 @@ class TestPwmSetup:
|
||||
PWM.start("PWM0", 0)
|
||||
with pytest.raises(ValueError):
|
||||
PWM.set_duty_cycle("PWM0", 101)
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_duty_cycle_invalid_value_negative(self):
|
||||
PWM.start("PWM0", 0)
|
||||
with pytest.raises(ValueError):
|
||||
PWM.set_duty_cycle("PWM0", -1)
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_duty_cycle_invalid_value_string(self):
|
||||
PWM.start("PWM0", 0)
|
||||
with pytest.raises(TypeError):
|
||||
PWM.set_duty_cycle("PWM0", "a")
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_frequency_invalid_value_negative(self):
|
||||
PWM.start("PWM0", 0)
|
||||
with pytest.raises(ValueError):
|
||||
PWM.set_frequency("PWM0", -1)
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_frequency_invalid_value_string(self):
|
||||
PWM.start("PWM0", 0)
|
||||
with pytest.raises(TypeError):
|
||||
PWM.set_frequency("PWM0", "11")
|
||||
PWM.cleanup()
|
||||
|
||||
def test_pwm_freq_non_setup_key(self):
|
||||
with pytest.raises(RuntimeError):
|
||||
|
11
test/test_utilities.py
Normal file
11
test/test_utilities.py
Normal file
@ -0,0 +1,11 @@
|
||||
import pytest
|
||||
|
||||
import CHIP_IO.Utilities as UT
|
||||
|
||||
class TestUtilities:
|
||||
def test_invalid_set_1v8_with_string(self):
|
||||
assert not UT.set_1v8_pin_voltage("yaystring")
|
||||
|
||||
def test_invalid_set_1v8_with_outofbounds_value(self):
|
||||
assert not UT.set_1v8_pin_voltage(0.5)
|
||||
assert not UT.set_1v8_pin_voltage(4.5)
|
Reference in New Issue
Block a user