I am writing for a very limited resource embedded processor. I have a structure that captures the time series of events, and I would like to use the same graphic display function for different values โโof different types. Something like (very stripped down, do not sweat uninitialized values, etc.):
#define GRAPH_ONE 1 #define GRAPH_TWO 2 struct _event_t { unsigned long timestamp; int sensorOne; float sensorTwo; } typedef struct _event_t event_t; event_t[10] MyEvents; void GraphSensor(byte graphType) { for (unsigned int i = 0; i < 9; i++) {
How can I use my function for different members of the structure? I can see this with a ton of switch (graphType) statements, but it's pretty ugly. There can easily be 8 or 10 members of the structure. I could move all these functions to a separate function and make each data access bit this function, always returning a float (which should be OK for my graph). Finally, I can convert to C ++ classes, which opens up other tools.
None of them are feeling well. Is there a better approach, preferably very light?
source share