jgc/falco_sw_ard_tft

Optimize data structures and code size

jgc opened this issue · 0 comments

jgc commented

See https://community.particle.io/t/gpio-control-via-gui/6310/6
and https://community.particle.io/t/gpio-control-via-gui/6310/4

const int value_count = 8; // the maximum number of values
int values[value_count];    // store the values here

char string[50];
strcpy(string, "123,456,789");  // the string to split
int idx = 0;
for (char* pt=strtok(string, ","); pt && idx<value_count; pt=strtok(NULL, ",")) {
   values[idx++] = atoi(pt);
}
At the end of the code, the values array looks like this:

values[0] = 123;
values[1] = 456;
values[2] = 789;

And idx equals 3, so you know there are 3 values in the array, just in case the user passes in more or fewer values.

See also re HEX encoding to save space: https://community.particle.io/t/gpio-control-via-gui/6310/34