I’m trying to write a class that will handle interrupts from button pushes using an EventQueue. I’ll need to send data over a BufferedSerial connection in response to the event so I can’t do it in the interrupt handler.
I’m completely stuck, likely because of my rusty C++ skills, on how I can construct a call to queue.event that actually compiles and results in a call to my class’s method. All of the examples I can find online are basic C examples where the event handler function is just a function, not a class member.
Keeping it simple if I have a class definition like this:
In order to get this to compile I had to specify "platform.callback-nontrivial": true. In OnPress() I am setting the onboard LED to 1 and in OnRelease() I’m setting the onboard LED to 0.
When I run this and press the button the LED starts to flash on and off randomly
Thanks for the reply. The EventQueue API documentation only has examples for basic C functions that aren’t part of a class. I’m specifically trying to learn how to use a class method as the event handler.
Thanks for the tip on the blinking LED, it is indeed crashing with a Fault exception
It works! Thanks @JohnnyK the code sample was just what I needed. Once I solved some other dumb pointer issues the event handler gets called correctly and the LED flashes.
It can be, but it is not correct solution because you will lose it every time you change MbedOS version.
Correct is to place content below to mbed_app.json file
so in my application i have a machine with 3 axes that are controlled by stepper motors so i built a class to control these axes. a “move” command will come in over the USB and my application will call the appropriate axis. when then move has been completed by the axis class i want an event to be raised ion the main where a handler will determine what to do next.
++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: bool(*this)
Location: 0x800AE83
File: ./mbed-os/platform/include/platform\Callback.h+506
Error Value: 0x0
Current Thread: main Id: 0x20005F34 Entry: 0x800BC19 StackSize: 0x1000 StackMem: 0x200047C8 SP: 0x2004FE78
For more info, visit: https://mbed.com/s/error?error=0x80FF0144&tgt=NUCLEO_F746ZG
-- MbedOS Error Info --
= System will be rebooted due to a fatal error =
= Reboot count(=1) reached maximum, system will halt after rebooting =