digint/tinyfsm

Passing data into the State machine.

Emmett-Byrne opened this issue · 2 comments

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.

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?

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!