├── src ├── ev.c ├── bmp1.c ├── light.c ├── main.c ├── touch.c ├── init_destory.c ├── polling.c ├── music.c ├── game.c ├── video.c ├── ui.c └── show_bmp.c ├── bin └── main.out ├── .vscode ├── settings.json └── c_cpp_properties.json ├── inc ├── bmp.h ├── ev.h ├── game.h ├── light.h ├── main.h └── show_bmp.h ├── .github └── workflows │ └── c-cpp.yml └── README.md /src/ev.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyk007/GEC6818/HEAD/src/ev.c -------------------------------------------------------------------------------- /src/bmp1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyk007/GEC6818/HEAD/src/bmp1.c -------------------------------------------------------------------------------- /src/light.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyk007/GEC6818/HEAD/src/light.c -------------------------------------------------------------------------------- /bin/main.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyk007/GEC6818/HEAD/bin/main.out -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "main.h": "c", 4 | "stdio.h": "c", 5 | "types.h": "c", 6 | "show_bmp.h": "c", 7 | "type_traits": "c", 8 | "string.h": "c" 9 | } 10 | } -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | int main(void) 4 | { 5 | //1.程序初始化 6 | project_init(); 7 | 8 | //2.程序主界面 9 | project_ui(); 10 | 11 | //3.程序销毁 12 | project_destroy(); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /inc/bmp.h: -------------------------------------------------------------------------------- 1 | #ifndef __BMP_H__ 2 | #define __BMP_H__ 3 | 4 | #include "light.h" 5 | #include 6 | #include "ev.h" 7 | 8 | void Dis_pan(); 9 | 10 | int Dis_pic(char *pic); 11 | 12 | 13 | //void Draw_Ck(int x0,int y0,int color); 14 | 15 | #endif -------------------------------------------------------------------------------- /inc/ev.h: -------------------------------------------------------------------------------- 1 | #ifndef __EV_H__ 2 | #define __EV_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | int Get_ev(int *x, int *y); 15 | 16 | 17 | #endif -------------------------------------------------------------------------------- /inc/game.h: -------------------------------------------------------------------------------- 1 | #ifndef __GAME_H__ 2 | #define __GAME_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | int Game_Change(); 15 | int Dis_zi(int x, int y, int flag); 16 | int Game_Over(); 17 | int clear(); 18 | 19 | 20 | 21 | 22 | 23 | #endif -------------------------------------------------------------------------------- /inc/light.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIGHT_H__ 2 | #define __LIGHT_H__ 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | int Display(int color, int x, int y); 14 | int Lcd_Init(); 15 | void Dis_wh(); 16 | void Dis_qu(); 17 | void Dis_cir(); 18 | void Dis_tri(); 19 | 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: configure 17 | run: ./configure 18 | - name: make 19 | run: make 20 | - name: make check 21 | run: make check 22 | - name: make distcheck 23 | run: make distcheck 24 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${default}", 7 | "${workspaceFolder}/include", 8 | "${workspaceFolder}/inc" 9 | ], 10 | "defines": [ 11 | "_DEBUG", 12 | "UNICODE", 13 | "_UNICODE" 14 | ], 15 | "cStandard": "c17", 16 | "cppStandard": "gnu++14", 17 | "intelliSenseMode": "windows-gcc-x64", 18 | "compilerPath": "D:/ProgramData/VisualStudioCode/mingw64/bin/g++.exe" 19 | } 20 | ], 21 | "version": 4 22 | } -------------------------------------------------------------------------------- /inc/main.h: -------------------------------------------------------------------------------- 1 | //#ifdef _MAIN_H_ 2 | 3 | #define _MAIN_H_ 4 | 5 | /*头文件*/ 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "show_bmp.h" 18 | #include"ev.h" 19 | #include"bmp.h" 20 | #include"game.h" 21 | #include"light.h" 22 | 23 | /*全局变量*/ 24 | #define PIXELS 800*480//屏幕像素点 25 | int fd_lcd;//LCD文件 26 | int fd_touch;//touch文件 27 | int* p_lcd;//LCD映射内存 28 | int posx, posy; //存放坐标 29 | int fd_fifo;//管道文件 30 | int x, y; 31 | /*结构体定义*/ 32 | struct input_event buf;//触摸屏结构体 33 | /*宏定义*/ 34 | 35 | /*联合体*/ 36 | 37 | /*枚举*/ 38 | 39 | /*函数声明*/ 40 | int project_init(void);//程序初始化 41 | int project_ui(void);//程序主界面 42 | int project_destroy(void);//程序销毁 43 | int project_touch(int*, int*);//触摸屏操作函数 44 | 45 | int Send_Cmd(char*);//写入管道文件 46 | //#endif -------------------------------------------------------------------------------- /src/touch.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | 4 | int project_touch(int *th_x, int *th_y) 5 | { 6 | //获取坐标 7 | /* 8 | 输入:屏幕点击 9 | 输出:点击的坐标(th_x, th_y) 10 | 返回:异常-1,点击0,向右移动1,向左移动2,向下移动3,向上移动4 11 | 注意:需要两个int指针存放坐标 12 | */ 13 | while(1) 14 | { 15 | int old_x, old_y; 16 | read(fd_touch, &buf, sizeof(buf)); 17 | 18 | if (buf.type == EV_ABS && buf.code == ABS_X) 19 | //*th_x = buf.value; 20 | *th_x = buf.value*800/1024; 21 | if (buf.type == EV_ABS && buf.code == ABS_Y) 22 | //*th_x = buf.value; 23 | *th_y = buf.value*480/600; 24 | //这是开发板驱动问题,开发板的屏幕像素是800*480,但驱动给的分辨率有误,驱动的分辨率是1024*600,所以需要乘相应的值 25 | //触控驱动正常的开发板无需乘这些值,即使用注释的代码,无需使用源代码 26 | if (buf.type == EV_KEY && buf.code == BTN_TOUCH && buf.value == 1) 27 | { 28 | old_x = *th_x; 29 | old_y = *th_y; 30 | 31 | } 32 | 33 | 34 | if (buf.type == EV_KEY && buf.code == BTN_TOUCH && buf.value == 0) 35 | { 36 | if (old_x < *th_x && (*th_x - old_x >= 50)) return 1;//向右移动 37 | if (old_x > *th_x && (old_x - *th_x >= 50)) return 2;//向左移动 38 | if (old_y < *th_y && (*th_y - old_y >= 50)) return 3;//向下移动 39 | if (old_y > *th_y && (old_y - *th_y >= 50)) return 4;//向上移动 40 | break ; 41 | } 42 | 43 | }//end while 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 使用说明书 2 | 3 | ## 硬件要求 4 | 5 | 粤嵌GEC6818开发板 6 | 7 | ## 编译命令 8 | 9 | linux终端输入: 10 | `arm-linux-gcc ./src/*.c -I ./inc -o ./main.out` 11 | 12 | ## 环境搭建 13 | 14 | 1. 使用arm-linux-gcc进行C语言代码编译 15 | 2. 使用VScode进行C语言代码编写 16 | 17 | ## 项目目录 18 | 19 | 1. bin文件夹:存放编译后的.out二进制文件 20 | 21 | 2. inc文件夹:存放引用的头文件 22 | 23 | 3. lib文件夹:存放引用的库文件 24 | 25 | 4. src文件夹:存放.c代码文件 26 | 27 | ## 素材文件 28 | 29 | 1. 图片文件 30 | 31 | 1. 开始界面 32 | `./picture/Photo_tip.bmp` 33 | 34 | 2. 菜单界面 35 | `./picture/background.bmp` 36 | 37 | 3. 电子相册 38 | `./picture/1.bmp` 39 | `./picture/2.bmp` 40 | `./picture/3.bmp` 41 | `./picture/4.bmp` 42 | `./picture/5.bmp` 43 | 44 | 4. 音乐播放界面 45 | `./picture/kjashdk.bmp` 46 | `./picture/music_play.bmp` 47 | `./picture/music_stop.bmp` 48 | 49 | 2. 音频文件 50 | `./music/Thisstreet.mp3` 51 | 52 | 3. 视频文件 53 | `./video/kungfu.avi` 54 | 55 | ## 功能操作 56 | 57 | #### 菜单操作 58 | 59 | 开机动画为提示界面,大约6秒后进入菜单。 60 | 61 | 选择屏幕下方四个按钮进入相应界面 62 | 63 | #### 音乐播放 64 | 65 | * 点击”||“暂停播放 66 | * 点击">"继续播放 67 | * 点击”返回菜单“退出音乐播放返回主界面 68 | * 点击”>>"快进 69 | * 点击“<<"快退 70 | * 点击”-“音量减 71 | * 点击”+“音量加 72 | 73 | #### 视频播放 74 | 75 | * 点击屏幕:暂停视频播放 76 | * 上滑:退出视频播放 77 | 78 | #### 电子相册 79 | 80 | * 下一张:向左滑动或点击屏幕右半边 81 | * 上一张:向右滑动或点击屏幕左半边 82 | * 退出:上滑 83 | 84 | #### 游戏 85 | 86 | 一个棋盘,下棋顺序先黑后白,可作为围棋和五子棋棋盘,功能未完善。 87 | 88 | 当一方获胜时,需要重启系统 89 | -------------------------------------------------------------------------------- /src/init_destory.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | //项目程序初始化 4 | int project_init(void) 5 | { 6 | //打开LCD文件 7 | fd_lcd = open("/dev/fb0", O_RDWR); 8 | if(fd_lcd == -1) return -1; 9 | 10 | //内存映射 11 | /*LCD屏幕映射到p_lcd*/ 12 | p_lcd = (int*)mmap(NULL, PIXELS*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd_lcd, 0);//不强转int*会出现段错误 13 | if(*p_lcd == -1) 14 | { 15 | perror("LCD mmap failed!\n"); 16 | return -1; 17 | } 18 | 19 | //打开触摸屏文件 20 | fd_touch = open("/dev/input/event0", O_RDONLY); 21 | if (fd_touch == -1) 22 | { 23 | perror("Open touch screen failed!\n"); 24 | return -1; 25 | } 26 | 27 | //创建管道文件 28 | if(access("/fifo",F_OK))// 默认管道文件创建在根目录 F_OK:判断是否存在 29 | { 30 | //如果没有创建 31 | mkfifo("/fifo",777); //创建管道文件函数 32 | 33 | } 34 | fd_fifo = open("/fifo",O_RDWR); 35 | if(fd_fifo == -1) 36 | { 37 | printf("创建管道文件失败!\n"); 38 | return -1; 39 | 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | //程序项目关闭 46 | int project_destroy(void) 47 | { 48 | int ret; 49 | //关闭LCD文件 50 | ret = close(fd_lcd); 51 | if(ret == -1) 52 | { 53 | perror("Close LCD failed!\n"); 54 | return -1; 55 | } 56 | 57 | //解除内存映射 58 | munmap(p_lcd, PIXELS*4);//lcd映射内存 59 | 60 | //关闭触摸屏文件 61 | ret = close(fd_touch); 62 | if(ret == -1) 63 | { 64 | perror("Close touch screen failed!\n"); 65 | return -1; 66 | } 67 | 68 | return 0; 69 | } -------------------------------------------------------------------------------- /src/polling.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | //幻灯片 4 | /* 5 | #输入:延时时间,单位秒 6 | #输出:幻灯片播放 7 | #返回:成功返回0,失败返回-1 8 | */ 9 | int Polling(int delay) 10 | { 11 | char* bmpname[5] = {"./picture/1.bmp", "./picture/2.bmp", "./picture/3.bmp", "./picture/4.bmp", "./picture/5.bmp"}; 12 | int bmpnum = 0; 13 | int choice; 14 | show_1152000bmp(bmpname[0], p_lcd); 15 | do{ 16 | //换图 17 | int nTouch = project_touch(&posx, &posy); 18 | if((nTouch == 0 && posx > 400) || nTouch == 2)//点击到了右边或左划 19 | choice = 1; 20 | 21 | else if((nTouch == 0 && posx < 400) || nTouch == 1)//点击到了左边或右划 22 | choice = 2; 23 | 24 | else if(nTouch == 4)//上划 25 | choice = 0; 26 | 27 | switch(choice) 28 | { 29 | case 0: 30 | printf("Exit!\n"); 31 | break; 32 | case 1: 33 | if(bmpnum == 4){ 34 | printf("This is the last picture!\n"); 35 | break; 36 | } 37 | bmpnum += 1; 38 | show_1152000bmp(bmpname[bmpnum], p_lcd); 39 | break; 40 | case 2: 41 | if(bmpnum == 0){ 42 | printf("This is the first picture!\n"); 43 | break; 44 | } 45 | bmpnum -= 1; 46 | show_1152000bmp(bmpname[bmpnum], p_lcd); 47 | break; 48 | default: 49 | printf("Error!\n"); 50 | break; 51 | } 52 | //end while 53 | }while(choice != 0); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/music.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | //音乐播放 4 | /* 5 | #输入:音乐文件路径 6 | #输出:音乐播放 7 | #返回:成功返回0,失败返回-1 8 | */ 9 | int MusicPlay(char musicpath[]) 10 | { 11 | show_1152000bmp("./picture/music_play.bmp", p_lcd); 12 | //打开音乐文件 13 | system("killall -9 mplayer"); 14 | char Music[255]; 15 | sprintf(Music, "mplayer %s &", musicpath); 16 | system(Music); 17 | int nTouch = project_touch(&posx, &posy); 18 | //操作视频 19 | int posx, posy; 20 | int choice; 21 | int MusicMode = 1; 22 | do{ 23 | 24 | int nTouch = project_touch(&posx, &posy); 25 | 26 | if(posx > 300 && posx < 490 && posy > 100 && posy < 300) choice = 1; //暂停或继续音乐 27 | else if(posx > 250 && posx < 540 && posy > 330 && posy < 430) choice = 0; //退出音乐 28 | else if(posx > 60 && posx < 160 && posy > 330 && posy < 430) choice = 2; //音量— 29 | else if(posx > 630 && posx < 730 && posy > 330 && posy < 430) choice = 3; //音量+ 30 | else if(posx > 0 && posx < 130 && posy > 100 && posy < 300) choice = 4; //快退 31 | else if(posx > 660 && posx < 800 && posy > 100 && posy < 300) choice = 5; //快进 32 | 33 | switch(choice) 34 | { 35 | case 0: 36 | system("killall -SIGKILL mplayer"); 37 | break; 38 | case 1: 39 | if(MusicMode == 1) 40 | { 41 | system("killall -SIGSTOP mplayer"); 42 | MusicMode = 0; 43 | show_1152000bmp("./picture/music_stop.bmp", p_lcd); 44 | } 45 | else 46 | { 47 | system("killall -SIGCONT mplayer"); 48 | MusicMode = 1; 49 | show_1152000bmp("./picture/music_play.bmp", p_lcd); 50 | } 51 | break; 52 | case 2: 53 | Send_Cmd("volume -10\n"); 54 | break; 55 | case 3: 56 | Send_Cmd("volume +10\n"); 57 | break; 58 | case 4: 59 | Send_Cmd("seek -10\n"); 60 | break; 61 | case 5: 62 | Send_Cmd("seek +10\n"); 63 | break; 64 | default: 65 | printf("Error!\n"); 66 | break; 67 | } 68 | 69 | }while(choice != 0); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /src/game.c: -------------------------------------------------------------------------------- 1 | #include "ev.h" 2 | #include "bmp.h" 3 | #include "game.h" 4 | 5 | int flag = 0; 6 | unsigned int Game_buf[12][20] = { 0 }; 7 | 8 | int Game_Change(int x, int y) 9 | { 10 | int i, j; 11 | i = x % 40; 12 | j = y % 40; 13 | if (i > 20) 14 | { 15 | i = x / 40 + 1; 16 | } 17 | else 18 | { 19 | i = x / 40; 20 | } 21 | if (j > 20) 22 | { 23 | j = y / 40 + 1; 24 | } 25 | else 26 | { 27 | j = y / 40; 28 | } 29 | x = i * 40; 30 | y = j * 40; 31 | if (Game_buf[j][i] == 0) 32 | { 33 | if (flag) 34 | { 35 | Game_buf[j][i] = 1; 36 | Dis_zi(y, x, flag); 37 | 38 | } 39 | else 40 | { 41 | Game_buf[j][i] = 2; 42 | Dis_zi(y, x, flag); 43 | } 44 | flag = ~flag; 45 | } 46 | 47 | 48 | } 49 | int clear() 50 | { 51 | for (int a = 0; a < 12; a++) 52 | { 53 | for (int b = 0; b < 20; b++) 54 | { 55 | Game_buf[a][b] = 0; 56 | 57 | } 58 | } 59 | } 60 | 61 | int Dis_zi(int x, int y, int flag) 62 | { 63 | int i, j; 64 | if (flag) 65 | { 66 | for (i = 0; i < 480; i++) 67 | { 68 | for (j = 0; j < 800; j++) 69 | { 70 | if ((i - x)*(i - x) + (j - y)*(j - y) <= 330) 71 | { 72 | Display(0x00, j, i); 73 | } 74 | } 75 | } 76 | } 77 | else 78 | { 79 | for (i = 0; i < 480; i++) 80 | { 81 | for (j = 0; j < 800; j++) 82 | { 83 | if ((i - x)*(i - x) + (j - y)*(j - y) <= 330) 84 | { 85 | Display(0x00ffffff, j, i); 86 | } 87 | } 88 | } 89 | } 90 | } 91 | 92 | int Game_Over() 93 | { 94 | int a, b, h = 1, s = 1, x = 1, j = 1; 95 | for (a = 0; a < 12; a++) 96 | { 97 | for (b = 0; b < 20; b++) 98 | { 99 | if (Game_buf[a][b] != 0) 100 | { 101 | 102 | while (h != 5) 103 | { 104 | if (Game_buf[a][b] == Game_buf[a + h][b]) 105 | h++; 106 | else 107 | break; 108 | } 109 | while (s != 5) 110 | { 111 | if (Game_buf[a][b] == Game_buf[a][b + s]) 112 | s++; 113 | else 114 | break; 115 | } 116 | while (x != 5) 117 | { 118 | if (Game_buf[a][b] == Game_buf[a + x][b + x]) 119 | x++; 120 | else 121 | break; 122 | } 123 | while (j != 5) 124 | { 125 | if (Game_buf[a][b] == Game_buf[a + j][b - j]) 126 | j++; 127 | else 128 | break; 129 | } 130 | if (h == 5 || s == 5 || x == 5 || j == 5) 131 | { 132 | Dis_pic("/game/bucuoo.bmp"); 133 | clear(); 134 | } 135 | } 136 | } 137 | } 138 | } -------------------------------------------------------------------------------- /src/video.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | int Send_Cmd(char *cmd)//写入管道文件 4 | { 5 | write(fd_fifo,cmd,strlen(cmd)); 6 | 7 | return 0; 8 | } 9 | 10 | 11 | //视频播放 12 | /* 13 | #输入:视频文件路径 14 | #输出:视频播放 15 | #返回:成功返回0,失败返回-1 16 | */ 17 | int VideoPlay_old(char videopath[], int width, int height) 18 | { 19 | show_1152000bmp("./picture/video_play.bmp", p_lcd); 20 | //打开视频文件 21 | system("killall -9 mplayer"); 22 | char Video[255]; 23 | sprintf(Video, "mplayer -slave -quiet -input file=/fifo -geometry 0:0 -zoom -x %d -y %d %s &", width, height, videopath); 24 | system(Video); 25 | //操作视频 26 | int posx, posy; 27 | int choice; 28 | int VideoMode = 1; 29 | do{ 30 | 31 | int nTouch = project_touch(&posx, &posy); 32 | 33 | if(nTouch == 0) choice = 1; //暂停或继续视频 34 | else if(nTouch == 4) choice = 2; //退出视频 35 | 36 | switch(choice) 37 | { 38 | case 0: 39 | system("killall -SIGKILL mplayer"); 40 | break; 41 | case 1: 42 | if(VideoMode == 1) 43 | { 44 | system("killall -SIGSTOP mplayer"); 45 | VideoMode = 0; 46 | } 47 | else 48 | { 49 | system("killall -SIGCONT mplayer"); 50 | VideoMode = 1; 51 | } 52 | break; 53 | default: 54 | printf("Error!\n"); 55 | break; 56 | } 57 | 58 | }while(choice != 0); 59 | 60 | return 0; 61 | } 62 | 63 | int VideoPlay(char videopath[]) 64 | { 65 | //show_1152000bmp("./picture/video_play.bmp", p_lcd); 66 | //打开视频文件 67 | system("killall -9 mplayer"); 68 | char Video[255]; 69 | sprintf(Video, "mplayer %s &", videopath); 70 | system(Video); 71 | //操作视频 72 | int posx, posy; 73 | int choice; 74 | int VideoMode = 1; 75 | do{ 76 | 77 | int nTouch = project_touch(&posx, &posy); 78 | 79 | if(nTouch == 0) choice = 1; //暂停或继续视频 80 | else if(nTouch == 4) choice = 0; //退出视频 81 | 82 | switch(choice) 83 | { 84 | case 0: 85 | system("killall -SIGKILL mplayer"); 86 | break; 87 | case 1: 88 | if(VideoMode == 1) 89 | { 90 | system("killall -SIGSTOP mplayer"); 91 | VideoMode = 0; 92 | } 93 | else 94 | { 95 | system("killall -SIGCONT mplayer"); 96 | VideoMode = 1; 97 | } 98 | break; 99 | default: 100 | printf("Error!\n"); 101 | break; 102 | } 103 | 104 | }while(choice != 0); 105 | 106 | return 0; 107 | } -------------------------------------------------------------------------------- /src/ui.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | //菜单选择 4 | /* 5 | #输入:无 6 | #输出:显示菜单以及选择的菜单项 7 | #返回值:选择的菜单项 0~4 8 | */ 9 | int ChoiceSelect(void) 10 | { 11 | int choices = 4; 12 | show_1152000bmp("./picture/background.bmp", p_lcd);//显示菜单 13 | 14 | 15 | //获取坐标 16 | int SlideMode = project_touch(&posx, &posy); 17 | printf("posx = %d, posy = %d\nSlideMode = %d\n", posx, posy, SlideMode); //test 18 | 19 | //返回choice 20 | // if(*posx > 240 && *posx < 480 && *posy > 0 && *posy > 800/choices) return 1; 21 | // else if(*posx > 240 && *posx < 480 && *posy > 800/choices && *posy > 800/choices*2) return 2; 22 | // else if(*posx > 240 && *posx < 480 && *posy > 800/choices*2 && *posy > 800/choices*3) return 3; 23 | // else if(*posx > 240 && *posx < 480 && *posy > 800/choices*3 && *posy > 800/choices*4) return 4; 24 | // else return 0; 25 | if(posx > 0 && posx < 800/4 && posy > 240 && posy < 480) return 1; 26 | else if(posx > 800/4 && posx < 800/4*2 && posy > 240 && posy < 480) return 2; 27 | else if(posx > 800/4*2 && posx < 800/4*3 && posy > 240 && posy < 480) return 3; 28 | else if(posx > 800/4*3 && posx < 800/4*4 && posy > 240 && posy < 480) return 4; 29 | else return 0; 30 | 31 | } 32 | 33 | //UI界面 34 | int project_ui(void) 35 | { 36 | /*函数声明*/ 37 | int Polling(int); 38 | int MusicPlay(char[]); 39 | int VideoPlay(char[], int, int); 40 | 41 | //1.开机提示 42 | printf("Welcome to my project!!\n"); 43 | printf("-------------------------\n"); 44 | printf("PICTURE: 1.picture polling\n2.music playing\n3.video playing\n"); 45 | show_1152000bmp("./picture/Photo_tip.bmp", p_lcd);//开机界面 46 | system("mplayer ./music/Thisstreet.mp3 &"); 47 | sleep(4); 48 | system("killall -9 mplayer"); 49 | sleep(3); 50 | show_1152000bmp("./picture/background.bmp", p_lcd);//显示菜单 51 | system("killall -9 mplayer");//防止复活 52 | 53 | //2.项目功能 54 | int choice; 55 | do{ 56 | //提示选择要进行的项目 57 | choice = ChoiceSelect(); 58 | printf("Menu load success!\n"); 59 | switch(choice) 60 | { 61 | //(0)退出 62 | case 0: 63 | printf("Exit!\n"); 64 | break; 65 | //(1)幻灯片播放 66 | case 1: 67 | Polling(3); 68 | break; 69 | //(2)音乐播放 70 | case 2: 71 | MusicPlay("./music/Thisstreet.mp3"); 72 | break; 73 | //(3)视频播放 74 | case 3: 75 | VideoPlay("./video/kungfu.avi", 800, 400); 76 | break; 77 | //(4)未知功能 78 | case 4: 79 | Lcd_Init(); 80 | Dis_pic("./picture/1.bmp");//封面图片 81 | Get_ev(&x, &y);//开始操作 82 | 83 | 84 | 85 | printf("What are you doing?\n"); 86 | break; 87 | //输入错误 88 | default: 89 | printf("You want to destory me??\n"); 90 | break; 91 | } 92 | }while(1); 93 | 94 | return 0; 95 | } -------------------------------------------------------------------------------- /inc/show_bmp.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************** 2 | *设 计:蒋亮 3 | *日 期:2018-8-26 4 | *说 明:头文件 5 | ****************************************************************************************/ 6 | #ifndef __SHOW_BMP_H__ 7 | #define __SHOW_BMP_H__ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | /* 19 | 图片特效: 20 | 1)“圆形扩散” 2)”圆形收缩“ 21 | 3)”向下飞入“ 4)”向上飞入“ 5)”向左飞入“ 6)”向右飞入“ 22 | 7)”横百叶窗“ 8)”竖百叶窗“ 9)“左右相合” 10)“中间展开” 23 | 11)“斜方块” 24 | */ 25 | 26 | /* 27 | 功能:显示800*480大小的bmp图片。 28 | 参数: 29 | char *pathname:要显示图片的名字。 30 | int *show_1152000bmp_fd:被映射区的指针。 31 | 返回值:成功 0 32 | 失败 -1 33 | */ 34 | int show_1152000bmp(char *pathname, int *show_1152000bmp_fd); 35 | 36 | /* 37 | 功能:(不超过800*480显示屏大小)显示任意位置任意大小的bmp图片 38 | 形参: 39 | char *pathname:要显示图片的名字 40 | int lcd_x_coordinates:lcd屏的x轴坐标 41 | int lcd_y_coordinates:lcd屏的y轴坐标(通过x、y轴坐标确定显示图片起始显示坐标) 42 | int wide:所显示图片的宽度 43 | int height:所显示图片的高度 44 | int *show_bmp_lcd_mmap:被映射区的指针 45 | 返回值:成功 0 46 | 失败 -1 47 | 48 | */ 49 | int show_location_bmp(char *pathname,int lcd_x_coordinates, int lcd_y_coordinates, int wide, int height,int *show_bmp_lcd_mmap); 50 | 51 | /* 52 | 功能:切换BMP图片特效“圆形扩散”。 53 | 参数: 54 | char *pathname:图片的路径。 55 | int *pic_circular_spread_fd:被映射区的指针。 56 | 返回值:成功 0 57 | 失败 -1 58 | */ 59 | int pic_circular_spread(char *pathname, int* pic_circular_spread_fd); 60 | 61 | /* 62 | 功能:切换BMP图片特效”圆形收缩“。 63 | 参数: 64 | char *pathname:图片的路径。 65 | int *pic_circular_shrink_fd:被映射区的指针。 66 | 返回值:成功 0 67 | 失败 -1 68 | */ 69 | int pic_circular_shrink(char *pathname, int* pic_circular_shrink_fd); 70 | 71 | /* 72 | 功能:切换BMP图片特效”向下飞入“。 73 | 参数: 74 | char *pathname:图片的路径。 75 | int *pic_down_fd:被映射区的指针。 76 | 返回值:成功 0 77 | 失败 -1 78 | */ 79 | int pic_down(char *pathname, int* pic_down_fd); 80 | 81 | /* 82 | 功能:切换BMP图片特效”向上飞入“。 83 | 参数: 84 | char *pathname:图片的路径。 85 | int *pic_up_fd:被映射区的指针。 86 | 返回值:成功 0 87 | 失败 -1 88 | */ 89 | int pic_up(char *pathname, int* pic_up_fd); 90 | 91 | /* 92 | 功能:切换BMP图片特效”向左飞入“。 93 | 参数: 94 | char *pathname:图片的路径。 95 | int *pic_left_fd:被映射区的指针。 96 | 返回值:成功 0 97 | 失败 -1 98 | */ 99 | int pic_left(char *pathname, int* pic_left_fd); 100 | 101 | /* 102 | 功能:切换BMP图片特效”向右飞入“。 103 | 参数: 104 | char *pathname:图片的路径。 105 | int *pic_right_fd:被映射区的指针。 106 | 返回值:成功 0 107 | 失败 -1 108 | */ 109 | int pic_right(char *pathname, int* pic_right_fd); 110 | 111 | /* 112 | 功能:切换BMP图片特效”横百叶窗“。 113 | 参数: 114 | char *pathname:图片的路径。 115 | int *pic_transverse_blinds_fd:被映射区的指针。 116 | 返回值:成功 0 117 | 失败 -1 118 | */ 119 | int pic_transverse_blinds(char *pathname, int* pic_transverse_blinds_fd); 120 | 121 | /* 122 | 功能:切换BMP图片特效”竖百叶窗“。 123 | 参数: 124 | char *pathname:图片的路径。 125 | int *pic_vertical_blinds_fd:被映射区的指针。 126 | 返回值:成功 0 127 | 失败 -1 128 | */ 129 | int pic_vertical_blinds(char *pathname, int* pic_vertical_blinds_fd); 130 | 131 | /* 132 | 功能:切换BMP图片特效“左右相合”。 133 | 参数: 134 | char *pathname:图片的路径。 135 | int *pic_left_right_coincidence_fd:被映射区的指针。 136 | 返回值:成功 0 137 | 失败 -1 138 | */ 139 | int pic_left_right_coincidence(char *pathname, int* pic_left_right_coincidence_fd); 140 | 141 | /* 142 | 功能:切换BMP图片特效“中间展开”。 143 | 参数: 144 | char *pathname:图片的路径。 145 | int *pic_mid_spread_fd:被映射区的指针。 146 | 返回值:成功 0 147 | 失败 -1 148 | */ 149 | int pic_mid_spread(char *pathname, int *pic_mid_spread_fd); 150 | 151 | /* 152 | 功能:切换BMP图片特效“斜方块”。 153 | 参数: 154 | char *pathname:图片的路径。 155 | int *pic_oblique_block_fd:被映射区的指针。 156 | 返回值:成功 0 157 | 失败 -1 158 | */ 159 | int pic_oblique_block(char *pathname, int *pic_oblique_block_fd); 160 | 161 | /* 162 | 功能:显示任意位置任意大小的lcd屏 163 | 参数: 164 | int color:要显示的颜色(RGB表示的十六进制) 165 | int lcd_x_coordinates:lcd屏幕的x轴坐标 166 | int lcd_y_coordinates:lcd屏幕的y轴坐标(通过x、y轴坐标确定起始显示颜色的坐标) 167 | int wide:所显示颜色的宽度 168 | int height:所显示颜色的高度(通过wide、height确定所显示颜色的面积) 169 | int *lcd_mmap:被映射区的指针 170 | 返回值:成功 0 171 | 失败 -1 172 | */ 173 | int clear_lcd_screen(int color, int lcd_x_coordinates, int lcd_y_coordinates, int wide, int height,int *lcd_mmap); 174 | 175 | #endif -------------------------------------------------------------------------------- /src/show_bmp.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************************** 2 | *设 计:蒋亮 3 | *日 期:2018-8-26 4 | *说 明:常用函数 5 | ****************************************************************************************/ 6 | #include "show_bmp.h" 7 | #include"main.h" 8 | 9 | /* 10 | 图片特效: 11 | 1)“圆形扩散” 2)”圆形收缩“ 12 | 3)”向下飞入“ 4)”向上飞入“ 5)”向左飞入“ 6)”向右飞入“ 13 | 7)”横百叶窗“ 8)”竖百叶窗“ 9)“左右相合” 10)“中间展开” 14 | 11)“斜方块” 15 | */ 16 | 17 | /* 18 | 功能:显示800*480大小的bmp图片。 19 | 参数: 20 | char *pathname:要显示图片的名字。 21 | int *show_1152000bmp_fd:被映射区的指针。 22 | 返回值:成功 0 23 | 失败 -1 24 | */ 25 | int show_1152000bmp(char *pathname, int *show_1152000bmp_fd) 26 | { 27 | //1、打开BMP格式图片和lcd显示屏 28 | int fd_bmp = open(pathname, O_RDWR); 29 | if(fd_bmp == -1) 30 | { 31 | perror("show_1152000bmp(), open bmp fail!\n"); 32 | return -1; 33 | } 34 | 35 | //2、去掉54个字节 36 | int ret = lseek(fd_bmp, 54, SEEK_SET); 37 | if(ret == -1) 38 | { 39 | printf("show_1152000bmp(), lseek bmp fail!\n"); 40 | return -1; 41 | } 42 | 43 | //3、读取BMP数据到lcd屏幕中 44 | char bmp_buf[800*480*3]; 45 | int lcd_buf[800*480]; 46 | bzero(bmp_buf, 800*480*3); 47 | bzero(lcd_buf, 800*480); 48 | 49 | ret = read(fd_bmp, bmp_buf, 800*480*3);//BMP数据放到了bmp_buf中 50 | if(ret == -1) 51 | { 52 | printf("show_1152000bmp(), read bmp fail!\n"); 53 | return -1; 54 | } 55 | 56 | //4、关闭文件,回收资源 57 | close(fd_bmp); 58 | 59 | //5、800*480个A像素变成800*480个B像素算法。 60 | int i; 61 | for(i=0; i<800*480; i++) 62 | { 63 | lcd_buf[i] = bmp_buf[i*3]<<0 | bmp_buf[i*3+1]<<8 | bmp_buf[i*3+2]<<16; 64 | //lcd_buf[0] = bmp_buf[0]<<0 | bmp_buf[1]<<8 | bmp_buf[2]<<16; 65 | //lcd_buf[1] = bmp_buf[3]<<0 | bmp_buf[4]<<8 | bmp_buf[5]<<16; 66 | //lcd_buf[2] = bmp_buf[6]<<0 | bmp_buf[7]<<8 | bmp_buf[8]<<16; 67 | } 68 | 69 | //6、lcd_buf数据(DDR2中的数据)通过mmap显示到LCD屏幕中。 70 | /* 71 | for(i=0; i<800*480; i++) 72 | { 73 | *(lcd_mmap+i)=lcd_buf[i]; 74 | } 75 | */ 76 | int x, y; 77 | for(y=0; y<480; y++)//优化算法,解决图片颠倒问题 78 | { 79 | for(x=0; x<800; x++) 80 | { 81 | *(show_1152000bmp_fd+800*(479-y)+x)= lcd_buf[800*y+x]; 82 | } 83 | } 84 | 85 | return 0; 86 | } 87 | 88 | /* 89 | 功能:(不超过800*480显示屏大小)显示任意位置任意大小的bmp图片 90 | 形参: 91 | char *pathname:要显示图片的名字 92 | int lcd_x_coordinates:lcd屏的x轴坐标 93 | int lcd_y_coordinates:lcd屏的y轴坐标(通过x、y轴坐标确定显示图片起始显示坐标) 94 | int wide:所显示图片的宽度 95 | int height:所显示图片的高度 96 | int *show_bmp_lcd_mmap:被映射区的指针 97 | 返回值:成功 0 98 | 失败 -1 99 | 100 | */ 101 | int show_location_bmp(char *pathname,int lcd_x_coordinates, int lcd_y_coordinates, int wide, int height,int *show_bmp_lcd_mmap) 102 | { 103 | int i; 104 | int ret; 105 | int x, y; 106 | 107 | char bmp_buf[wide*height*3]; 108 | int new_buf[wide*height]; 109 | bzero(bmp_buf, sizeof(bmp_buf)); 110 | bzero(new_buf, sizeof(new_buf)); 111 | 112 | int bmp_fd = open(pathname, O_RDONLY);//1、打开BMP格式图片 113 | if(bmp_fd == -1) 114 | { 115 | printf("show_location_bmp(), open bmp failed\n"); 116 | return -1; 117 | } 118 | 119 | ret = lseek(bmp_fd,54,SEEK_SET);//2、跳过bmp图片的前54个位置 120 | if(ret == -1) 121 | { 122 | printf("show_location_bmp(), lseek bmp failed\n"); 123 | return -1; 124 | } 125 | 126 | int *new_p = show_bmp_lcd_mmap + 800*lcd_y_coordinates + lcd_x_coordinates;//3、重新确定映射位置。 127 | 128 | ret = read(bmp_fd, bmp_buf, wide*height*3);//4、取读图片像素 129 | if(ret == -1) 130 | { 131 | printf("show_location_bmp(), read bmp failed\n"); 132 | return -1; 133 | } 134 | 135 | close(bmp_fd);//5、关闭图片 136 | 137 | for(i=0; i=0; k-=3) 286 | { 287 | for(i=0; i<480; i++) 288 | { 289 | for(j=0; j<800; j++) 290 | { 291 | if((j-400)*(j-400)+(i-240)*(i-240) >= k*k) 292 | pic_circular_shrink_fd[800*i+j] = mi_buf[800*i+j]; 293 | } 294 | } 295 | } 296 | 297 | return 0; 298 | } 299 | 300 | /* 301 | 功能:切换BMP图片特效”向下飞入“。 302 | 参数: 303 | char *pathname:图片的路径。 304 | int *pic_down_fd:被映射区的指针。 305 | 返回值:成功 0 306 | 失败 -1 307 | */ 308 | int pic_down(char *pathname, int* pic_down_fd) 309 | { 310 | int ret=0; 311 | int line=0; 312 | int block=0; 313 | int i=0, j=0, k=0; 314 | int bmp_fd=0; 315 | 316 | char bmp_buf[480*800*3]; 317 | int mi_buf[480*800]; 318 | int temp_buf[480*800]; 319 | bzero(mi_buf,sizeof(mi_buf)); 320 | bzero(bmp_buf,sizeof(bmp_buf)); 321 | bzero(temp_buf,sizeof(temp_buf)); 322 | 323 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 324 | if(bmp_fd == -1) 325 | { 326 | printf("pic_down(), open bmp failed\n"); 327 | return -1; 328 | } 329 | 330 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 331 | if(ret == -1) 332 | { 333 | perror("pic_down(), lseek bmp failed\n"); 334 | return -1; 335 | } 336 | 337 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 338 | if(ret == -1) 339 | { 340 | printf("pic_down(), read bmp failed\n"); 341 | return -1; 342 | } 343 | 344 | close(bmp_fd);//5、关闭图片 345 | 346 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 347 | { 348 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 349 | } 350 | 351 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 352 | { 353 | for(i=0; i<=800 ; i++) 354 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 355 | } 356 | 357 | //8、特殊动画“向下飞入”效果算法 358 | for(i=0; i<480; i++) 359 | { 360 | for(j=0; j<800; j++) 361 | { 362 | pic_down_fd[800*i+j] = mi_buf[800*i+j]; 363 | } 364 | usleep(1000); 365 | } 366 | 367 | return 0; 368 | } 369 | 370 | /* 371 | 功能:切换BMP图片特效”向上飞入“。 372 | 参数: 373 | char *pathname:图片的路径。 374 | int *pic_up_fd:被映射区的指针。 375 | 返回值:成功 0 376 | 失败 -1 377 | */ 378 | int pic_up(char *pathname, int* pic_up_fd) 379 | { 380 | int ret=0; 381 | int line=0; 382 | int block=0; 383 | int i=0, j=0, k=0; 384 | int bmp_fd=0; 385 | 386 | char bmp_buf[480*800*3]; 387 | int mi_buf[480*800]; 388 | int temp_buf[480*800]; 389 | bzero(mi_buf,sizeof(mi_buf)); 390 | bzero(bmp_buf,sizeof(bmp_buf)); 391 | bzero(temp_buf,sizeof(temp_buf)); 392 | 393 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 394 | if(bmp_fd == -1) 395 | { 396 | printf("pic_up(), open bmp failed\n"); 397 | return -1; 398 | } 399 | 400 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 401 | if(ret == -1) 402 | { 403 | perror("pic_up(), lseek bmp failed\n"); 404 | return -1; 405 | } 406 | 407 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 408 | if(ret == -1) 409 | { 410 | printf("pic_up(), read bmp failed\n"); 411 | return -1; 412 | } 413 | 414 | close(bmp_fd);//5、关闭图片 415 | 416 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 417 | { 418 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 419 | } 420 | 421 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 422 | { 423 | for(i=0; i<=800 ; i++) 424 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 425 | } 426 | 427 | //8、特殊动画“向上飞入”效果算法 428 | for(i=479; i>=0; i--) 429 | { 430 | for(j=0; j<800; j++) 431 | { 432 | pic_up_fd[800*i+j] = mi_buf[800*i+j]; 433 | } 434 | usleep(500); 435 | } 436 | 437 | return 0; 438 | } 439 | 440 | /* 441 | 功能:切换BMP图片特效”向左飞入“。 442 | 参数: 443 | char *pathname:图片的路径。 444 | int *pic_left_fd:被映射区的指针。 445 | 返回值:成功 0 446 | 失败 -1 447 | */ 448 | int pic_left(char *pathname, int* pic_left_fd) 449 | { 450 | int ret=0; 451 | int line=0; 452 | int block=0; 453 | int i=0, j=0, k=0; 454 | int bmp_fd=0; 455 | 456 | char bmp_buf[480*800*3]; 457 | int mi_buf[480*800]; 458 | int temp_buf[480*800]; 459 | bzero(mi_buf,sizeof(mi_buf)); 460 | bzero(bmp_buf,sizeof(bmp_buf)); 461 | bzero(temp_buf,sizeof(temp_buf)); 462 | 463 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 464 | if(bmp_fd == -1) 465 | { 466 | printf("pic_left(), open bmp failed\n"); 467 | return -1; 468 | } 469 | 470 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 471 | if(ret == -1) 472 | { 473 | perror("pic_left(), lseek bmp failed\n"); 474 | return -1; 475 | } 476 | 477 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 478 | if(ret == -1) 479 | { 480 | printf("pic_left(), read bmp failed\n"); 481 | return -1; 482 | } 483 | 484 | close(bmp_fd);//5、关闭图片 485 | 486 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 487 | { 488 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 489 | } 490 | 491 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 492 | { 493 | for(i=0; i<=800 ; i++) 494 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 495 | } 496 | 497 | //8、特殊动画“向左飞入”效果算法 498 | for(j=799; j>=0; j--) 499 | { 500 | for(i=0; i<480; i++) 501 | { 502 | pic_left_fd[800*i+j] = mi_buf[800*i+j]; 503 | } 504 | usleep(500); 505 | } 506 | 507 | return 0; 508 | } 509 | 510 | /* 511 | 功能:切换BMP图片特效”向右飞入“。 512 | 参数: 513 | char *pathname:图片的路径。 514 | int *pic_right_fd:被映射区的指针。 515 | 返回值:成功 0 516 | 失败 -1 517 | */ 518 | int pic_right(char *pathname, int* pic_right_fd) 519 | { 520 | int ret=0; 521 | int line=0; 522 | int block=0; 523 | int i=0, j=0, k=0; 524 | int bmp_fd=0; 525 | 526 | char bmp_buf[480*800*3]; 527 | int mi_buf[480*800]; 528 | int temp_buf[480*800]; 529 | bzero(mi_buf,sizeof(mi_buf)); 530 | bzero(bmp_buf,sizeof(bmp_buf)); 531 | bzero(temp_buf,sizeof(temp_buf)); 532 | 533 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 534 | if(bmp_fd == -1) 535 | { 536 | printf("pic_right(), open bmp failed\n"); 537 | return -1; 538 | } 539 | 540 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 541 | if(ret == -1) 542 | { 543 | perror("pic_right(), lseek bmp failed\n"); 544 | return -1; 545 | } 546 | 547 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 548 | if(ret == -1) 549 | { 550 | printf("pic_right(), read bmp failed\n"); 551 | return -1; 552 | } 553 | 554 | close(bmp_fd);//5、关闭图片 555 | 556 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 557 | { 558 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 559 | } 560 | 561 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 562 | { 563 | for(i=0; i<=800 ; i++) 564 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 565 | } 566 | 567 | //8、特殊动画“向右飞入”效果算法 568 | for(j=0; j<800; j++) 569 | { 570 | for(i=0; i<480; i++) 571 | { 572 | pic_right_fd[800*i+j] = mi_buf[800*i+j]; 573 | } 574 | usleep(500); 575 | } 576 | 577 | return 0; 578 | } 579 | 580 | /* 581 | 功能:切换BMP图片特效”横百叶窗“。 582 | 参数: 583 | char *pathname:图片的路径。 584 | int *pic_transverse_blinds_fd:被映射区的指针。 585 | 返回值:成功 0 586 | 失败 -1 587 | */ 588 | int pic_transverse_blinds(char *pathname, int* pic_transverse_blinds_fd) 589 | { 590 | int ret=0; 591 | int line=0; 592 | int block=0; 593 | int i=0, j=0, k=0; 594 | int bmp_fd=0; 595 | 596 | char bmp_buf[480*800*3]; 597 | int mi_buf[480*800]; 598 | int temp_buf[480*800]; 599 | bzero(mi_buf,sizeof(mi_buf)); 600 | bzero(bmp_buf,sizeof(bmp_buf)); 601 | bzero(temp_buf,sizeof(temp_buf)); 602 | 603 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 604 | if(bmp_fd == -1) 605 | { 606 | printf("pic_transverse_blinds(), open bmp failed\n"); 607 | return -1; 608 | } 609 | 610 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 611 | if(ret == -1) 612 | { 613 | perror("pic_transverse_blinds(), lseek bmp failed\n"); 614 | return -1; 615 | } 616 | 617 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 618 | if(ret == -1) 619 | { 620 | printf("pic_transverse_blinds(), read bmp failed\n"); 621 | return -1; 622 | } 623 | 624 | close(bmp_fd);//5、关闭图片 625 | 626 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 627 | { 628 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 629 | } 630 | 631 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 632 | { 633 | for(i=0; i<=800 ; i++) 634 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 635 | } 636 | 637 | //8、特殊动画“横百叶窗”效果算法 638 | for(j=0; j<800/8; j++) 639 | { 640 | for(i=0; i<480; i++) 641 | { 642 | for(k=0; k<8; k++) 643 | { 644 | pic_transverse_blinds_fd[800*i+j+k*800/8] = mi_buf[800*i+j+k*800/8]; 645 | } 646 | } 647 | usleep(500); 648 | } 649 | 650 | return 0; 651 | } 652 | 653 | /* 654 | 功能:切换BMP图片特效”竖百叶窗“。 655 | 参数: 656 | char *pathname:图片的路径。 657 | int *pic_vertical_blinds_fd:被映射区的指针。 658 | 返回值:成功 0 659 | 失败 -1 660 | */ 661 | int pic_vertical_blinds(char *pathname, int* pic_vertical_blinds_fd) 662 | { 663 | int ret=0; 664 | int line=0; 665 | int block=0; 666 | int i=0, j=0, k=0; 667 | int bmp_fd=0; 668 | 669 | char bmp_buf[480*800*3]; 670 | int mi_buf[480*800]; 671 | int temp_buf[480*800]; 672 | bzero(mi_buf,sizeof(mi_buf)); 673 | bzero(bmp_buf,sizeof(bmp_buf)); 674 | bzero(temp_buf,sizeof(temp_buf)); 675 | 676 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 677 | if(bmp_fd == -1) 678 | { 679 | printf("pic_vertical_blinds(), open bmp failed\n"); 680 | return -1; 681 | } 682 | 683 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 684 | if(ret == -1) 685 | { 686 | perror("pic_vertical_blinds(), lseek bmp failed\n"); 687 | return -1; 688 | } 689 | 690 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 691 | if(ret == -1) 692 | { 693 | printf("pic_vertical_blinds(), read bmp failed\n"); 694 | return -1; 695 | } 696 | 697 | close(bmp_fd);//5、关闭图片 698 | 699 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 700 | { 701 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 702 | } 703 | 704 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 705 | { 706 | for(i=0; i<=800 ; i++) 707 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 708 | } 709 | 710 | //8、特殊动画竖百叶窗”效果算法 711 | for(i=0; i<480/8; i++) 712 | { 713 | for(j=0; j<800; j++) 714 | { 715 | for(k=0; k<8; k++) 716 | { 717 | pic_vertical_blinds_fd[800*(i+k*480/8)+j] = mi_buf[800*(i+k*480/8)+j]; 718 | } 719 | } 720 | usleep(500); 721 | } 722 | 723 | return 0; 724 | } 725 | 726 | /* 727 | 功能:切换BMP图片特效“左右相合”。 728 | 参数: 729 | char *pathname:图片的路径。 730 | int *pic_left_right_coincidence_fd:被映射区的指针。 731 | 返回值:成功 0 732 | 失败 -1 733 | */ 734 | int pic_left_right_coincidence(char *pathname, int* pic_left_right_coincidence_fd) 735 | { 736 | int ret=0; 737 | int line=0; 738 | int block=0; 739 | int i=0, j=0; 740 | int bmp_fd=0; 741 | 742 | char bmp_buf[480*800*3]; 743 | int mi_buf[480*800]; 744 | int temp_buf[480*800]; 745 | bzero(mi_buf,sizeof(mi_buf)); 746 | bzero(bmp_buf,sizeof(bmp_buf)); 747 | bzero(temp_buf,sizeof(temp_buf)); 748 | 749 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 750 | if(bmp_fd == -1) 751 | { 752 | printf("pic_left_right_coincidence(), open bmp failed\n"); 753 | return -1; 754 | } 755 | 756 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 757 | if(ret == -1) 758 | { 759 | perror("pic_left_right_coincidence(), lseek bmp failed\n"); 760 | return -1; 761 | } 762 | 763 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 764 | if(ret == -1) 765 | { 766 | printf("pic_left_right_coincidence(), read bmp failed\n"); 767 | return -1; 768 | } 769 | 770 | close(bmp_fd);//5、关闭图片 771 | 772 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 773 | { 774 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 775 | } 776 | 777 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 778 | { 779 | for(i=0; i<=800 ; i++) 780 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 781 | } 782 | 783 | for(block=0;block<10;block++)//8、特殊动画“左右相合”效果算法 784 | { 785 | for(i=40*block;i<(block+1)*40;i++)//刷左部分矩形 786 | { 787 | for(j=0;j<480;j++) 788 | pic_left_right_coincidence_fd[j*800+i]=mi_buf[j*800+i]; 789 | } 790 | for(line=799-block*40;line>799-(block+1)*40;line--) //刷右部分矩形 791 | { 792 | for(j=0;j<480;j++) 793 | pic_left_right_coincidence_fd[j*800+line]=mi_buf[j*800+line]; 794 | } 795 | usleep(100000); 796 | } 797 | 798 | return 0; 799 | } 800 | 801 | /* 802 | 功能:切换BMP图片特效“中间展开”。 803 | 参数: 804 | char *pathname:图片的路径。 805 | int *pic_mid_spread_fd:被映射区的指针。 806 | 返回值:成功 0 807 | 失败 -1 808 | */ 809 | int pic_mid_spread(char *pathname, int *pic_mid_spread_fd) 810 | { 811 | int ret=0; 812 | int line=0; 813 | int block=0; 814 | int i=0, j=0; 815 | int bmp_fd=0; 816 | 817 | char bmp_buf[480*800*3]; 818 | int mi_buf[480*800]; 819 | int temp_buf[480*800]; 820 | bzero(mi_buf,sizeof(mi_buf)); 821 | bzero(bmp_buf,sizeof(bmp_buf)); 822 | bzero(temp_buf,sizeof(temp_buf)); 823 | 824 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 825 | if(bmp_fd == -1) 826 | { 827 | printf("pic_mid_spread(), open bmp failed\n"); 828 | return -1; 829 | } 830 | 831 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 832 | if(ret == -1) 833 | { 834 | perror("pic_mid_spread(), lseek bmp failed\n"); 835 | return -1; 836 | } 837 | 838 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 839 | if(ret == -1) 840 | { 841 | printf("pic_mid_spread(), read bmp failed\n"); 842 | return -1; 843 | } 844 | 845 | close(bmp_fd);//5、关闭图片 846 | 847 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 848 | { 849 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 850 | } 851 | 852 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 853 | { 854 | for(i=0; i<=800 ; i++) 855 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 856 | } 857 | 858 | //8、特殊动画“中间展开”效果算法 859 | for(i=0; i<800/2; i++) 860 | { 861 | for(j=0; j<480; j++) 862 | { 863 | pic_mid_spread_fd[800/2+800*j+i] = mi_buf[800/2+800*j+i]; 864 | pic_mid_spread_fd[800/2+800*j-i] = mi_buf[800/2+800*j-i]; 865 | } 866 | usleep(500); 867 | } 868 | 869 | return 0; 870 | } 871 | 872 | /* 873 | 功能:切换BMP图片特效“斜方块”。 874 | 参数: 875 | char *pathname:图片的路径。 876 | int *pic_oblique_block_fd:被映射区的指针。 877 | 返回值:成功 0 878 | 失败 -1 879 | */ 880 | int pic_oblique_block(char *pathname, int *pic_oblique_block_fd) 881 | { 882 | int ret=0; 883 | int line=0; 884 | int block=0; 885 | int i=0, j=0, k=0; 886 | int m=0, n=0; 887 | int bmp_fd=0; 888 | 889 | char bmp_buf[480*800*3]; 890 | int mi_buf[480*800]; 891 | int temp_buf[480*800]; 892 | bzero(mi_buf,sizeof(mi_buf)); 893 | bzero(bmp_buf,sizeof(bmp_buf)); 894 | bzero(temp_buf,sizeof(temp_buf)); 895 | 896 | bmp_fd = open(pathname , O_RDONLY);//1、打开BMP格式图片 897 | if(bmp_fd == -1) 898 | { 899 | printf("pic_oblique_block(), open bmp failed\n"); 900 | return -1; 901 | } 902 | 903 | ret = lseek(bmp_fd, 54 , SEEK_SET);//2、跳过bmp图片的前54个位置 904 | if(ret == -1) 905 | { 906 | perror("pic_oblique_block(), lseek bmp failed\n"); 907 | return -1; 908 | } 909 | 910 | ret = read(bmp_fd , bmp_buf , sizeof(bmp_buf)); //4、取读图片像素 911 | if(ret == -1) 912 | { 913 | printf("pic_oblique_block(), read bmp failed\n"); 914 | return -1; 915 | } 916 | 917 | close(bmp_fd);//5、关闭图片 918 | 919 | for(i=0, j=0 ; i<800*480 ; i++, j+=3)//6、24bits 转 32bits控制变量 920 | { 921 | temp_buf[i] = bmp_buf[j+2]<<16 | bmp_buf[j+1]<<8 | bmp_buf[j] ; 922 | } 923 | 924 | for(line=0 ; line <=480 ;line++)//7、解决图片上下颠倒问题 925 | { 926 | for(i=0; i<=800 ; i++) 927 | mi_buf[800*line + i] = temp_buf[ (479-line)*800 + i ]; 928 | } 929 | 930 | //8、特殊动画“斜方块”效果算法 931 | for(k=0; k<=14; k++) 932 | { 933 | for(i=0; i<8; i++) 934 | { 935 | for(j=0; j<8; j++) 936 | { 937 | if(i+j <= k) 938 | { 939 | for(m=100*i; m<100*(i+1); m++) 940 | { 941 | for(n=60*j; n<60*(j+1); n++) 942 | { 943 | pic_oblique_block_fd[n*800+m] = mi_buf[n*800+m]; 944 | } 945 | } 946 | usleep(200); 947 | } 948 | } 949 | } 950 | } 951 | 952 | return 0; 953 | } 954 | 955 | /* 956 | 功能:显示任意位置任意大小的lcd屏 957 | 参数: 958 | int color:要显示的颜色(RGB表示的十六进制) 959 | int lcd_x_coordinates:lcd屏幕的x轴坐标 960 | int lcd_y_coordinates:lcd屏幕的y轴坐标(通过x、y轴坐标确定起始显示颜色的坐标) 961 | int wide:所显示颜色的宽度 962 | int height:所显示颜色的高度(通过wide、height确定所显示颜色的面积) 963 | int *lcd_mmap:被映射区的指针 964 | 返回值:成功 0 965 | 失败 -1 966 | */ 967 | int clear_lcd_screen(int color, int lcd_x_coordinates, int lcd_y_coordinates, int wide, int height,int *lcd_mmap) 968 | { 969 | int x, y; 970 | int *new_p = lcd_mmap + 800*lcd_y_coordinates + lcd_x_coordinates; 971 | for(y=0; y