Hello,
i'm not sure how to properly architect the code in this situation.
This is rtos type system, where i want to create a few objects that perform actions based on the events.
I think that once "setup" function completes, the "eventGroup" variable becomes inaccessible from "outlet" object.
EventGroupHandle_t xEventGroupCreate( void );
Creates a new RTOS event group, and returns a handle by which the newly created event group can be referenced.
Question:
what is the proper way of proceeding in this situation?
1 2 3 4 5 6 7 8
void setup() {
...
// Create event Group for use by all tasks
eventGroup = xEventGroupCreate(); //check if NULL NOT returned.
...
Zap* outlet = new Zap(DATA_PIN, &eventGroup,bit_time, "Task UNO") ; // make a new Zap instance
...
}
I think that once "setup" function completes, the "eventGroup" variable becomes inaccessible from "outlet" object.
I couldn't say. I don't see in which scope eventGroup is declared. If it's a local then yeah, obviously the object from line 6 will point to an object that no longer exists, if it continues to exist after the function returns. It's the same as doing this:
1 2 3 4 5 6 7 8 9 10
struct A{
int *a;
};
A *f(){
int x = 42;
returnnew A{&x};
}
std::cout << *(f()->a) << std::endl;
Is Zip your class? Why are you passing a pointer to handle? Just pass the handle.
Helios,
thank you for the reply.
To answer your question:
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
// other includes
#include <zap.h>
EventGroupHandle_t eventGroup;
void setup() {
...
// Create event Group for use by all tasks
eventGroup = xEventGroupCreate(); //check if NULL NOT returned.
...
Zap* outlet = new Zap(DATA_PIN, &eventGroup,bit_time, "Task UNO") ; // make a new Zap instance
...
}
If that's how Zap is declared then this new Zap(DATA_PIN, &eventGroup,bit_time, "Task UNO") ; is clearly wrong. Zap is expecting an EventGroupHandle_t as the second parameter, yet you're passing a EventGroupHandle_t *.
I was thinking that it might not be available, since "setup" has completed.
How would whatever framework you're using know that one of your functions has returned?