Reputation: 804
I have three array, like this, that contains my bitmap images:
static unsigned char __attribute__ ((progmem)) impostazioni_logo[]={
0x00, 0x02, 0x7E, 0x02, 0x00, 0x00, 0x78, 0x10, 0x08, 0x08, 0x08, 0x70, 0x10, 0x08, 0x08, 0x08,
0x70, 0x00, 0x00, 0x78, 0x10, 0x08, 0x08, 0x08, 0x10, 0x60, 0x00, 0x00, 0x60, 0x10, 0x08, 0x08,
0x08, 0x10, 0x60, 0x00, 0x00, 0x30, 0x48, 0x48, 0x08, 0x08, 0x10, 0x00, 0x00, 0x08, 0x7E, 0x08,
0x08, 0x08, 0x00, 0x00, 0x50, 0x48, 0x48, 0x48, 0x70, 0x00, 0x00, 0x08, 0x08, 0x08, 0x48, 0x28,
0x18, 0x00, 0x00, 0x7A, 0x00, 0x00, 0x60, 0x10, 0x08, 0x08, 0x08, 0x10, 0x60, 0x00, 0x00, 0x78,
0x10, 0x08, 0x08, 0x08, 0x08, 0x70, 0x00, 0x00, 0x7A, 0x00, 0x00, 0x08, 0x0F, 0x08, 0x00, 0x00,
0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x7F, 0x08, 0x08,
0x08, 0x08, 0x04, 0x03, 0x00, 0x00, 0x03, 0x04, 0x08, 0x08, 0x08, 0x04, 0x03, 0x00, 0x00, 0x04,
0x08, 0x08, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x07, 0x08, 0x08, 0x08, 0x00, 0x07, 0x08, 0x08,
0x08, 0x04, 0x0F, 0x00, 0x00, 0x0C, 0x0A, 0x09, 0x08, 0x08, 0x08, 0x00, 0x00, 0x0F, 0x00, 0x00,
0x03, 0x04, 0x08, 0x08, 0x08, 0x04, 0x03, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F,
0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
Now i want a function return the correct array to display on lcd by passing the page parameter.
unsigned char logo(int page){
char buffer[32];
switch(page){
case 1:
for(int i=0;i<sizeof(impostazioni_logo);i++){
strcpy_P(buffer,pgm_read_byte(&(impostazioni_logo[i]))); //<==pgm_read_byte comes from here:http://www.arduino.cc/en/Reference/PROGMEM
}
break;
}
return buffer;
} it doesn't work. Compiler tell me something wrong about conversion.
EDIT:
caller is a simply function that draw the right image. Images can be different for different pages. Number of pages are near 20:
void drawLogo(){
glcd.drawbitmap(15,1, logo(), 90,16); //display lcd library for ST7565
}
Upvotes: 0
Views: 1890
Reputation: 710
There are a few issues with this code:
logo
is unsigned char
while you are returning char *
buffer[i]=pgm_read_byte(...)
buffer
that you are trying to return is allocated on the stack and will not exist after function returns.You should probably be using strlcpy_P
instead.
Update:
1. Assuming you have a fixed number of pages. Try creating a bitmap per page, like:
static unsigned char __attribute__ ((progmem)) impostazioni_logo_page1[]={..}
2. return a pointer to each pages' logo:
unsigned char* logo(int page)
{
switch(page)
{
case 1:
return impostazioni_logo_page1;
break;
}
return NULL;
}
If you like to have all bitmaps in a single array, calculate an offset in the array and return that instead:
int offset = page_num*page_size_in_chars;
return &impostazioni_logo_all_pages[offset];
Update 2: Another option to manage pages:
static unsigned char* pages[] = { impostazioni_logo_page1, impostazioni_logo_page2, ... }
...
glcd.drawbitmap(15,1, pages[page_index], 90,16);
Upvotes: 1