Go Down

Topic: New Arduino library: MenuSystem (Read 30454 times) previous topic - next topic

Dorzo_

#60
Aug 18, 2017, 04:25 pm Last Edit: Aug 22, 2017, 06:34 pm by Dorzo_ Reason: Found a way that works
Hi fellow duinists,

I am doing a project which includes a tft display, and at startup it is supposed to have some menu items where the user can select some startup options.
I have successfully made a sketch that will display some menu-items, a sub-menu (level 2 items) and am able to navigate it with some buttons.

After many failed attempts i have even been able to show and modify a NumericMenuItem. (select first time allows editing the number, then selecting again lets me go back to navigate the menu.

What i have not been able to do, but i think it must be possible, is to display that number as an integer, rather than as it is implemented in the library, a float.
As far as i understand, I should be able to define a ' format_value_fn '  that formats the float value into any String in a specific way.
But here i run into a problem. I get :

error: invalid conversion from 'String (*)(float)' to 'NumericMenuItem::FormatValueFnPtr {aka const String (*)(float)}' [-fpermissive]

It seems that the function i created is correct in that it returns a String from the input of a float, but the IDE complains that my function is not a member function of the NumericMenuItem class??

Does anyone have an example of using this format_value_fn, either adding it while defining the NumericMenuItem, or somewhere in the sketch by using the 'set_number_formatter' member function of the class?


Thanks for just reading :-)


edit Wednesday 2017/8/23

I have found a way that works.
- defined a type (variable that points to a function..) , and named the type 'MyPtr_type' .
     specifically it points to a function that takes a const float as argument and returns a 'const String'
           typedef const String (*MyPtr_type) (const  float val);

- declared an instance of that variable named My_pointer
           MyPtr_type My_pointer;
     
- created a function that is conforming to this, so that My_pointer can point to it
           const String My_Function (const float value){   .. insert function code here .. }

- Then let My_pointer actually point to My_function
           My_pointer = My_function;

Now I can instantiate (define) the NumericMenuItem with 'My_pointer' as the 7th argument (instead of NullPtr) .. if you know what  I mean.

Feeling a little smug now.. LoL
(Ah, dont forget THANKS So much to Nick Gammon for his very clear page on pointers to functions)

Still don't understand why a return value can be / should be defined as const. ??
But it seems to make a load of difference.
I understand that in this case it is required to be a const because the function in the MenuSystem library is also defined that way.
But in my (very limited) understanding, the keyword const in a function is used to tell the compiler that the source value should not be modified. (and if you try, it would give an error/warning)
But here even the return String is defined as const String.



jparisse

Hi,

I am attempting to replicate a working project that relies on MenuSystem.h and am having what I think may be a basic issue. When I compile I get:

no matching function for call to 'MenuSystem::MenuSystem()'

Searching leads me to C+ tutorials that are not necessarily related to running this library and a bit beyond my experience at the moment. I've matched code used in the program to best practices outlined in the tutorials for MenuSystem and I know this code runs elsewhere so I am reasoning that there is a problem with the IDE or something basic like that.

Can anyone suggest a path to troubleshooting this error with reference to MenuSystem.h? Thanks!

Jeff

tobias_faust

Hi,
are dynamic menuitems possible?
I want to display volatile menuitems (add_item/del_item) as a filelist that will be fetched over network in my loop.

Go Up