[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.

Two Button Menu RSS feed
Forum Index » tcMenu Arduinio library
Author Message
betti54


Joined: Jul 17, 2020
Messages: 5
Offline
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

davetcc


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


Joined: Jul 17, 2020
Messages: 5
Offline
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


davetcc


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


Joined: Jul 17, 2020
Messages: 5
Offline
Thanks for the clarification, points me in the right direction.

Cheers, Damien
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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.
 
Forum Index » tcMenu Arduinio library
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.