I want to use PROGMEM with a transform array.
PROGMEM and TRANSFORM array work as expected when implemented individually.
But PROGMEM with TRANSFORM array implemented together does not have the expected output.
The following example sketch was compiled 4 ways, here are the 4 outputs:
#define WITH_PROGMEM, output is as expected.
#define WITH_TRANSFORM, output is as expected.
#define WITH_PROGMEM_TRANSFORM1, output is blank, was expecting "ba".
#define WITH_PROGMEM_TRANSFORM2, output is blank, was expecting "ba".
Example sketch:
How to use PROGMEM with a transform array?
I am running Teensy2 on Arduino IDE 1.6.5 with C++11 and Teensyduino 1.25 on Linux.
Thank you.
PROGMEM and TRANSFORM array work as expected when implemented individually.
But PROGMEM with TRANSFORM array implemented together does not have the expected output.
The following example sketch was compiled 4 ways, here are the 4 outputs:
#define WITH_PROGMEM, output is as expected.
Code:
output: ab
#define WITH_TRANSFORM, output is as expected.
Code:
output: ba
#define WITH_PROGMEM_TRANSFORM1, output is blank, was expecting "ba".
Code:
output:
#define WITH_PROGMEM_TRANSFORM2, output is blank, was expecting "ba".
Code:
output:
Example sketch:
Code:
//uncomment exactly one #define and compile
//#define WITH_PROGMEM
//#define WITH_TRANSFORM
#define WITH_PROGMEM_TRANSFORM1
//#define WITH_PROGMEM_TRANSFORM2
const char A = 'a';
const char B = 'b';
#ifdef WITH_PROGMEM //output: ab
const PROGMEM char * const layout[] = {&A, &B};
const char* getPtrChar(uint8_t i)
{
return (char*) pgm_read_ptr(&layout[i]);
}
#endif
#ifdef WITH_TRANSFORM //output: ba
const char * const layout[] = {&A, &B};
const char * const transform[] = { layout[1], layout[0] };
const char* getPtrChar(uint8_t i)
{
return transform[i];
}
#endif
#ifdef WITH_PROGMEM_TRANSFORM1 //output:
const char * const layout[] = {&A, &B};
const PROGMEM char * const transform[] = { layout[1], layout[0] };
const char* getPtrChar(uint8_t i)
{
return (char*) pgm_read_ptr(&transform[i]);
}
#endif
#ifdef WITH_PROGMEM_TRANSFORM2 //output:
const PROGMEM char * const layout[] = {&A, &B};
const char * const transform[] = { layout[1], layout[0] };
const char* getPtrChar(uint8_t i)
{
return (char*) pgm_read_ptr(&(transform[i]));
}
#endif
void setup()
{
Keyboard.begin();
delay(1000);
Keyboard.print(F("output: "));
const char* ptrChar;
ptrChar = getPtrChar(0);
Keyboard.print(*ptrChar);
ptrChar = getPtrChar(1);
Keyboard.print(*ptrChar);
}
void loop() {}
I am running Teensy2 on Arduino IDE 1.6.5 with C++11 and Teensyduino 1.25 on Linux.
Thank you.
Last edited: