Wednesday, May 15, 2013

Pointers on Pointers in Arduino Land

My degree in CS dates back a long long ways...in fact so far back that "C" was only just starting to gain in popularity and Unix System V had just come out of Bell Labs into the university community.   Pointers made my head hurt then and they still do today!   The following code defines and then passes an array of structures to a function.  It took me forever, and a lot of help from the Arduino forum, to get this to work to this point...but...I have a lot of learning still to do.

struct F4Utft {
    String name;
    int x;
    int y;
    String formatName;
};

static struct F4Utft m01 = {"selStats", 15, 195, "BigFontS"};
static struct F4Utft m02 = {"selGraph", 215, 195, "BigFontS"};
static struct F4Utft m03 = {"line2", 15, 185, "None"};

struct F4Utft *Def_Menu[] = {&m01, &m02, &m03};

void setup() {
    // For debugging messages
    Serial.begin(57600);

    Serial.println("--->" + Def_Menu[1]->formatName);
    Serial.println("--->" + String(test(Def_Menu)));
}

void loop() {
    while (true) {

    }
}

String test(struct F4Utft** menu) {
    return(menu[1]->formatName);
}

The initializer gave me fits and there is another format (single statement with a structure declaration before each entry) that I liked better could not get to work...but this does so I am happy and can move on!

My next challenge is to try and understand why I can not seem to put this resultant structure into PROGMEM without it killing my script.......arghhhhh!

No comments:

Post a Comment