I implemented a function into my program for an attiny connected to a display called bpl (boot print line).
My goal was to pass simple F("flash strings") to it, like so:
bpl(F("[Boot sequence start]"));
It works fine and all but the String.h library chews up a kb of flash...
uint8_t lines = 0;
static void bpl(String str){
delay(300);
if(lines == 7){
display.clear();
lines = 0;
}
display.printFixed_oldStyle(0, 8 * (lines+1), str.c_str(), STYLE_NORMAL);
++lines;
}
//note: the display.printblahblah() function is from lexus2k
so I chose to try a different option;
static void bpl(const __FlashStringHelper* str){
delay(300);
if(lines == 7){
display.clear();
lines = 0;
}
memcpy_P(buf,str,22);
display.printFixed_oldStyle(0, 8 * (lines+1), buf, STYLE_NORMAL);
lines++;
}
This method saved a load of flash, but it only executed 2 of the bpls (marked with comments):
void setup() {
pinMode(1,INPUT);//ran
display.setFixedFont(ssd1306xled_font6x8); // ran
display.begin();//ran
display.clear();//didnt run
delay(100);//idk
bpl(F("[Boot sequence start]"));//ran
bpl(F("[PIN0 floating ]"));//ran
TinyWireM.begin();//idk
bpl(F("[Wire lib init ]"));//didnt run
}
What could be done to fix this? am I missing something or did I choose the wrong approach?
Thanks!
EDIT:
static void bpl(const __FlashStringHelper* fstr){
char buf[strlen_P((PGM_P)fstr)];
delay(300);
if(lines == 7){
display.clear();
lines = 0;
}
strcpy_P(buf,(PGM_P)fstr);
display.printFixed_oldStyle(0, 8 * (lines+1), buf, STYLE_NORMAL);
lines++;
}
fixed the issue...