Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching generic button events possible? #29

Closed
arkhipenko opened this issue Mar 31, 2020 · 3 comments
Closed

Catching generic button events possible? #29

arkhipenko opened this issue Mar 31, 2020 · 3 comments

Comments

@arkhipenko
Copy link

arkhipenko commented Mar 31, 2020

Hi,
I am writing a python script that deals with a changing number of buttons on the Blynk app side.
Currently every button event is caught individually:

@blynk.handle_event('write V1')
def write_virtual_pin_handler1(pin, value):
...

@blynk.handle_event('write V3')
def write_virtual_pin_handler3(pin, value):
...

Is there a way to catch all or a subset of buttons via same method? Since pin is available I can make determination which event happened?
Like this for instance?

@blynk.handle_event('write V*')
def write_virtual_pin_handler_all(pin, value):
...
@arkhipenko
Copy link
Author

Right now I am "solving" this like illustrated below, but it is not elegant.

@blynk.handle_event('write V1')
def write_virtual_pin_handler1(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V2')
def write_virtual_pin_handler2(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V3')
def write_virtual_pin_handler3(pin, value):
    virtual_pin_handler_all(pin, value)
    
@blynk.handle_event('write V4')
def write_virtual_pin_handler4(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V5')
def write_virtual_pin_handler5(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V6')
def write_virtual_pin_handler6(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V7')
def write_virtual_pin_handler7(pin, value):
    virtual_pin_handler_all(pin, value)

@blynk.handle_event('write V8')
def write_virtual_pin_handler9(pin, value):
    virtual_pin_handler_all(pin, value)


    
def virtual_pin_handler_all(pin, value):
    global logger
    ...

@antohaUa
Copy link
Collaborator

antohaUa commented Mar 31, 2020

Hi Anatoli!
We have global capture for multiple pins
Please see example: https://github.com/blynkkk/lib-python/blob/master/examples/07_tweet_and_logging.py

@blynk.handle_event('write V*')
will capture write events from virtual pins 0-32, but if needed you can change hardcoded MAX allowed value inside lib VPIN_MAX_NUM

Hope this is what you are looking for. If no - just ping me additionally )).

@arkhipenko
Copy link
Author

arkhipenko commented Mar 31, 2020

You guys are go-o-o-d! It works like a charm. Thank you. 32 is a decent number of buttons for what I need to do. Thanks for the VPIN_MAX_NUM tip.
I can't believe I didn't just test the "write V*" option prior to creating this issue! Could have discovered this by myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants