tinkerspy / Automaton

Reactive State Machine Framework for Arduino
https://github.com/tinkerspy/Automaton/wiki
MIT License
374 stars 63 forks source link

Access machine data in callback #56

Open gtom opened 6 years ago

gtom commented 6 years ago

Hi, I have a machine with a state named POWER. In private-part of my machine class definition I added a timer:

Atm_timer timer;

Within the ENT_POWER part of this machine actions I want to start this timer that fires every 1000 ms:

timer.begin(1000).repeat(-1).onTimer( timer_callback ).start();

My callback function is:

void timer_callback( int idx, int v, int up ) {

Serial.print("callback: ");

Serial.println(up); // just counting

}

in EXT_POWER I stop() my timer later on. This works fine. But now I want to have access to one of my machines public attributes within my callback. How can I achieve that? Is there any possibility to send more arguments (eg. this->value) to my callback? I think this problem is not about Automaton itself but perhaps anyone knows a working solution? gTom

tinkerspy commented 6 years ago

Why don't you use a standard atm_timer_millis object inside your state machine and then change state when the timer expires. Then you stay inside the machine and have access to all values.

Rgdz, Tinkerspy