uasyncio - How detect the end task in another task.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uasyncio - How detect the end task in another task.
The suppress arg has caused confusion before so I guess I need to improve the docs. Here is how the Pushbutton instance behaves if constructed with suppress=True.
On a button press, the press_func always runs. It is the behaviour of release_func which is modified by suppress.
Given that you have long_func and double_func defined, the behaviour of release_func is as follows.
A press too short to trigger long_func starts the double click timer. If a second click occurs within this time, double_func runs and release_func does not. If no second click occurs, release_func runs when the timer expires.
A press long enough to trigger long_func means that release_func does not run (i.e. it's suppressed).
In other words, one only of long_func, double_func and release_func will run.
On a button press, the press_func always runs. It is the behaviour of release_func which is modified by suppress.
Given that you have long_func and double_func defined, the behaviour of release_func is as follows.
A press too short to trigger long_func starts the double click timer. If a second click occurs within this time, double_func runs and release_func does not. If no second click occurs, release_func runs when the timer expires.
A press long enough to trigger long_func means that release_func does not run (i.e. it's suppressed).
In other words, one only of long_func, double_func and release_func will run.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Pushbutton class - suppress constructor arg
I can see where the confusion was arising and have updated the doc - hopefully this is now better explained.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: uasyncio - How detect the end task in another task.
Hey Pete,
Thanks as always! This indeed clarifies the approach. I've removed press_func and now have only release_func, double_func, and long_func defined and everything works as expected.
On to the next step - rotary encoder.
Thanks as always! This indeed clarifies the approach. I've removed press_func and now have only release_func, double_func, and long_func defined and everything works as expected.
On to the next step - rotary encoder.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uasyncio - How detect the end task in another task.
As you might expect I have a take on this. I believe this is the fastest, simplest algorithm. Note there is a much better way on STM which has hardware support.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: uasyncio - How detect the end task in another task.
Thanks, Pete!
I tried opening encoder_portable.py at your link, but got a 404 from GitHub. In the meantime, I've been using
https://github.com/SpotlightKid/micropy ... er/encoder
which seems to work fine and integrates into the class well.
I tried opening encoder_portable.py at your link, but got a 404 from GitHub. In the meantime, I've been using
https://github.com/SpotlightKid/micropy ... er/encoder
which seems to work fine and integrates into the class well.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uasyncio - How detect the end task in another task.
I'm puzzled - the link works here. Try https://github.com/peterhinch and then micropython-samples.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: uasyncio - How detect the end task in another task.
That worked! The only thing I'm wondering is how to get the encoder value? Would I just instantiate an Encoder class, like enc = Encoder(...) and then call enc.position ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uasyncio - How detect the end task in another task.
Yes. If enc is an Encoder instance, enc.position will return the current position. The scale constructor arg enables the position to be mapped onto meaningful units. The position setter allows the position to be set, e.g. by a limit switch.
The code in my samples repo is meant for experimenters: the Encoder class can be stripped down further if you have no need for the scale or reverse features or the position setter.
The algorithm is based on hardware I designed in the 1970's for an NC machine, so has been extensively tested.
The code in my samples repo is meant for experimenters: the Encoder class can be stripped down further if you have no need for the scale or reverse features or the position setter.
The algorithm is based on hardware I designed in the 1970's for an NC machine, so has been extensively tested.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: uasyncio - How detect the end task in another task.
Thanks! I'll give it a shot on the weekend. As I'm thinking through this more, are you aware of any means to generate a menu structure in micropython, where you can scroll up and down through a menu and then click with the switch to enter and maybe double click to get back out?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uasyncio - How detect the end task in another task.
I think you'll have to write that yourself. There is this GUI option but it doesn't currently support menus.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.