Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » is it possible to use also use the encoder in a task being executed?

Author: markjhatch
08/06/2020 00:40:55
Thank you for making this library available.

I use the tcMenu to initiated a function that takes character coming into thru a digital pin and displays them on the screen. I create a buffer of "x" characters and had planned on using the rotary encoder to move up and down in this buffer displaying the different characters in the buffer.

Several questions. Please feel free to tell me where I should be rtfm-ing

1. Is this possible using just one encoder? While in the function, I want to process the encoder. When I exit this callback function, I want the menu to re-engage and take over the encoder input.

2. The plan would be to use the encoder switch to exit from this subtask to get back to the menu system. Is that button event something I can capture in the processing function?

3. Aside from exiting the callback function, should I be executing any tcMenu function prior to exit?

4. Can I use the same "lcd" variable for displaying the results as used by the menu system?

Thanks you for any hints pointers to investigate.

Author: markjhatch
08/06/2020 01:37:42
Believe I found the answer to #4 with the renderer.takeOverDisplay(myDisplayCallback);

Still searching for the others. smilie

Mark

Author: davetcc
08/06/2020 07:03:52
Hi Mark,

I assume by this we are talking about taking over the display so that you can leave the menu and render your own data.

In that case I'll discuss this in terms of the rendering function callback:

1. Is this possible using just one encoder? While in the function, I want to process the encoder. When I exit this callback function, I want the menu to re-engage and take over the encoder input.


During the take over display rendering function you are passed an integer as the first parameter and a boolean as the second, this is the current value of the rotary encoder and if it is pressed, during the setup of taking over the display, you can change the precision of the encoder to represent a different range.

2. The plan would be to use the encoder switch to exit from this subtask to get back to the menu system. Is that button event something I can capture in the processing function?


As per above the button press is captured by the second boolean parameter in the take over display call back.

3. Aside from exiting the callback function, should I be executing any tcMenu function prior to exit?


The take over display callback is actually a task from taskManager, it's repeatedly called so you should be rendering once then letting the function exit. When you're ready to give back the display to the menu, call renderer.giveBackDisplay()

4. Can I use the same "lcd" variable for displaying the results as used by the menu system?


Yes, but only in the render callback, never use it in any other task or when the display has not been taken over.

See the takeOverDisplay example that ships with TcMenu, that does most of what you're looking to do here.

Thanks,
Dave






Author: markjhatch
08/06/2020 13:35:45
Dave,

Thanks for the very quick reply!

Two clarification and I will go dig some more.

So the task that is executed is long running (it is actually processing and displaying morse code that has been translated to characters by my rig and the rotary allows backward forward movement in the time dimension). So I need to be diligent in reading the serial line and of course displaying the received code.

1. It looks like I could schedule a task to read from the serial line every xxx ms.
2. Seems like it would not be efficient to take over the display on every character that I receive. Is that the best practice or would a different approach be advisable?

Thanks again!

Mark

Author: davetcc
09/06/2020 12:57:02
 
1. It looks like I could schedule a task to read from the serial line every xxx ms.


Yes, that would probably be quite straightforward to achieve, there's lots of examples in IoAbstraction of creating tasks. Just make sure that you don't do any blocking IO in that call, IE call available() before read().


2. Seems like it would not be efficient to take over the display on every character that I receive. Is that the best practice or would a different approach be advisable?


It's up to you, many take over the display at startup and only give the menu control when a "menu" button is pressed, to help with this there's also a reset timer, that can be set up to call you back when the menu is idle for a given amount of time (defaulting to about 30 seconds).

Author: markjhatch
09/06/2020 16:49:32
Dave,

Thank you again. Now for the fun part. smilie

Mark

Author: patebeng
17/09/2021 01:05:14
removed




Register / Login  |  Desktop view  |  Jump to top of page