#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include<linux/input.h>
#define IMG1 "1.bmp"
#define IMG2 "2.bmp"
int main(){
int fd = open("/dev/input/event0",O_RDWR);
struct input_event myevent;
int flag =0;
display(IMG1);
read(fd,&myevent,sizeof(myevent));
int i =0;
if(myevent.type==EV_ABS){
// if(flag){
// display(IMG1);
// printf("change BMP%d\n",i++);
// }
// else{
// !flag;
for (; i<=200; i++){
display_1(IMG2,i);
}
// display_1(IMG2);
// display(IMG2);
printf("change BMP%d\n",i++);
// }
}
close(fd);
return 0;
}
int display(const char *pathname){
//打开lcd
int fd_lcd;
fd_lcd = open("/dev/fb0", O_RDWR);
if(fd_lcd < 0){
printf("open lcd fail\n");
return -1;
}
//映射
int *addr;
addr = mmap(NULL, 800*480*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd_lcd, 0);
if (addr == NULL){
printf("mmap fail\n");
return -1;
}
//读取图片
int fd_bmp;
fd_bmp = open(pathname, O_RDWR);
if(fd_bmp <0){
printf("open bmp fail\n");
return -1;
}
//-去掉头字节
off_t offset = lseek(fd_bmp, 54, SEEK_SET);
if (offset == -1)
{
printf("Offset failed!\n");
return -1;
}
//读取图片数据
char buf_r[800*480*3],buf[800*480*3];
size_t re_ret = read(fd_bmp, buf, 800*480*3);
if (re_ret == -1)
{
printf("Read BMP failed!\n");
return -1;
}
int x, y;
int i = 0;
// for(y = 0; y < 480; y++)
// {
// for(x = 0; x < 800; x++)
// {
// buf[y*800+x] = buf_r[(479-y)*800+x];
// }
// }
for(y =0; y<480;y++){
for(x=0; x<800;x++){
*(addr+(479-y)*800+x) =
buf[3*(y*800+x)]|
buf[3*(y*800+x)+1]<<8|
buf[3*(y*800+x)+2]<<16;
}
}
// for (i=0; i<480*800; i++)
// {
// *(addr+i) =
// buf[i*3+2]<<16 |
// buf[i*3+1]<<8 |
// buf[i*3+0]<<0;
// }
close(fd_bmp);
close(fd_lcd);
return 0;
}
int display_1(const char *pathname, int i){
//打开lcd
int fd_lcd;
fd_lcd = open("/dev/fb0", O_RDWR);
if(fd_lcd < 0){
printf("open lcd fail\n");
return -1;
}
//映射
int *addr;
addr = mmap(NULL, 800*480*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd_lcd, 0);
if (addr == NULL){
printf("mmap fail\n");
return -1;
}
//读取图片
int fd_bmp;
fd_bmp = open(pathname, O_RDWR);
if(fd_bmp <0){
printf("open bmp fail\n");
return -1;
}
//-去掉头字节
off_t offset = lseek(fd_bmp, 54, SEEK_SET);
if (offset == -1)
{
printf("Offset failed!\n");
return -1;
}
//读取图片数据
char buf_r[800*480*3],buf[800*480*3];
size_t re_ret = read(fd_bmp, buf, 800*480*3);
if (re_ret == -1)
{
printf("Read BMP failed!\n");
return -1;
}
int x, y;
// for(y = 0; y < 480; y++)
// {
// for(x = 0; x < 800; x++)
// {
// buf[y*800+x] = buf_r[(479-y)*800+x];
// }
// }
for(y =0; y<480;y++){
for(x=0; x<i+1;x++){
*(addr+(479-y)*800+x) =
buf[3*(y*800+x)]|
buf[3*(y*800+x)+1]<<8|
buf[3*(y*800+x)+2]<<16;
}
for(x=200; x<i+201;x++){
*(addr+(479-y)*800+x) =
buf[3*(y*800+x)]|
buf[3*(y*800+x)+1]<<8|
buf[3*(y*800+x)+2]<<16;
}
for(x=400; x<i+401;x++){
*(addr+(479-y)*800+x) =
buf[3*(y*800+x)]|
buf[3*(y*800+x)+1]<<8|
buf[3*(y*800+x)+2]<<16;
}
for(x=600; x<i+601;x++){
*(addr+(479-y)*800+x) =
buf[3*(y*800+x)]|
buf[3*(y*800+x)+1]<<8|
buf[3*(y*800+x)+2]<<16;
}
}
// for (i=0; i<480*800; i++)
// {
// *(addr+i) =
// buf[i*3+2]<<16 |
// buf[i*3+1]<<8 |
// buf[i*3+0]<<0;
// }
close(fd_bmp);
close(fd_lcd);
return 0;
}
10-15
2149
