add_event_detect edge as argument to callback function
A Python module to control the GPIO on a Raspberry Pi
Brought to you by:
croston
Originally created by: timpur...@gmail.com
Originally owned by: btcros...@googlemail.com
When using add_event_detect function to detect pin state changes, it would be nice if edge comes as argument to callback function like this:
def my_cb_function(gpio, edge):
if edge == GPIO.FALLING:
print "Falling edge"
GPIO.add_event_detect(pin_number, GPIO.BOTH, callback=my_cb_function)
Now I have to check pin state in my callback function.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: btcros...@googlemail.com
(No comment was entered for this change.)
Labels: -Type-Defect Type-Enhancement
Owner: btcros...@googlemail.com
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: patr...@eldwick.org.uk
Maybe the argument passing could be even more general. For instance if you want the callback function to do something useful (rather than just print something) then it would be nice to be able to pass a pointer to some object to be updated (otherwise only way seems to be to have globals). You could do worse than the threading.Tread system i.e.
GPIO.add_event_detect(pin, GPIO.BOTH, my_func, args=(a, b ,c))
Last edit: Anonymous 2017-11-11
Diff: