vshymanskyy / blynk-library-python

Blynk library for Python. Works with Python 2, Python 3, MicroPython.
https://blynk.io/
MIT License
281 stars 97 forks source link

Provide virtual pin number to callback function #22

Closed chrissv closed 5 years ago

chrissv commented 5 years ago

Currently the callbacks for each pin must be declared individually and uniquely:

@blynk.VIRTUAL_READ(2)
def v2_read_handler():
    print "This is V2 handler"
@blynk.VIRTUAL_READ(3)
def v3_read_handler():
    print "This is V3 handler"

But there are cases where I want to call a common function, passing in the pin. Something like this (not real code, but the concept):

@blynk.VIRTUAL_READ(2)
def v2_read_handler():
    common_handler(pin)
@blynk.VIRTUAL_READ(3)
def v3_read_handler():
    common_handler(pin)

def common_handler(pin):
    print "This is V{} handler" % pin

This issue is to provide some mechanism to make the pin number available to the callback function.

vshymanskyy commented 5 years ago

Implemented. Please check the latest master, examples directory. Waiting for the feedback!

vshymanskyy commented 5 years ago

v0.2.0 is released and available via pip: https://github.com/vshymanskyy/blynk-library-python/releases/latest