From 6f0ddabfb2ef41c75e746a0f396f2a175f99b781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Sun, 7 Mar 2021 19:30:44 +0100 Subject: [PATCH 1/2] Fix input poll compatibility Original RPi.GPIO calls callback with channel number as parameter. Correctl callbacks list usage and pass channel number to callback. Fixes pibrella example. --- RPi/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RPi/core.py b/RPi/core.py index 83ef760..5ea8975 100644 --- a/RPi/core.py +++ b/RPi/core.py @@ -657,8 +657,8 @@ def line_do_poll(channel, bouncetime, timeout): break if line_event_wait(channel, bouncetime, timeout): callbacks = _State.lines[channel].callbacks - for fn in callbacks(): - fn() + for fn in callbacks: + fn(channel) end_critical_section(channel, msg="do poll") time.sleep(TEN_MILLISECONDS_IN_SECONDS) From 025bf2d58244ba8ce109520b1fc6e27bb924305c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Sun, 7 Mar 2021 21:57:55 +0100 Subject: [PATCH 2/2] Allow PWM.start() repeated calls Original C version allows repeated PWM.start() calls, because it just ignores start() call once helper thread is running. Emulate such behaviour and avoid printing warnings if already started. Fixes issue #53. --- RPi/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/RPi/core.py b/RPi/core.py index 5ea8975..a5377d1 100644 --- a/RPi/core.py +++ b/RPi/core.py @@ -1166,6 +1166,7 @@ def __init__(self, channel, frequency): if frequency <= 0.0: raise ValueError("frequency must be greater than 0.0") self.channel = channel + self.started = False line_pwm_set_frequency(channel, frequency) def start(self, dutycycle): @@ -1176,13 +1177,16 @@ def start(self, dutycycle): if dutycycle < 0.0 or dutycycle > 100.0: raise ValueError("dutycycle must have a value from 0.0 to 100.0") - return line_pwm_start(self.channel, dutycycle) + if not self.started: + return line_pwm_start(self.channel, dutycycle) + return False def stop(self): """ Stop software PWM """ line_pwm_stop(self.channel) + self.started = False def ChangeDutyCycle(self, dutycycle): """ @@ -1199,7 +1203,6 @@ def ChangeFrequency(self, frequency): Change the frequency frequency - frequency in Hz (freq > 1.0) """ - if frequency <= 0.0: raise ValueError("frequency must be greater than 0.0")