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

Passing data into the State machine. #15

Open
Emmett-Byrne opened this issue Oct 22, 2018 · 2 comments
Open

Passing data into the State machine. #15

Emmett-Byrne opened this issue Oct 22, 2018 · 2 comments
Labels

Comments

@Emmett-Byrne
Copy link

I was wondering how I might pass data into the state machine either during initialization or after it's been initialized.
I seen this question came up before but the author closed it without providing a solution and I can't find it in the examples provided.

@digint
Copy link
Owner

digint commented Oct 23, 2018

For initialization, I suggest implementing a reset function (see example in: resetting_switch.cpp).

More generally, from a Fsm class, you can use the state<S>() function (with S being your state class) in order to access the state instance, see:

https://github.com/digint/tinyfsm/blob/master/examples/api/resetting_switch.cpp#L68

You can as well access the state instance low-level using _state_instance<S>::value, which represents the static instance of state S.
I would not recommend doing this, perhaps a better option would be to have some setMyData event?

@Emmett-Byrne
Copy link
Author

I just figured out moments ago. I just made some static variables and functions to access them similar to how direction and getDirection was done in motor.hpp.

Thanks for your help!

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

No branches or pull requests

2 participants