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

tcMenu Arduinio library » Using rotary encoder whilst using renderer.takeOverDisplay

Author: WattsAmps
09/11/2020 12:18:43
Forgive any ignorance on my part I am very much a newbie where coding with Arduino is concerned.

My objective is to have essentially two main Display screens for my preamplifier controller.
It has one rotary encoder and an OLED display using U8G2 part of tcMenu.

Firstly I want a 'Main screen' which allows the user to change the volume, balance and inputs.
That would be the default or main screen. I have designed this and done some testing on it.

Secondly after a double press (or similar) on the rotary encoder I want to switch to using tcMenu and displaying this with a number of options available to the user.
I have built and tested the tcMenu and it works perfectly for my purposes.

I have also managed to default after power to the Main Screen and after a timed interval on to the tcMenu screen with exit and save settings all working.

But I cannot work out how to use the Rotary encoder for the volume/input/balance functions within my Main screen when when within the CALLBACK function called by renderer.takeOverDisplay.

I have tried various example functions such as the IOAbstraction buttonRotaryEncoder example and the tcMenu takeOverDisplay example and as examples they work fine.
But it appears that what ever I try tcMenu is controlling the encoder and I cannot read it unless tcMenu is displaying.

I have tried creating a new hardware encoder but using the same pins (excuse my ignorance but thought it worth trying).

I understand from several posts that everything I need to do for the main display must be handled within my CALLBACk function and I can probably work with this but I need to take control of the encoder as well as the display and I am stumped on how to do it. It maybe I just don't know how to capture the changes when outside of the tcMenu area.

Many thanks

Author: davetcc
09/11/2020 12:34:07
The current value of the rotary encoder is parameter 1 of the take over display callback.

Copied from the takeOverDisplay example shipped with tcMenu library :

What you'd normally do is to set the encoders range of possible values directly upon taking over the display, then every time you are called to draw the screen, the encoder value and button state are provided.

void myDisplayFunction(unsigned int encoderValue, RenderPressMode clicked)



Rotary encoder for the volume/input/balance functions within main screen


you can access menu items programatically, take a look in the _menu.h file and you see they are all declared there. Writing a complex custom renderer though is probably outside the scope of a forum post.

I recommend that you look through the examples, as several of them have different ways to deal with taking over the display.

Author: davetcc
09/11/2020 12:44:33
Just to add when taking over the display the usual procedure is:

1. call takeOverDisplay either having provided the callback function or display observer object

2. upon first taking over the display (either first time into the callback or on the notification for take over starting) prepare the display and initialise the encoders range. For example: switches.changeEncoderPrecision(999, 50)

3. upon every callback you would then draw the screen as needed, taking account of any changes in encoder value. You can programatically access menu items as discussed above.

Author: WattsAmps
09/11/2020 14:21:19
thanks for the very prompt response.

I have been accessing the menu items programatically without issue and use that to populate my 'main screen'. So I don't see that the current value of the encoder at the point of taking back the display helps me much.

So my thought was while displaying my main screen I should be able to use the same rotary encoder to change the value for the volume/input/balance which I can then programatically update/write back to the menu.

I understand I would need to use switches.changeEncoderPrecision but I can't seem to read the encoder value when changing it outside of the tcMenu display and therefore I am not sure what this is going to achieve.

If I set up a hardware encoder with an onChange call back that encoder works but values only change whilst tcMenu is displaying (i.e. my simple onChange event prints the changed value to serial).

What I don't want to do is push the user into using the tcMenu section to adjust volume etc. I just plan to redraw my Main screen as/when volume is changed programatically update/write back to the menu but using the one rotary to change it. At the moment it looks like I would have to dedicate one rotary to the main screen and one to tcMenu...

I could of course build my own menu system from scratch but your library and app are way way easier smilie
Sorry I am probably being thick or just lack the knowledge for what I am trying to do but I really do appreciate your help.

Author: davetcc
09/11/2020 14:49:02
I think an example serves to help out here, lets imagine you have a menu called menuVolume and you wanted to control it with the encoder during the take over display callback, this is all that would be required (apart from drawing of course!):

void weNeedToTakeOverScreen() {
  renderer.takeOverDisplay(myDisplayCallback);
  switches.changeEncoderPrecision(menuVolume.getMaximumValue(), menuVolume.getCurrentValue();
}



void myDisplayCallback(unsigned int encoderValue, RenderPressMode clicked) {
  if(clicked) {
    renderer.giveBackDisplay();
  }

  menuVolume.setCurrentValue(encoderValue); // it only updates if it has changed, so safe to keep calling\

  // your rendering would go here!
 
}

Author: davetcc
09/11/2020 15:02:52
Also, when you are called back in the rendering function, the clicked parameter is actually the state of the encoder button. It is an enum of:

enum RenderPressMode: uint8_t { RPRESS_NONE = 0, RPRESS_PRESSED = 1, RPRESS_HELD = 2 };

So you could use short presses to change the input, and a press and hold to go back to the menu for example.

I hope this clears up how to use the encoder during the custom display callback.

Author: WattsAmps
09/11/2020 15:28:05
Thank you

I will build a stripped down simple version get that working and go from there

Author: WattsAmps
09/11/2020 16:29:45
Thanks again for your very prompt responses.
Your simple example really helped this simple bloke out!
My stripped down version works as expected and explained so I can now build on that.




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