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

IoAbstraction & TaskManagerIO » takeOverDisplay and encoder

Author: Andrea
10/05/2021 08:14:44
Hi,
I'm working with ESP32, ILI9341 and rotary encoder around takeOverDisplay example.
I'm trying to take menu ready to use in background and one or some other display window to visualize other things by default ( for example temperature and time always visible and when I click encoder, I start menu).
With one default window I have no problem,I have add a window design in "myDisplayFunction" of the eample, so when I use the CALLBACK_FUNCTION, I return to my default screen.

Now I want to scroll between some other two window with encoder (outside of menu function) and go to Menu only when I press encoder button for 5 sec (for example).

My question is:
there's a way to use encoder outside of Menu function for other purpose? For example, if I press button short I turn on the backlight, if I move encoder I switch between two other screen, if I press button for lon time I will start Menu.

how can I manage encoder button for a long time pressed? there's a built in function or I must create by myself?
thanks

Author: davetcc
10/05/2021 08:54:03
 
how can I manage encoder button for a long time pressed? there's a built in function or I must create by myself?


When the button is held down it goes into a HELD state after about 1 second, if the repeat key parameter is set it will start repeating at this point. You can adjust the timing by changing the repeat / hold frequency passed in, see: https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/switches-rotary-encoder-documentation/.

there's a way to use encoder outside of Menu function for other purpose


In terms of getting encoder values there are two possibilities:

1. Simplest: in the takeOverDisplay rendering callback, the first parameter is the encoder's current value, the second parameter is the switch state (see enum). You can adjust the range of encoder values by changing the range that it currently represents, again, see the above link

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


2. you register the rotary encoder and switch yourself (see the above link), then pass the values to menuManager when the menu is being displayed. For this see "Controlling the menu items manually" in https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/. Be aware that this (option 2) is a pretty advanced use case, and not used that often. There are possible assumptions that switches.getEncoder(0) is the menu encoder. Option 1 requires little on your side and works pretty well for many cases.



Author: Andrea
10/05/2021 14:48:38
ok, I've tested the "simplest" one and it work!
Now I work on it, thanks!

really great work!!

Author: Andrea
14/05/2021 12:44:19
I am still working on a sketch based on the 'takeOverDisplay' example, where the menu function remains in the background and by default I display a screen I created.
I tried to exploit the encoder value read during the execution of the function called by the 'takeOverDisplay' callback to be able to view other screens.
in particular I am going to make a partial update of the screen that allows me to view the temperature of other areas of the house every time I rotate the encoder, based on the value read and recalling different functions. I noticed that every time the 'takeOverDisplay' function is called (for example exiting the menu), the encoder value is always 50.
Can I rely on this value?
is it a default value you set?

at the moment, for how I set up the sketch, everything is great, but I would like to be sure that this value remains the same.

Other question:
There’s a timer that takes me back to my screen ( or takeOverDisplay) . How can I set it, if is possible to set?

Author: davetcc
14/05/2021 17:19:45
 
There’s a timer that takes me back to my screen ( or takeOverDisplay) . How can I set it, if is possible to set?


You can add a reset handler, see this link that describes how to handle the reset event: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/renderer-take-over-display/

I noticed that every time the 'takeOverDisplay' function is called (for example exiting the menu), the encoder value is always 50.



When you take over the display, if you want to use the encoder, then you need to set the range and current value. Normally you'd do something like:

void myRenderingFunction() {
   // do the drawing
}

void onTakeDisplay() {
    // 1. take the display
    renderer.takeOverDisplay(myRenderingFunction);
    // 2. set the encoder range and current value
    switches.getEncoder()->changePrecision(zeroBasedMaximum, currentValue);
}

Author: Andrea
14/05/2021 17:24:39
Perfect, all clear, thanks!




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