diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4f94287..16deb25 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 --- * Fixes to the PWM pytest diff --git a/debian/changelog b/debian/changelog index 0a3a1ae..674e447 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Sun, 26 Feb 2017 20:46:00 -0600 + chip-io (0.5.3-1) unstable; urgency=low * Fixes to the PWM pytest diff --git a/setup.py b/setup.py index 8d1d798..e987c0c 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.5.3', + version = '0.5.4', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', diff --git a/source/c_pwm.c b/source/c_pwm.c index f496ffa..298bc66 100644 --- a/source/c_pwm.c +++ b/source/c_pwm.c @@ -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,18 +529,19 @@ 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_frequency(key, freq); + rtnval = pwm_set_enable(key, ENABLE); if (rtnval != -1) { rtnval = 0; - rtnval = pwm_set_duty_cycle(key, duty); + rtnval = pwm_set_frequency(key, freq); + if (rtnval != -1) { + rtnval = 0; + 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); - } + pwm_set_polarity(key, 0); if ((fd = open("/sys/class/pwm/pwmchip0/unexport", O_WRONLY)) < 0) { diff --git a/source/constants.c b/source/constants.c index 15ad57d..9145346 100644 --- a/source/constants.c +++ b/source/constants.c @@ -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.3"); + version = Py_BuildValue("s", "0.5.4"); PyModule_AddObject(module, "VERSION", version); } diff --git a/test/test_pwm_setup.py b/test/test_pwm_setup.py index bdc9810..4fd611a 100644 --- a/test/test_pwm_setup.py +++ b/test/test_pwm_setup.py @@ -31,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() @@ -59,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() @@ -83,6 +80,7 @@ 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()