jobin-sun / raspberry-gpio-python

Automatically exported from code.google.com/p/raspberry-gpio-python
MIT License
0 stars 0 forks source link

Callback function requires argument passed to it when one is not necessary #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Run the main script shown here 
(http://raspi.tv/tag/threaded-callback-with-rpi-gpio), but change the line "def 
my_callback(channel):" to "def my_callback():"

The function only prints to terminal and should not require any argument passed 
to it.

If no output is passed, an error is generated:

TypeError: my_callback() takes no arguments (1 given)

I am using RPi.GPIO 0.5.2a on the latest Raspbian dist. on my RPi.

Other users report the same problem in the comments here - search for 
"TypeError" 
(http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-
rpi-gpio-part-3)

Original issue reported on code.google.com by Ken.R.We...@gmail.com on 8 May 2013 at 2:06

GoogleCodeExporter commented 9 years ago
Just wanted to add that in place of "(channel)" as described above, any jumble 
of letters works.  "(aklsjv)" would cause the TypeError to not be generated.

Original comment by Ken.R.We...@gmail.com on 8 May 2013 at 2:08

GoogleCodeExporter commented 9 years ago
The library was changed between 0.5.1a and 0.5.2a to pass the channel number 
for a callback.  Note that the 'a' stands for alpha - in other words, the 
library is not mature enough yet to not occasionally undergo changes that might 
break your old code.  I try my best to avoid it though!

For more explanation from the Raspi.tv thread you mentioned, see:
http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-r
pi-gpio-part-3#comment-19971

It is also fully documented here:
http://code.google.com/p/raspberry-gpio-python/wiki/Inputs#Threaded_callbacks

Original comment by btcros...@googlemail.com on 23 Jun 2013 at 10:26