Hello,
I was searching in source code of uPyEasy in branch "master" for a place, when interrupt (irq / external even listener / isr ... however you call it) is configured on GPIO, if such GPIO is configured for switch.
However i didn't find any. I only found aswitch.py with these lines:
loop = asyncio.get_event_loop()
loop.create_task(self.switchcheck()) # Thread runs forever
Did i overlook it, or is there really no interrupt registered and only relying on fact, that one of these reads will detect pressed state (specially if i have push button)? Cannot it then happen, that button press was in between of two checks and hence not detected at all?
How often is event loop running? Isn't its run actually dealyed, if i do network communication?
thank you
best regards
jano
reading of events on gpio pins for switch
Moderators: Voyager, BertB, grovkillen, Stuntteam, LisaM
Re: reading of events on gpio pins for switch
It's interrupt based, but not as you're used to. Using the right libraries there is no need to program any interrupt routine.
Just add this to the init function of the plugin (for a push button):
The available push button functions: press_func, release_func, double_func and long_func.
The function names explain their own function enough.
The togglebutton function (add in the custom plugin section):
And presto, every time you push the pushbutton, the togglebutton function will be called instantly. The button library together with the async library and MicroPython does all the work for you. No need to program your own interrupt function, everything is already in place (the libraries together with Micropython will do all the interrupting for you).
The button check function is running forever in it's own loop and will be called asynchronously every milliseconds or so, any pushbutton action (including push contact) will take a lot longer then that. In fact it's so fast it has a bounce function, when you push the button it might bounce a few times on the contact giving false push events. Therefor it waits for 50 ms for accepting new push contacts after the initial push contact, so that no false push events are generated...
How i know this works? I'm using this exact code in my top-secret project...![Knipoog ;)](./images/smilies/icon_e_wink.gif)
Just add this to the init function of the plugin (for a push button):
Code: Select all
from aswitch import Switch, Pushbutton
from machine import Pin
# init button
pbpin = Pin(0, Pin.IN, Pin.PULL_UP)
pb = Pushbutton(pbpin)
pb.press_func(self.togglebutton)
The function names explain their own function enough.
The togglebutton function (add in the custom plugin section):
Code: Select all
#
#CUSTOM SENSOR CODE...
#
def togglebutton(self):
# plugin specific section
self._log.debug("Plugin: toggle button")
# do something... :-)
The button check function is running forever in it's own loop and will be called asynchronously every milliseconds or so, any pushbutton action (including push contact) will take a lot longer then that. In fact it's so fast it has a bounce function, when you push the button it might bounce a few times on the contact giving false push events. Therefor it waits for 50 ms for accepting new push contacts after the initial push contact, so that no false push events are generated...
How i know this works? I'm using this exact code in my top-secret project...
![Knipoog ;)](./images/smilies/icon_e_wink.gif)
Who is online
Users browsing this forum: No registered users and 33 guests