I am looking for the best way to pass different objects into the same queue for my lcd task. I am using C.
As an example, I am faced with sending different objects such as strings, bmps, buttons, etc to an lcdTask’s queue.
Is there an elegant and efficient way to do this, or is this a no-no in practice?
Here are my thoughts on one approach for doing this:
I was thinking of using a struct that contains
int dataType; //string, bmp, etc
void * data; //pointer to the string, bmp, etc
and then the lcd task will get the dataType from this **object **struct and then use that information to properly dereference the data. Is this a good way to send different datatypes to the same queue or is there a better way? The one question I have about this approach is how do the tasks putting this data into the lcdQueue find out the type of datatypes available (string, bmp, etc). If I define these datatype structs in lcd.h (where the lcd task is), then what is the best way for functions residing in other modules to find out the datatypes and how to populate them…right now, the way I was thinking to handle this is to store these datatype structs in the lcd.h file to share the datatype (string, bmp) directly. Is there a better way to do this, for example, by utilizing a public function in lcd.c that the callee residing in another module can ask for the different types of datatypes (string, bmp) available?
Thanks for your insight and help.