mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
Re-enabled polarity set on the CHIP PWM, fixed issues that caused me to disable that feature to begin with. This could have been a 1 letter change, but I re-eabled tests in the unit test to validate. This will close #61
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
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
|
0.5.3
|
||||||
---
|
---
|
||||||
* Fixes to the PWM pytest
|
* Fixes to the PWM pytest
|
||||||
|
9
debian/changelog
vendored
9
debian/changelog
vendored
@ -1,3 +1,12 @@
|
|||||||
|
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> Sun, 26 Feb 2017 20:46:00 -0600
|
||||||
|
|
||||||
chip-io (0.5.3-1) unstable; urgency=low
|
chip-io (0.5.3-1) unstable; urgency=low
|
||||||
|
|
||||||
* Fixes to the PWM pytest
|
* Fixes to the PWM pytest
|
||||||
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha',
|
|||||||
'Topic :: System :: Hardware']
|
'Topic :: System :: Hardware']
|
||||||
|
|
||||||
setup(name = 'CHIP_IO',
|
setup(name = 'CHIP_IO',
|
||||||
version = '0.5.3',
|
version = '0.5.4',
|
||||||
author = 'Robert Wolterman',
|
author = 'Robert Wolterman',
|
||||||
author_email = 'robert.wolterman@gmail.com',
|
author_email = 'robert.wolterman@gmail.com',
|
||||||
description = 'A module to control CHIP IO channels',
|
description = 'A module to control CHIP IO channels',
|
||||||
|
@ -246,13 +246,14 @@ int pwm_set_polarity(const char *key, int polarity) {
|
|||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pwm->enable) {
|
// THIS ONLY WORKS WHEN PWM IS NOT ENABLED
|
||||||
|
if (pwm->enable == 0) {
|
||||||
if (polarity == 0) {
|
if (polarity == 0) {
|
||||||
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
|
len = snprintf(buffer, sizeof(buffer), "%s", "normal"); BUF2SMALL(buffer);
|
||||||
}
|
}
|
||||||
else
|
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;
|
ssize_t s = write(pwm->polarity_fd, buffer, len); e_no = errno;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -271,6 +272,7 @@ int pwm_set_polarity(const char *key, int polarity) {
|
|||||||
} else {
|
} else {
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,12 +529,12 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int rtnval = 0;
|
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
|
// 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) {
|
if (rtnval != -1) {
|
||||||
rtnval = 0;
|
rtnval = 0;
|
||||||
rtnval = pwm_set_frequency(key, freq);
|
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);
|
rtnval = pwm_set_duty_cycle(key, duty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return rtnval;
|
return rtnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,9 +566,7 @@ int pwm_disable(const char *key)
|
|||||||
pwm_set_frequency(key, 0);
|
pwm_set_frequency(key, 0);
|
||||||
pwm_set_duty_cycle(key, 0);
|
pwm_set_duty_cycle(key, 0);
|
||||||
pwm_set_enable(key, DISABLE);
|
pwm_set_enable(key, DISABLE);
|
||||||
if (pwm->iscpro == 1) {
|
|
||||||
pwm_set_polarity(key, 0);
|
pwm_set_polarity(key, 0);
|
||||||
}
|
|
||||||
|
|
||||||
if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0)
|
if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0)
|
||||||
{
|
{
|
||||||
|
@ -85,6 +85,6 @@ void define_constants(PyObject *module)
|
|||||||
bcm = Py_BuildValue("i", BCM);
|
bcm = Py_BuildValue("i", BCM);
|
||||||
PyModule_AddObject(module, "BCM", bcm);
|
PyModule_AddObject(module, "BCM", bcm);
|
||||||
|
|
||||||
version = Py_BuildValue("s", "0.5.3");
|
version = Py_BuildValue("s", "0.5.4");
|
||||||
PyModule_AddObject(module, "VERSION", version);
|
PyModule_AddObject(module, "VERSION", version);
|
||||||
}
|
}
|
||||||
|
@ -31,27 +31,25 @@ class TestPwmSetup:
|
|||||||
assert int(duty) == 0
|
assert int(duty) == 0
|
||||||
assert int(period) == 500000
|
assert int(period) == 500000
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
|
||||||
def test_start_pwm_with_polarity_one(self):
|
def test_start_pwm_with_polarity_one(self):
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0, 2000, 1)
|
PWM.start("PWM0", 0, 2000, 1)
|
||||||
|
|
||||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||||
|
|
||||||
#assert os.path.exists(pwm_test) == True
|
|
||||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||||
period = open(pwm_test + 'period').readline().strip()
|
period = open(pwm_test + 'period').readline().strip()
|
||||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||||
assert int(duty) == 0
|
assert int(duty) == 0
|
||||||
assert int(period) == 500000
|
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):
|
def test_start_pwm_with_polarity_default(self):
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0, 2000, 0)
|
PWM.start("PWM0", 0, 2000, 0)
|
||||||
|
|
||||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||||
|
|
||||||
#assert os.path.exists(pwm_test) == True
|
|
||||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||||
period = open(pwm_test + 'period').readline().strip()
|
period = open(pwm_test + 'period').readline().strip()
|
||||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||||
@ -59,13 +57,12 @@ class TestPwmSetup:
|
|||||||
assert int(period) == 500000
|
assert int(period) == 500000
|
||||||
assert str(polarity) == "normal"
|
assert str(polarity) == "normal"
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="pwm cleanup is doing weirdness for this test")
|
|
||||||
def test_start_pwm_with_polarity_zero(self):
|
def test_start_pwm_with_polarity_zero(self):
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0, 2000, 0)
|
PWM.start("PWM0", 0, 2000, 0)
|
||||||
|
|
||||||
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'
|
||||||
|
|
||||||
#assert os.path.exists(pwm_test) == True
|
|
||||||
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
duty = open(pwm_test + 'duty_cycle').readline().strip()
|
||||||
period = open(pwm_test + 'period').readline().strip()
|
period = open(pwm_test + 'period').readline().strip()
|
||||||
polarity = open(pwm_test + 'polarity').readline().strip()
|
polarity = open(pwm_test + 'polarity').readline().strip()
|
||||||
@ -83,6 +80,7 @@ class TestPwmSetup:
|
|||||||
|
|
||||||
def test_pwm_start_valid_duty_cycle_min(self):
|
def test_pwm_start_valid_duty_cycle_min(self):
|
||||||
#testing an exception isn't thrown
|
#testing an exception isn't thrown
|
||||||
|
PWM.cleanup()
|
||||||
PWM.start("PWM0", 0)
|
PWM.start("PWM0", 0)
|
||||||
PWM.cleanup()
|
PWM.cleanup()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user