diff --git a/Linux-VTS/PO/1.bmp b/Linux-VTS/PO/1.bmp new file mode 100644 index 0000000..f3bbb68 Binary files /dev/null and b/Linux-VTS/PO/1.bmp differ diff --git a/Linux-VTS/PO/2.bmp b/Linux-VTS/PO/2.bmp new file mode 100644 index 0000000..a9c374d Binary files /dev/null and b/Linux-VTS/PO/2.bmp differ diff --git a/Linux-VTS/PO/3.bmp b/Linux-VTS/PO/3.bmp new file mode 100644 index 0000000..76ff736 Binary files /dev/null and b/Linux-VTS/PO/3.bmp differ diff --git a/Linux-VTS/PO/4.bmp b/Linux-VTS/PO/4.bmp new file mode 100644 index 0000000..deb5ffc Binary files /dev/null and b/Linux-VTS/PO/4.bmp differ diff --git a/Linux-VTS/PO/main b/Linux-VTS/PO/main new file mode 100644 index 0000000..72b31d3 Binary files /dev/null and b/Linux-VTS/PO/main differ diff --git a/Linux-VTS/PO/q.c b/Linux-VTS/PO/q.c new file mode 100644 index 0000000..ff6355a --- /dev/null +++ b/Linux-VTS/PO/q.c @@ -0,0 +1,108 @@ +#include +//open lseek +#include +#include +#include +//close write read lseek +#include +//mmap +#include + +//函数声明 +//图片显示,全屏显示 +int bmp_show(char *pic_path,int x,int y,int w,int h); + +int main(int argc, char const *argv[]) +{ + // 分别显示四张小图 + bmp_show("./1.bmp",200,100,200,120); + bmp_show("./2.bmp",350,100,200,120); + bmp_show("./3.bmp",200,200,200,120); + bmp_show("./4.bmp",350,200,200,120); + + return 0; +} + +//图片显示,全屏显示 +int bmp_show(char *pic_path,int x,int y,int w,int h) +{ + // 1.打开LCD屏幕(设备文件:"/dev/fb0") + int lcd_fd=open("/dev/fb0",O_RDWR); + if(lcd_fd == -1) + { + perror("打开LCD屏失败"); + return -1; + } + else + { + printf("打开LCD屏成功\n"); + } + + //映射内存 + unsigned *FB = mmap(NULL,4*800*480,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_fd,0); + + //映射新的显存 + unsigned *new_FB = FB + (x+y*800); + + // 2.打开BMP文件 + int bmp_fd = open(pic_path,O_RDWR); + if (bmp_fd == -1) + { + perror("打开图片失败"); + return -1; + } + else + { + printf("打开图片成功\n"); + } + + + // 3.读取BMP中的RGB的数据 + //将图片文件头和信息头读完(54个字节) + unsigned char bmp_info[54]={0}; + read(bmp_fd,bmp_info,sizeof(bmp_info)); + //读取BMP中的RGB数据 + unsigned char bmp_buf[w*h*3]; + read(bmp_fd,bmp_buf,sizeof(bmp_buf)); + + // 4.将aRGB颜色写入到LCD屏中 + //将3字节RGB数据转换为4字节aRGB数据 + unsigned int lcd_buf[w*h]; + for(int i = 0;i +//open lseek +#include +#include +#include +//close write read lseek +#include +//mmap +#include +//输入子系统头文件 +#include + +//函数申明 +//打开触摸屏设备文件 +void ts_open(); +//打开模拟器LCD屏设备文件 +void lcd_open(); +//关闭触摸屏设备文件 +void ts_close(); +//关闭模拟器LCD屏设备文件 +void lcd_close(); +//获取坐标 +void get_xy(int *x,int *y); +//图片显示,显示某个大小某一个位置某张图片 +int bmp_show(char *pic_path,int x,int y,int w,int h); +//功能一:相册 +void photo(); + +//全局变量 +int ts_fd; +int lcd_fd; +unsigned *FB; +int pos_x,pos_y; + +int main(int argc, char const *argv[]) +{ + /****************一、打开设备文件*******************/ + ts_open(); + lcd_open(); + /****************二、程序逻辑代码*******************/ + bmp_show("./main.bmp",0,0,800,480); + while (1) + { + get_xy(&pos_x,&pos_y); + if(pos_x > 84 && pos_x < 296 && pos_y > 213 && pos_y < 424) //坐标 68 278 218 428 + { + printf("进入相册功能\n"); + photo(); + } + // printf("(%d,%d)\n",pos_x,pos_y); + } + /****************三、关闭设备文件*******************/ + ts_close(); + lcd_close(); + + return 0; +} + +//打开触摸屏设备文件 +void ts_open() +{ + // 1.打开模拟器的触摸屏设备文件("/dev/ubuntu_event") + ts_fd = open("/dev/ubuntu_event",O_RDWR); + if(ts_fd == -1) + { + perror("打开模拟器的触摸屏设备文件失败"); + } +} + +//打开模拟器LCD屏设备文件 +void lcd_open() +{ + // 1.打开LCD屏幕(设备文件:"/dev/fb0") + lcd_fd=open("/dev/ubuntu_lcd",O_RDWR); + if(lcd_fd == -1) + { + perror("打开LCD屏失败"); + } + + + //映射内存 + FB = mmap(NULL,4*800*480,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_fd,0); +} + +//关闭触摸屏设备文件 +void ts_close() +{ + // 3.关闭模拟器的触摸屏设备文件 + close(ts_fd); +} + +//关闭模拟器LCD屏设备文件 +void lcd_close() +{ + //解除映射 + munmap(FB,4*800*480); + + // 6.关闭LCD设备文件的文件描述符 + close(lcd_fd); +} + + +//获取坐标 +void get_xy(int *x,int *y) +{ + // 2.读取坐标信息,存储在信息结构体中 + struct input_event ts_buf; + int x_read = 0; + int y_read = 0; + + while (1) + { + //产生堵塞,获取x,y的值 + read(ts_fd,&ts_buf,sizeof(ts_buf)); + if(ts_buf.type == EV_ABS && ts_buf.code == ABS_X) + { + *x = ts_buf.value; + x_read = 1; + } + else if (ts_buf.type == EV_ABS && ts_buf.code == ABS_Y && y_read == 0) + { + *y = ts_buf.value; + y_read = 1; + } + else if(x_read == 1 && y_read == 1) + { + break; + } + } +} + +//图片显示,显示某个大小某一个位置某张图片 +int bmp_show(char *pic_path,int x,int y,int w,int h) +{ + + //映射新的显存 + unsigned *new_FB = FB + (x+y*800); + + // 2.打开BMP文件 + int bmp_fd = open(pic_path,O_RDWR); + if (bmp_fd == -1) + { + perror("打开图片失败"); + return -1; + } + + // 3.读取BMP中的RGB的数据 + //将图片文件头和信息头读完(54个字节) + unsigned char bmp_info[54]={0}; + read(bmp_fd,bmp_info,sizeof(bmp_info)); + //读取BMP中的RGB数据 + unsigned char bmp_buf[w*h*3]; + read(bmp_fd,bmp_buf,sizeof(bmp_buf)); + + // 4.将aRGB颜色写入到LCD屏中 + //将3字节RGB数据转换为4字节aRGB数据 + unsigned int lcd_buf[w*h]; + for(int i = 0;i 0 && pos_x < 80 && pos_y > 0 && pos_y < 480) + { + printf("显示上一张图片\n"); + i--; + if(i < 0) + { + i=2; + } + bmp_show(pic[i],80,0,640,480); + } + else if(pos_x > 720 && pos_x < 800 && pos_y > 0 && pos_y < 480) + { + printf("显示下一张图片\n"); + i++; + if(i>2) + { + i=0; + } + bmp_show(pic[i],80,0,640,480); + } + else if(pos_x > 300 && pos_x < 510 && pos_y > 165 && pos_y < 365) + { + printf("返回主界面\n"); + bmp_show("./main.bmp",0,0,800,480); + break; + } + } +}