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

tcMenu Arduinio library » Two Button Menu

Author: betti54
17/07/2020 01:30:13
Hi,

I'm a complete newbie to tcMeny, though am keen to use the library for a specific project with a TFT display which I've setup and got the basics working on.

Although I knew tat tcMenu used 3 input buttons (up, down, ok), I was hoping that I might get away with a 2 button input (this is a hard constraint of the solution). I believe I could make this work if the up (or down) button scrolled looped through the menu, such that once it hits the bottom it scrolls around to the top.

All of my input will be combo/enum style, and possible the dialogue to confirm an action though I've not tested that yet.

Any suggestions on how to achieve this (via a config change), or code mod would be very much appreciated.

Thanks in advance, Damien


Author: davetcc
17/07/2020 07:19:06
Hi there, yes within reason you can manage the menu in any way that you wish.

Basically you could set the input facilities to none, or custom input in the designer and then implement the input by just using two switches. Switches is a core part of the libraries that make up tcMenu and handles buttons with event callbacks. Take a look at the button / switch examples in https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/.

Once you've got two switches working, you can decide what function of the button (press, long press, repeat etc) causes which function.

For this, you'll interact with menuMgr, the object that is in control of the menu. I would implement RotaryEncoder in a way that it works for one button, as you described above, in the base class, there is a maximum value and a current value, you would essentially just implement it to go up every time the button is pressed and then wrap. You could even make it so it can go up and down, but for example, down has to be held down to work as down, where a short press is select. Take a look at the UpDownEncoderButtons class in https://github.com/davetcc/IoAbstraction/blob/master/src/SwitchInput.cpp as a starting point for that.


What I'd do is start with a sketch that uses the standard 3 button arrangement, and then understand how it's configured in <projectName>_menu.cpp/h in your project, this will give you an idea how to implement and set up your own facilities. Never add any code in the <projectName>_menu files, as they are overwritten every cycle.

Author: betti54
17/07/2020 07:35:46
Hi,

Thanks for the reply. I'm up and running with 3 buttons, that works great and looks slick!

I'm just looking for the least impact change to operate with OK and DOWN buttons, so when DOWN hits the bottom of a list it will cycle back to index 0 in a loop.

Can you please elaborate what you mean by "set the input facilities to none, or custom input in the designer and then implement the input by just using two switches"?

Thanks, Damien



Author: davetcc
17/07/2020 08:54:13
I mean that in the TcMenuDesigner application -> Generate Code dialog, you'd turn off the generation of input facilities and then instead you'd just provide your own rotary encoder and select button function.

There are many implementations of RotaryEncoder (base class defined in SwitchInput.h) that you can take a look at, and then implement your own. I'd say the up down one would be the best starting point. RotaryEncoder is a really bad name for the class, it's really something more akin to Scrollable. The way tcMenu works is that the menu position is controlled by the encoder, and in edit mode, the values are chosen by the encoder. So if you implement that, you'll get everything out of the box.

For an example of what the default does, see MenuManager::initForEncoder and MenuManager::initForUpDownOk in tcMenu.cpp

Always set up the input last, basically after the setupMenu() has finished in your project sketch / main file.

Author: betti54
17/07/2020 09:14:48
Thanks for the clarification, points me in the right direction.

Cheers, Damien

Author: davetcc
19/07/2020 09:17:47
Feel free to reach out again if you need more assistance getting started with this. I would be interested in how it works myself if you can get a prototype working, it may be an option that should be added to the core set.




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