peterharrison:
The most space efficient method then seems to be something like:
...
This is not going to work.
-> To convince yourself just try this
const PROGMEM char path01[] = "dart.cfg";
const PROGMEM char path02[] = "arrow.cfg";
const PROGMEM char path03[] = "lightning.cfg";
void touch(const char* pathName) {
Serial.println(pathName);
}
void setup() {
Serial.begin(115200);
touch(path01);
touch(path02);
touch(path03);
}
void loop() {}
You won't see your string in the Serial console but garbage
It would need to be something like this to work fine
const PROGMEM char path01[] = "dart.cfg";
const PROGMEM char path02[] = "arrow.cfg";
const PROGMEM char path03[] = "lightning.cfg";
void touch(const void* pathName) {
Serial.println((const __FlashStringHelper*) pathName);
}
void setup() {
Serial.begin(115200);
touch(path01);
touch(path02);
touch(path03);
}
void loop() {}
and that's because the println() function knows how to handle a __FlashStringHelper pointer
In your case the open function does not know how to handle a __FlashStringHelper pointer so you would have to create a local cString (null terminated char buffer) to call open() and close(). Something like this (using an array which is also in flash memory to make your life easier) should work
const PROGMEM char path01[] = "dart.cfg";
const PROGMEM char path02[] = "arrow.cfg";
const PROGMEM char path03[] = "lightning.cfg";
const char* const pathList[] PROGMEM = {path01, path02, path03};
const uint8_t nbPaths = sizeof(pathList) / sizeof(pathList[0]);
void touch(const uint8_t index) {
char buffer[51];
strncpy_P(buffer, pgm_read_word(&(pathList[index])), 50); // make sure you don't overwflow the buffer
buffer[50] = '\0'; // just in case
Serial.print(F("pathList["));
Serial.print(index);
Serial.print(F("] = \t"));
Serial.println( buffer );
// you would do your open / close on buffer
}
void setup() {
Serial.begin(115200);
for (uint8_t index = 0; index < nbPaths; index++) {
touch(index);
}
}
void loop() {}
or if you want to keep a function accepting an entry in the array
const PROGMEM char path01[] = "dart.cfg";
const PROGMEM char path02[] = "arrow.cfg";
const PROGMEM char path03[] = "lightning.cfg";
const char* const pathList[] PROGMEM = {path01, path02, path03};
const uint8_t nbPaths = sizeof(pathList) / sizeof(pathList[0]);
void touch(const char* const& p) {
char buffer[51];
strncpy_P(buffer, pgm_read_word(&p), 50); // make sure you don't overwflow the buffer
buffer[50] = '\0'; // just in case
Serial.println( buffer );
// you would do your open / close on buffer
}
void setup() {
Serial.begin(115200);
for (uint8_t index = 0; index < nbPaths; index++) {
Serial.print(F("pathList["));
Serial.print(index);
Serial.print(F("] = \t"));
touch(pathList[index]);
}
}
void loop() {}