C++ Arduino-如何返回正确的位图图像数组
我有三个数组,如下所示,其中包含位图图像:C++ Arduino-如何返回正确的位图图像数组,c++,arduino,C++,Arduino,我有三个数组,如下所示,其中包含位图图像: 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,
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, };
现在我需要一个函数,通过传递page参数返回正确的数组以显示在lcd上
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;
调用者是一个简单的函数,用于绘制正确的图像。不同页面的图像可能不同。页数接近20页:
void drawLogo(){
glcd.drawbitmap(15,1, logo(), 90,16); //display lcd library for ST7565
}
此代码存在一些问题:
char*
buffer[i]=pgm_read_byte(…)
缓冲区
在堆栈上分配,并且在函数返回后将不存在strlcpy\p
更新:1.假设您有固定数量的页面。尝试在每页创建位图,如:
static unsigned char __attribute__ ((progmem)) impostazioni_logo_page1[]={..}
二,。返回指向每个页面徽标的指针:unsigned char* logo(int page)
{
switch(page)
{
case 1:
return impostazioni_logo_page1;
break;
}
return NULL;
}
如果希望将所有位图放在一个数组中,请计算数组中的偏移量并返回:
int offset = page_num*page_size_in_chars;
return &impostazioni_logo_all_pages[offset];
更新2:管理页面的另一个选项:
static unsigned char* pages[] = { impostazioni_logo_page1, impostazioni_logo_page2, ... }
...
glcd.drawbitmap(15,1, pages[page_index], 90,16);
谢谢那么,你能给我一个简单正确的代码吗?发布调用unsigned char logo(int page)函数的代码,我来看看我能做什么…我刚刚编辑了我的问题,所以你可以看到simply caller函数
static unsigned char* pages[] = { impostazioni_logo_page1, impostazioni_logo_page2, ... }
...
glcd.drawbitmap(15,1, pages[page_index], 90,16);