[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

takeOverDisplay and encoder RSS feed
Forum Index » IoAbstraction & TaskManagerIO
Author Message
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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.


Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
ok, I've tested the "simplest" one and it work!
Now I work on it, thanks!

really great work!!
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
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?
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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);
}
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
Perfect, all clear, thanks!
 
Forum Index » IoAbstraction & TaskManagerIO
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.