uasyncio - How detect the end task in another task.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - How detect the end task in another task.

Post by pythoncoder » Sat Aug 22, 2020 4:56 pm

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.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Pushbutton class - suppress constructor arg

Post by pythoncoder » Sat Aug 22, 2020 6:06 pm

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.

Primesty
Posts: 49
Joined: Sun Jun 28, 2020 11:06 pm

Re: uasyncio - How detect the end task in another task.

Post by Primesty » Sat Aug 22, 2020 6:38 pm

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - How detect the end task in another task.

Post by pythoncoder » Sun Aug 23, 2020 1:46 pm

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.

Primesty
Posts: 49
Joined: Sun Jun 28, 2020 11:06 pm

Re: uasyncio - How detect the end task in another task.

Post by Primesty » Tue Aug 25, 2020 6:16 pm

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - How detect the end task in another task.

Post by pythoncoder » Wed Aug 26, 2020 5:45 am

I'm puzzled - the link works here. Try https://github.com/peterhinch and then micropython-samples.
Peter Hinch
Index to my micropython libraries.

Primesty
Posts: 49
Joined: Sun Jun 28, 2020 11:06 pm

Re: uasyncio - How detect the end task in another task.

Post by Primesty » Wed Aug 26, 2020 9:37 pm

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 ?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - How detect the end task in another task.

Post by pythoncoder » Thu Aug 27, 2020 5:59 am

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.
Peter Hinch
Index to my micropython libraries.

Primesty
Posts: 49
Joined: Sun Jun 28, 2020 11:06 pm

Re: uasyncio - How detect the end task in another task.

Post by Primesty » Fri Aug 28, 2020 10:04 pm

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?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - How detect the end task in another task.

Post by pythoncoder » Mon Aug 31, 2020 6:57 am

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.

Post Reply