-
Hello Mr. Thomas, I am doing a lot of research and learning alot about c++ in order to utilize your library in a project. I am trying to use an ItemInput() with a callback function f(), in order to manipulate the String value parameter of the ItemInput(). But I am not sure how to get and set the value parameter of the ItemInput() object, within the callback function f(). My goal is to use a joystick to cycle each character in the value String to whatever the user wishes from the ASCII table, and then update the contents of the value parameter of the ItemInput() object. This value will later be saved as a setting in the EEPROM of a device, to be called as a parameter for a function that will be recording measurements from sensor over a period of time. I can currently explicitly grab the value using something like 'String x = mainMenu[4].value;' But I would like something more generic so that I can reuse the function on any ItemInput().value that calls the callback function f(). How would I pass a reference of the ItemInput() object to the callback function()? Or more directly, how would I get and set the value String parameter of the ItemInput() object, within the callback function? I would imagine it may be passing an implicit 'this' reference, that I could then get or set the value parameter with a this->value call. Any answers or resources you have in accomplishing this would be greatly appreciated. Thank you. I should note I also adapted the inputs for your library to come from a joystick with a press button. I have created five input commands to be interpreted from the joystick, up down left right and press, and debounced them. I've only used 4 so far as you only have four callable functions for menu navigation. I assume you designed the ItemInput() value Strings to be set by your keypad input device. p.s. I noticed that the newer versions of LiquidCrystal_I2C.h have deprecated the init() function and replaced it with a begin() function that does something similar. In my project I have manually replaced init() with begin() for the one occurence it has in your LcdMenu.h . Also in my research, I've learned that C++11 deprecated the conversion of Strings to char* types, and your example sketches, for the name parameters of the menuItem objects, pass Strings to the menuItem which is expecting char*. This comes up with a warning, but still compiles. Answers I've seen on stack exchange say this is left in for backward compatibility but should not be used, as it may lead to undefined behavior in the compiler. The easy solution is to declare the names as char* arrays outside the mainMenu declaration, and reference them for the name parameters of the menuItem() objects, instead of typing them in directly as Strings. Also a getTop() function on LcdMenu would be greatly appreciated when selecting digits to manipulate. The actual row to display a blinking cursor is at (myLcdMenu.getCursorPosition() - myLcdMenu.top) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
I have found that you can use your LcdMenu object and it's setText() member function to update the String value parameter, from within the callback function. This is because the library remembers the current menu position when calling the enter() function on a menuItem. Also to get the String value member parameter for the current menuItem there are 2 functions buried in the library I just dug up.
myLcdMenu.getItemAt(uint8_t position) to get ¤tMenuTable[position] Glad these were imbedded in there, but I really think you ought to update and flesh out your examples for each of these common abilities. Knowing I could have done this from the start would have saved me about a day and a half of head scratching. Although I did learn all about pointers and callback functions in c++ in the meantime. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
Beginning in version 2.0.0, the value of the //... stuff
//
ItemInput("Name","", saveName)
//
//... more stuff
//
void saveName(String name) {
// 🤗 do stuff with name
} |
Beta Was this translation helpful? Give feedback.
Beginning in version 2.0.0, the value of the
ItemInput
, the position ofItemList
or the toggle state is passed directly to the callback function,