Carrying parameters to a timer callback
Posted: Fri Sep 08, 2017 1:11 am
I am wishing there were a way to carry a "miscellaneous baggage" parameter to a timer callback or a node.task.post callback.
Currently node.task.post() gives a "priority" argument to its callback function. That seems rather useless, unless I am missing something obvious. And a callback from myTimer.alarm() is given one argument, the ID of the timer.
I have a stepper motor application with two myStepper1 and myStepper2, constructed as objects. They each own a OO timer, and the two timers call the SAME class Stepper "step" function. When Stepper.step(timr) callback is called by the timer, the only thing the callback can know is the timer. It doesn't know who OO "itself" is! I have needed to use a lookup table of timerID-vs-stepperID to find my own OO "self". In the Stepper constructor [ myStepper1 = Stepper.new(pin, pin, pin, pin) ] I add a new entry to a lookup table: Stepper.identifyMe[self.timer]=self
And then as step() starts I need to retrieve my own identity like this: local self = Stepper.identifyMe[timr]
Unnecessarily convoluted. Again, am I missing something easy?
Currently node.task.post() gives a "priority" argument to its callback function. That seems rather useless, unless I am missing something obvious. And a callback from myTimer.alarm() is given one argument, the ID of the timer.
I have a stepper motor application with two myStepper1 and myStepper2, constructed as objects. They each own a OO timer, and the two timers call the SAME class Stepper "step" function. When Stepper.step(timr) callback is called by the timer, the only thing the callback can know is the timer. It doesn't know who OO "itself" is! I have needed to use a lookup table of timerID-vs-stepperID to find my own OO "self". In the Stepper constructor [ myStepper1 = Stepper.new(pin, pin, pin, pin) ] I add a new entry to a lookup table: Stepper.identifyMe[self.timer]=self
And then as step() starts I need to retrieve my own identity like this: local self = Stepper.identifyMe[timr]
Unnecessarily convoluted. Again, am I missing something easy?