Automaton icon indicating copy to clipboard operation
Automaton copied to clipboard

Access machine data in callback

Open gtom opened this issue 7 years ago • 1 comments

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

gtom avatar Apr 11 '18 18:04 gtom

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

tinkerspy avatar Apr 19 '18 09:04 tinkerspy