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

tcMenu Arduinio library » How to Use the ListRuntimeMenuItem

Author: Snafky
30/07/2019 07:17:41
Hi All!

I'm love the tcMenu lib and thank you so much for creating it!
I gives hobby/amateur programmers the ability to create something which would have taken me probably to long or even impossible (for me).

It is with this mindset that come to the following question.
How should I use ListRuntimeMenuItem to create a dynamic list of items during runtime(to select from).
I know it mainly my lack of understanding why i can't use is properly.
The main thing i don't understand is how to handle the "V" parts in the code ( buffer[0] = 'V'; buffer[1]=0 smilie.

I cannot find any examples how to use it in the "example" folder.
I did read the documentation but i'm not getting all of it (or how it fits together, sorry).
I hope that there is anyone out there that can help me....

This is the code stub created automaticly for handling the menu
// see tcMenu list documentation on thecoderscorner.com
int CALLBACK_FUNCTION fnDevicesRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
   switch(mode) {
    case RENDERFN_INVOKE:
    	Serial.println("Index selected: " + String(row));
        // TODO - your code to invoke goes here - row is the index of the item
        return true;
    case RENDERFN_NAME:
        // TODO - each row has it's own name - 0xff is the parent item
    	
        ltoaClrBuff(buffer, row, 3, NOT_PADDED, bufferSize);
        return true;
    case RENDERFN_VALUE:
        // TODO - each row can has its own value - 0xff is the parent item
        buffer[0] = 'V'; buffer[1]=0;
        
        fastltoa(buffer, row, 3, NOT_PADDED, bufferSize);
        return true;
    case RENDERFN_EEPROM_POS: return 0xffff; // lists are generally not saved to EEPROM
    default: return false;
    }
}

Author: davetcc
30/07/2019 08:09:28
Thanks for the post. TcMenu took quite a bit of work to get it where it is.

Agreed there are no real examples of lists at the moment. I’ll add a list item to one of the examples. The docs were updated for it yesterday but still not as good as an example.

Here’s a link to an actual use in the core code but by no means an example.

https://github.com/davetcc/tcMenuLib/blob/master/src/RemoteMenuItem.cpp Function: authenticationMenuItemRenderFn

Author: Snafky
30/07/2019 08:36:02
Thank you for the quick reply!
And indeed i can see all the efforts in TcMenu and i can imagen some examples are not there. smilie

Tonight (i'm in europe) i'll try to interpret what is on your link and do my best to understand it smilie.
Please let me know if i can help with anything. smilie

Author: Snafky
30/07/2019 21:24:38
Thanks to your tip to look at the other function i did get something more to go.
Unfortunatly i miss the knowledge/skill to wrap my had around the way the names of the menu items are derrived.
I see they come from a "const char XXX[] PROGMEM = "xxxxx";.
But my intention is to have the values dynamic at runtime.
As is said i miss some understanding and knowledge

I'll continue later with finding the exact way and understanding it.
Thank you for your help so far.

Author: davetcc
31/07/2019 18:32:30
There’s nothing that says they have to come from program memory. When the callback asks for the name the only thing you need to do is copy it as a zero terminated string into the buffer parameter provided. The buffer parameter is an array of char. The buffer size parameter is the number of elements in that array.

To be honest for this level of embedded C / C++ coding you’re going to need to fully understand c zero terminated character arrays. There are many online guides for that.

Author: Snafky
31/07/2019 19:37:02
thanks for your reply and i'll dig into the subject for sure.
I have noticed its my tripping point in many source code i see and indeed the problem lies with me.
Thank you for the patient i'll have to learn how to use this stuff so i won't hold you longer with my questions.
Cheers.

Author: davetcc
01/08/2019 13:48:57
No problem, hope you enjoy learning C strings and pointers!




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