Comments (4)
Old topic but I'll add this for anyone passing through:
The simple solution to the original question appears to be to just define an 'Update' event with a corresponding react handler just like any other event.
Dispatch the 'Update' event every iteration of the main loop, and it will call the respective react for 'Update' on the current state if defined. I was able to use this for simple timeout functionality when playing around with the library.
from tinyfsm.
Might be a dumb question. But my understanding is that the react method of each state is used to update the current state.
The state is updated in transit:
https://github.com/digint/tinyfsm/blob/master/include/tinyfsm.hpp#L137
Is there some way of including an update method that is called on each loop of the main program? Making it possible to perform an operation for the duration of the state?
You can e.g. call such a methon in exit/entry functions, these are always called before / after transit.
from tinyfsm.
Hello @digint could you maybe elaborate a little bit further on this? I'm a novice C programmer so maybe you could give me some hint?
I'd love to implement this state machine on an ESP8266. The ESP is currently connected to a LED matrix and I implemented two featrues: display a clock and display animated Gifs. Now i want to combine both and be able to switch between the two states clock
and gif
. Both implementations need to have a method loop()
called in the EPS loop
method to update the time / draw the next frame of the gif.
The state machine itself is working, but I'm not sure how to update the state in the ESP loop
method. So the state transition would set up the clock or the gif decoder. But I'm not sure how to implement a method loop
that is called on the current active state and will call for example clock->loop()
or gifdecoder->loop()
.
I tried to create a After looking into the code and documentation, maybe a event is the way to go?Loop
event and continue to call this in the loop
method. But I think this is a little bit overkill. A direct call would be easier?
from tinyfsm.
You can e.g. call such a methon in exit/entry functions, these are always called before / after transit.
These methods don't really call on for the duration of the state. Presumably one could loop inside the entry and exit methods, but ideally those methods would execute once and return.
My use case is that I'd like to poll a device in order to get the conditions to transit to other states. I'm thinking something like
fsmList::Run(), that would could call the run methods of each fsm in the list.
Is this something of interest, or am I thinking of a use case that is ill suited for this library?
edit:
Also another way would be to constantly transit between two states, which would then evaluate the conditions for breaking the loop.
from tinyfsm.
Related Issues (20)
- Events double dispatching support HOT 3
- Should FSM_INITIAL_STATE call entry? HOT 1
- Is it possible to query the current state of the State Machine? HOT 4
- How do you pass a SM to a function? HOT 1
- non virtual destructor HOT 3
- Linking error HOT 3
- Not able to compile with IAR ARM v8.20.2 HOT 2
- size on Mac doesn't support -B flag HOT 1
- calling dispatch() before start() throws unhandled exception with read access violation HOT 2
- any plan for latest tag release ? HOT 4
- Doesn't compile when debug information is enabled. HOT 2
- How to separate state classes from the state machine class?
- Is it possible to set initial state (at runtime) to something which is different from what was passed in FSM_INITIAL_STATE? HOT 1
- is it possible to instantiate multiple Elevators classes, using the same elevator.hpp and .cpp? HOT 3
- connecting IO class with Tiny FSM HOT 2
- Testing tinyFSM state machines with VectorCAST?
- Calling dispatch() and/or transit() from action function HOT 3
- Handle multiple FSMs HOT 2
- Security Disclosure Policy HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyfsm.