从班级传递一个void(*fn)
我正在使用PIO在Arduino Framework上使用ESP32编写自动显示关闭功能。 我有一个用于处理所有屏幕功能的屏幕类。
void Screen::turn_off_screen(){
digitalWrite(SCREEN_ENABLE, LOW);
}
void turn_off_screen_wrapper()
{
Serial.println("turn_off_screen_wrapper called");
if (c_screen_Instance != nullptr)
{
c_screen_Instance->turn_off_screen();
}
}
void Screen::auto_display_power_off(int timeout){
Serial.println("auto_display_power_off called");
c_screen_Instance = this;
auto_off_timer = timerBegin(0, 80, true);
Serial.println("auto_off_timer ran");
timerAttachInterrupt(auto_off_timer, &turn_off_screen_wrapper, true);
Serial.println("timerAttachInterrupt ran");
//Converts given seconds from us to seconds
timerAlarmWrite(auto_off_timer,timeout*1000000,false);
timerAlarmEnable(auto_off_timer);
}
但是,当我在板上运行时,我会得到代码。
auto_display_power_off called
[E][esp32-hal-cpu.c:93] addApbChangeCallback(): duplicate func=400811F8 arg=3FFBDC54
auto_off_timer ran
屏幕当然永远不会关闭,因为回调从未运行。有什么想法,为什么会发生这种情况?
I'm writing an auto display turn-off function with ESP32 on Arduino framework with PIO.
I have a Screen class for handling all of the screen functions.
void Screen::turn_off_screen(){
digitalWrite(SCREEN_ENABLE, LOW);
}
void turn_off_screen_wrapper()
{
Serial.println("turn_off_screen_wrapper called");
if (c_screen_Instance != nullptr)
{
c_screen_Instance->turn_off_screen();
}
}
void Screen::auto_display_power_off(int timeout){
Serial.println("auto_display_power_off called");
c_screen_Instance = this;
auto_off_timer = timerBegin(0, 80, true);
Serial.println("auto_off_timer ran");
timerAttachInterrupt(auto_off_timer, &turn_off_screen_wrapper, true);
Serial.println("timerAttachInterrupt ran");
//Converts given seconds from us to seconds
timerAlarmWrite(auto_off_timer,timeout*1000000,false);
timerAlarmEnable(auto_off_timer);
}
The code compiles however I get this when I run it on the board.
auto_display_power_off called
[E][esp32-hal-cpu.c:93] addApbChangeCallback(): duplicate func=400811F8 arg=3FFBDC54
auto_off_timer ran
The screen never gets turned off of course since the callback never runs. Any ideas why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
c_screen_instance
全局吗?auto_off_timer
全局吗?考虑提供更多代码。
但是无论如何。
这是
addapbChangeCallback
的声明。您的错误来自此行:
其中
r
是一个结构,可以保留所有回调。此错误确实表明此回调函数已在您的代码中的某个地方分配。
r
是全局,因此您的代码正在两次重新分配同一回调。尝试仅分配一次,或者在使用
removeapBchangeCallback(void * arg,apb_change_cb_t cb)
或timerDetachIrstrupt
我也找到了一个报告的报告与
timerattach
在当前版本上有关的问题: https:/ /Github.com/espressif/arduino-esp32/issues/6730尝试将平台PIO的版本滚动到更稳定的版本中:
查看可用的可用标签的git链接。
is
c_screen_Instance
global?is
auto_off_timer
global?Consider providing a bit more of your code.
But anyway.
This is
addApbChangeCallback
's declaration.Your error comes from this line :
Where
r
it's a struct to hold all the callbacks.This error indeed indicates this callback function was already assigned somewhere in your code.
r
is global, so your code is re-assigning the same callback twice.Try to either only assign it once, or to unassign the function before assigning it again with
removeApbChangeCallback(void * arg, apb_change_cb_t cb)
ortimerDetachInterrupt
I've also found a reported issue related to
timerAttach
on the current version here: https://github.com/espressif/arduino-esp32/issues/6730Try to roll back the Platform PIO's version to a more stable one:
Check on the git link for the available tags you can use.
问题是我将中断连接在void loop()中。它的运行速度比实际计时器快。将其移至设置(设置为占位符)之后,我计划将其放在硬件中断上,它按预期工作。
Problem was that I was attaching the interrupt in the void loop(). Which would run way faster than the actual timer. After moving it to setup (Setup being a placeholder) I plan on having it on a Hardware interrupt it worked as expected.