Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Initialization Outside of Main #433

Open
mikejr83 opened this issue Jan 20, 2024 · 2 comments
Open

Support for Initialization Outside of Main #433

mikejr83 opened this issue Jan 20, 2024 · 2 comments

Comments

@mikejr83
Copy link

I'm trying to get this library set-up so that I can initialize a rather complex menu structure in a separate file. How can I do this? It doesn't seem possible that I can return nav:

MenuConfig.cpp

Menu::navRoot CreateMenu()
{
  // create menu structure
  NAVROOT(nav, mainMenu, MAX_DEPTH, in, out);

  return nav;
}

main.cpp

Menu::navRoot nav = CreateMenu();

void setup(void) 
{
  // set up Serial, etc.
}

void loop(void)
{
  nav.poll();
}

I've tried several ways, like passing references, etc. The program seems to crash in the loop.

Is there a way to do this or do am I forced to have a gigantic main.cpp file?!

@mikejr83
Copy link
Author

I found issue #293. This gives a great start, but I'm not sure how to do this within a helper function? The OP of that issue has an unresolved question on how to provide the return type. I've been struggling with trying to wrap my head on how to get the references in and out of a call to the function. I'm a C# dev so grasping how pointers and references work in this situation such that anything created locally in the function isn't destroyed is killing me.

@neu-rah
Copy link
Owner

neu-rah commented Jan 21, 2024

not sure if this helps, if dealing with value fields, they are hooked to your variables, so the values are already on the variables...
but if you still want you can capture the events, see this example https://github.com/neu-rah/ArduinoMenu/blob/master/examples/handlers/handlers/handlers.ino

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants