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

tcMenu Arduinio library » Example / code snippet to make a menu item visible/invisble on button long press?

Author: hackintoshlover12
17/11/2021 05:06:24
Hey Guys,
I was trying to do some code to make one or more menu item visible/invisible by pressing the switch of attached encoder for more than 5 seconds.
Any help on how i can achieve the same would be very helpful.
I am stuck with it.
I know that the menu manager needs to be updated of the change by using notifyStructureChanged();
But how do i do that exactly?

Author: davetcc
17/11/2021 10:22:42
Something similar to the following should do the job in most cases:

Lets say you had an event handler onMyEventOccurs:

void onMyEventOccurs() {
    menuMyItem.setVisible(false);
    // any other structural changes to the menu
    menuMgr.notifyStructureChanged();
}


But to capture the button click from the encoder, as I said the other day in the issue, your use-cases are slightly outside what the default input plugin supports, you'll need to manually handle the input as per https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-plugins/customise-menu-input-display-plugin/ and https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/#controlling-the-menu-items-manually as by default it is assumed tcMenu has control of input unless you take over the display.

Let me know if it doesn't work and I'll take a look, but normally this should work because the rendering facilities are listening for structure change events.

Author: hackintoshlover12
18/11/2021 07:02:47
Hi Dave,
Thanks for sending the code snippet.
I tried the code snippet but i guess either menuMgr is not responding or i am doing something wrong.
Basically after changing menu item state i need to go back into main menu otherwise the changes don't display.
Kindly have a look at the attachments below.
https://drive.google.com/file/d/1uCWTkDWmbUL0khwaUNkY7hDvVIVP_v5l/view?usp=drivesdk

[Thumb - Screenshot (87).png]
Filename Screenshot (87).png
Description No description given
Filesize 69 Kbytes
Downloaded 888 time(s)
[Disk] Download


Author: davetcc
18/11/2021 18:10:03
I'll probably need to try this exact case and see what happens to be honest. I'll feedback once I've had a chance to test it.

Author: hackintoshlover12
18/11/2021 19:04:09
Thanks
I'll wait for your response




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