GithubHelp home page GithubHelp logo

State update loop about tinyfsm HOT 4 OPEN

digint avatar digint commented on May 31, 2024
State update loop

from tinyfsm.

Comments (4)

outlookhazy avatar outlookhazy commented on May 31, 2024 2

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.

digint avatar digint commented on May 31, 2024

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.

MoJo2600 avatar MoJo2600 commented on May 31, 2024

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 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? After looking into the code and documentation, maybe a event is the way to go?

from tinyfsm.

txf- avatar txf- commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.