有人可以帮我解决以下代码吗?
我有一个自定义类,我想为该ticker函数定义一个回调onTickerCallback()。
它可以在 ESP8266 上编译并运行,但不能在 ESP32 上编译和运行。
我看到 ESP32Ticker::once有不同的声明,但我的 C++ 知识无法帮助我找到解决方案。
测试.h
class Test {
public:
void start();
void doSomething();
private:
void onTickerCallback();
};
Run Code Online (Sandbox Code Playgroud)
测试.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");
}
Run Code Online (Sandbox Code Playgroud)
主程序
#include <Arduino.h>
#include <Test.h>
Test t;
void setup() {
Serial.begin(115200);
t.start();
}
void …Run Code Online (Sandbox Code Playgroud)