0

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

}
0

1 Answer 1

1

There are a few issues with this code:

  1. return type for logo is unsigned char while you are returning char *
  2. pgm_read_byte supposedly returns a byte, so you could simply do buffer[i]=pgm_read_byte(...)
  3. 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);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks. so can u, please, give me a simple correct code to do that?
Post the code that is calling the unsigned char logo(int page) function and I'll see what I can do...
i just edited my question so you can see the simply caller function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.