Callback functions

Discussion related to "under the hood" OpenMV topics.
ArneLegrand
Posts: 10
Joined: Wed Feb 19, 2020 10:47 am

Callback functions

Postby ArneLegrand » Tue Feb 25, 2020 3:45 am

Hellow

To use the timer's callback function, in the example it says you can not use functions that allocate memory in these callbacks.
So this means it is not possible to use the TF person detection code inside a callback function? I have tried this and it has worked. But not always, it can also shut down the camera and disconnect.
Is there anyway to use a timer to trigger other events then the callback function?
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Callback functions

Postby iabdalkader » Tue Feb 25, 2020 9:46 am

ArneLegrand wrote:
Tue Feb 25, 2020 3:45 am
Hellow

To use the timer's callback function, in the example it says you can not use functions that allocate memory in these callbacks.
So this means it is not possible to use the TF person detection code inside a callback function? I have tried this and it has worked. But not always, it can also shut down the camera and disconnect.
Is there anyway to use a timer to trigger other events then the callback function?
You can just set a flag and check in the main loop if that flag is set, run the person detection and clear the flag.
ArneLegrand
Posts: 10
Joined: Wed Feb 19, 2020 10:47 am

Re: Callback functions

Postby ArneLegrand » Wed Feb 26, 2020 3:21 am

Yhea did that now. Can you explain why you can't do anything memory allocating in the timer callback?

Thanks for the answer
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Callback functions

Postby iabdalkader » Wed Feb 26, 2020 11:42 am

ArneLegrand wrote:
Wed Feb 26, 2020 3:21 am
Yhea did that now. Can you explain why you can't do anything memory allocating in the timer callback?

Thanks for the answer
It had something to do with MicroPython's garbage collector being locked in IRQs I think, maybe it's not thread-safe, can't really remember the exact issue but it's not allowed.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests