Can someone help me with the following code ?
I have a custom class and I want to define a callback for the ticker
the function onTickerCallback()
.
It compiles and runs on ESP8266 but not on ESP32.
I see that ESP32 Ticker::once
has a different declaration but my c++ knowledge does not help me to find a solution.
Test.h
class Test {
public:
void start();
void doSomething();
private:
void onTickerCallback();
};
Test.cpp
#include <Arduino.h>
#include <Test.h>
#include <functional>
// for ESP8266: https://github.com/esp8266/Arduino/blob/master/libraries/Ticker/src/Ticker.h
// for ESP32: https://github.com/espressif/arduino-esp32/blob/master/libraries/Ticker/src/Ticker.h
#include <Ticker.h>
Ticker ticker;
void Test::start(){
ticker.once(5, std::bind(&Test::onTickerCallback, this) );
}
void Test::onTickerCallback() {
doSomething();
}
void Test::doSomething() {
Serial.println("Hello");
}
main.cpp
#include <Arduino.h>
#include <Test.h>
Test t;
void setup() {
Serial.begin(115200);
t.start();
}
void loop() {
}
On ESP32 I get the following error:
error: no matching function for call to 'Ticker::once(int, std::_Bind_helper<false, void (Test::*)(), Test*>::type)'
note: candidate: void Ticker::once(float, Ticker::callback_t)
void once(float seconds, callback_t callback)
note: no known conversion for argument 2 from 'std::_Bind_helper<false, void (Test::*)(), Test*>::type {aka std::_Bind<std::_Mem_fn<void (Test::*)()>(Test*)>}' to 'Ticker::callback_t {aka
void (*)()}'
note: candidate: template<class TArg> void Ticker::once(float, void (*)(TArg), TArg)
void once(float seconds, void (*callback)(TArg), TArg arg)
note: mismatched types 'void (*)(TArg)' and 'std::_Bind<std::_Mem_fn<void (Test::*)()>(Test*)>'