Page 1 of 1

HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Posted: Wed May 20, 2020 1:52 pm
by jmcSciences
Hello,
As of the new 1.9.0 release, attachInterrupt callback's API of the HardwareTimer class is now std::function(void). HardwareTimer *htim is no longer passed as argument. As the callback must be a C function pointer, it must be a static function or a static member. So "this" operateur isn't usable.

So now, how to handle the HardwareTimer instance caller in the timer interrupt callback ?

Re: HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Posted: Wed May 20, 2020 2:16 pm
by fpiSTM
Answer from @ABOSTM ;)
With the new implementation done in the 1.9.0, it is always possible to give an argument to the callback at execution time. Thanks to the magical C++ binding and templates.

But the parameter is no longer restricted to the HardwareTimer object, it can be anything.
It is therefore always possible to pass the object ... but more if necessary.
An example is available here:
https://github.com/stm32duino/STM32Exam ... _parameter

Re: HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Posted: Wed May 20, 2020 3:33 pm
by jmcSciences
that's clear now, thank you for all ! ;)

Re: HardwareTimer : How to handle HardwareTimer instance caller in the timer callback

Posted: Wed May 20, 2020 11:22 pm
by mrburnette

Code: Select all

  // Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup() function is finished.
+1 Nice


Ray