基于粤嵌gec6818开发板嵌入式开发电子相册,音乐播放,视频播放,2048游戏
一、功能与要求
实现功能:本系统需要使用粤嵌的GEC-6818开发板设计一款娱乐影音系统,其中包括图片显示(相册)、音乐播放、视频播放,游戏四个部分,在每个部分内部,具有操控各个部分的功能触摸按键。本系统还应具有蓝牙远程操控功能。
具体要求:对使用者具有良好的可视交互体验,可自由切换各个模块。在图片模块里面,能够点击左右两侧来切换上一张和下一张图片,退出相册显示主屏幕;在音乐模块里面,能够点击屏幕进行播放/暂停/退出;在视频模块中,点击屏幕进行播放/暂停/快进/快退/音量加/音量减/退出。所有模块还应具有退出至菜单的功能。这些交互除了需要通过触摸屏幕完成,也还应通过蓝牙进行远程操作。
演示视频
【基于粤嵌gec6818开发板嵌入式开发电子相册,音乐播放,视频播放,2048游戏】
(二)软件设计
电子相册功能程序如下:
- 准备图片素材:1.bmp,2.bmp,3.bmp,img1.bmp。
- 头文件、设置变量和定义函数,关键代码如下:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/input.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>//打开触摸屏设备文件
void open_ts();
//关闭触摸屏设备文件
void close_ts();
//获取坐标
void get_xy(int *x,int *y);
//打开LCD设备文件
void open_lcd();
//关闭LCD设备文件
void close_lcd();
//显示某张大小的图片某个位置
int show_bmp(char *pic_path,int x,int y,int w,int h);
//相册
void photo();
//音乐
void music();
//视频
void video();
void guan();
//蓝牙控制照片
void photo1();
//蓝牙控制音频
void music1();
//蓝牙控制视频
void video1();
//全局变量
int ts_fd;
int lcd_fd;
unsigned *FB;
int pos_x,pos_y;int fd_fifo;
- 获取坐标,读取坐标信息,存储到信息结构体,产生阻塞,等待用户触摸屏幕,关键代码如下:
//获取坐标
void get_xy(int *x,int *y)
{//读取坐标信息,存储到信息结构体struct input_event ts_buf;int x_read = 0;int y_read = 0;int pre = -1;while (1){//产生阻塞,等待用户触摸屏幕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 = ts_buf.value;y_read = 1;} else if(ts_buf.type == EV_KEY && ts_buf.code == BTN_TOUCH) {pre = ts_buf.value;}if (x_read == 1 && y_read == 1 && pre == 0 ){*x = *x*800/1024;*y = *y*480/600;break;} }
}
- 完成show_bmp函数,实现显示某张大小的图片某个位置,关键代码如下:
//显示某张大小的图片某个位置
int show_bmp(char *pic_path,int x,int y,int w,int h)
{//映射新的显存unsigned *new_FB = FB + (x+y*800);//打开BMP图片文件int bmp_fd = open(pic_path,O_RDWR);//读取BMP中RGB数据//先将BMP图片的文件头14个字节和信息头40个字节读取到bmp_infounsigned char bmp_info[54]={0};read(bmp_fd,bmp_info,sizeof(bmp_info));unsigned char bmp_buf[3*w*h];read(bmp_fd,bmp_buf,sizeof(bmp_buf));unsigned int lcd_buf[w*h];for(int i = 0; i<w*h; i++){lcd_buf[i] = bmp_buf[i*3] << 0 | bmp_buf[i*3+1] << 8 | bmp_buf[i*3+2] << 16 | 0x00 << 24;}//图片上下颠倒int n,m;unsigned int lcd_buf1[w*h];for (m = 0; m < h; m++){for(n = 0; n < w; n++){lcd_buf1[n+m*w] = lcd_buf[n+(h-1-m)*w];}}//将aRGB写入到LCD屏中for (m = 0; m < h; m++){for(n = 0; n < w; n++){*(new_FB+n+m*800) = lcd_buf1[n+m*w];}}close(bmp_fd);
}
5. 完成Photo1()函数,实现蓝牙控制电子相册功能,实现相册展示,关键代码如下:
//蓝牙控制相册
void photo1(){// 1.访问串口3int fd = open("/dev/ttySAC3", O_RDWR | O_NOCTTY);// 2.配置串口3参数init_tty(fd);char buf[10] = {0};int ret;int current_photo = 1; // 记录当前显示的照片编号,初始值为1。char bmp_path[20]; //字符串数组,用于存储照片的路径int switch_x = 700; // 切换按钮的右边x 坐标int switch_y = 200; // 切换按钮的右边 y 坐标int switch_width = 100; // 切换按钮的宽度int switch_height = 50; // 切换按钮的高度int left_switch_x = 0; // 左边切换按钮的左边 x 坐标int left_switch_y = 200; // 左边切换按钮的右边 y 坐标int left_switch_width = 100; // 左边切换按钮的宽度int left_switch_height = 50; // 左边切换按钮的高度while (1){//使用当前照片编号动态构建照片路径,并将结果存储在bmp_path字符串中sprintf(bmp_path, "./%d.bmp", current_photo); //调用一个名为show_bmp的函数,显示指定路径的照片在屏幕上。show_bmp(bmp_path, 0, 0, 800, 480); // 读数据ret = read(fd, buf, 10);if (ret == -1){perror("read error");return -1;}// 对比if (0 == strcmp(buf, "on")){printf("下一张图片\n");current_photo++; if (current_photo > 3) {current_photo = 1;}}else if (0 == strcmp(buf, "off")){printf("退出相册\n");show_bmp("./img1.bmp", 0, 0, 800, 480);break;}else if (0 == strcmp(buf, "back")){current_photo--; if (current_photo < 1){current_photo = 3;}}write(fd, buf, strlen(buf));// 清空bufbzero(buf, 10);}
}
音频播放功能代码如下:
- 准备音乐素材:jay.mp3,yy.mp3
- 头文字,设置变量、定义函数。
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/input.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>//打开触摸屏设备文件
void open_ts();
//关闭触摸屏设备文件
void close_ts();
//获取坐标
void get_xy(int *x,int *y);
//打开LCD设备文件
void open_lcd();
//关闭LCD设备文件
void close_lcd();
//显示某张大小的图片某个位置
int show_bmp(char *pic_path,int x,int y,int w,int h);
//相册
void photo();
//音乐
void music();
//视频
void video();
void guan();
//蓝牙控制照片
void photo1();
//蓝牙控制音频
void music1();
//蓝牙控制视频
void video1();
//全局变量
int ts_fd;
int lcd_fd;
unsigned *FB;
int pos_x,pos_y;
int fd_fifo;
- 音频模块
//音频
void music(){int current_track = 0; int switch_x = 700; int switch_y = 200; int switch_width = 100; int switch_height = 50; int left_switch_x = 0; int left_switch_y = 200; int left_switch_width = 100; int left_switch_height = 50; const char* mu[] = {"jay.mp3","yy.mp3",};char command[50];sprintf(command, "madplay %s &", mu[current_track]);while(1){get_xy(&pos_x, &pos_y);system("madplay jay.mp3 &");if (pos_x > 700 && pos_x < 800 && pos_y > 0 && pos_y < 50){printf("退出音乐\n");show_bmp("./img1.bmp", 0, 0, 800, 480);break;}if (pos_x > switch_x && pos_x < switch_x + switch_width && pos_y > switch_y && pos_y < switch_y + switch_height){printf("下一首\n");current_track++;if (current_track > 2) {current_track = 0; }}if (pos_x > left_switch_x && pos_x < left_switch_x + left_switch_width && pos_y > left_switch_y && pos_y < left_switch_y + left_switch_height){printf("上一首\n");current_track--;if (current_track < 0) {current_track = 2; }}if (pos_x > 95 && pos_x < 245 && pos_y > 255 && pos_y < 405){printf("暂停\n");system("killall -19 madplay"); }if (pos_x > 500 && pos_x < 600 && pos_y > 255 && pos_y < 405){printf("继续\n");system("killall -18 madplay"); }if (pos_x > 700 && pos_x < 800 && pos_y > 400 && pos_y < 480){printf("终止\n");system("killall -9 madplay"); } }
}
- 蓝牙控制音频
//蓝牙控制音乐
void music1(){// 1.访问串口3int fd = open("/dev/ttySAC3", O_RDWR | O_NOCTTY);// 2.配置串口3参数init_tty(fd);char buf[10] = {0};int ret;
show_bmp("./music.bmp", 0, 0, 800, 480); int current_track = 0; // 当前播放的音频文件索引int switch_x = 700; // 切换按钮的右边x 坐标int switch_y = 200; // 切换按钮的右边 y 坐标int switch_width = 100; // 切换按钮的宽度int switch_height = 50; // 切换按钮的高度int left_switch_x = 0; // 左边切换按钮的左边 x 坐标int left_switch_y = 200; // 左边切换按钮的右边 y 坐标int left_switch_width = 100; // 左边切换按钮的宽度int left_switch_height = 50; // 左边切换按钮的高度// 音频文件列表const char* mu[] = {"jay.mp3","yy.mp3"};// 拼接当前音频文件的路径char command[50];sprintf(command, "madplay %s &", mu[current_track]);system("madplay jay.mp3 &"); // 后台播放while (1){// 读数据ret = read(fd, buf, 10);if (ret == -1){perror("read error");return -1;}// 对比if (0 == strcmp(buf, "1")){printf("退出音乐\n");show_bmp("./img1.bmp", 0, 0, 800, 480);break;}else if (0 == strcmp(buf, "2")){printf("下一首\n");current_track++;if (current_track > 2) {current_track = 0; // 切换到第一首音频文件}}else if (0 == strcmp(buf, "3")){printf("上一首\n");current_track--;if (current_track < 0) {current_track = 2; // 切换到最后一首音频文件}}else if (0 == strcmp(buf, "4")){printf("上一首\n");current_track--;if (current_track < 0) {current_track = 2; // 切换到最后一首音频文件}}else if (0 == strcmp(buf, "5")){printf("暂停\n");system("killall -19 madplay"); // 暂停音乐播放}else if (0 == strcmp(buf, "6")){printf("继续\n");system("killall -18 madplay"); // 继续音乐播放}else if (0 == strcmp(buf, "7")){printf("终止\n");system("killall -9 madplay"); // 继续音乐播放}write(fd, buf, strlen(buf));// 清空bufbzero(buf, 10);}
}
5.视频部分核心代码如下:
int init_tty(int fd)
{struct termios old_flags, new_flags;// 清空new_flagsbzero(&new_flags, sizeof(new_flags));// 1. 获取旧的属性tcgetattr(fd, &old_flags);// 2. 设置原始模式cfmakeraw(&new_flags);// 3. 激活本地连接CLOCAL与接收使能CREAD的选项new_flags.c_cflag |= CLOCAL | CREAD;// 4. 设置波特率cfsetispeed(&new_flags, B9600);cfsetospeed(&new_flags, B9600);// 5. 设置数据位位8位// 清空原有的数据位new_flags.c_cflag &= ~CSIZE;new_flags.c_cflag |= CS8;// 6. 设置奇偶校验位new_flags.c_cflag &= ~PARENB;// 7. 设置一位停止位new_flags.c_cflag &= ~CSTOPB;// 8. 设置等待时间,最少接收字符个数new_flags.c_cc[VTIME] = 0;new_flags.c_cc[VMIN] = 1;// 9. 清空串口缓冲区tcflush(fd, TCIFLUSH);// 10. 设置串口的属性到文件中tcsetattr(fd, TCSANOW, &new_flags);return 0;
}
//蓝牙控制视频
void video1(){system("mplayer -slave -quiet -input file=/fifo -geometry 0:0 -zoom -x 800 -y 400 1.mp4 &");sleep(1);// 1.访问串口3int fd = open("/dev/ttySAC3", O_RDWR | O_NOCTTY);// 2.配置串口3参数init_tty(fd);char buf[10] = {0};int ret;system("mplayer -slave -quiet -input file=/fifo -geometry 0:0 -zoom -x 800 -y 400 1.mp4 &");sleep(1);while (1){// 读数据ret = read(fd, buf, 10);if (ret == -1){perror("read error");return -1;}// 对比if (0 == strcmp(buf, "1")){printf("暂停 继续!\n");Send_Cmd("pause\n");}else if (0 == strcmp(buf, "2")){printf("音量+\n");Send_Cmd("volume +10\n");}else if (0 == strcmp(buf, "3")){printf("音量-\n");Send_Cmd("volume -10\n");}else if (0 == strcmp(buf, "4")){printf("快进!\n");Send_Cmd("seek +10\n");}else if (0 == strcmp(buf, "5")){printf("快退!\n");Send_Cmd("seek -10\n");}else if (0 == strcmp(buf, "6")){system("killall -9 mplayer");printf("退出视频\n");show_bmp("./img1.bmp",0,0,800,480);break;}write(fd, buf, strlen(buf));// 清空bufbzero(buf, 10);}
}
//视频
void video()
{system("mplayer -slave -quiet -input file=/fifo -geometry 0:0 -zoom -x 800 -y 400 1.mp4 &");sleep(1);//show_bmp("13.bmp",0,0,800,480);while(1){get_xy(&pos_x, &pos_y);//判断坐标位置if(pos_x>241 && pos_x<440 && pos_y>400 && pos_y<480){printf("暂停 继续!\n");Send_Cmd("pause\n");}if(pos_x>0 && pos_x<120 && pos_y>400 && pos_y<480){printf("音量+\n");Send_Cmd("volume +10\n");}if(pos_x>121 && pos_x<240 && pos_y>400 && pos_y<480){printf("音量-\n");Send_Cmd("volume -10\n");}if(pos_x>441 && pos_x<560 && pos_y>400 && pos_y<480){printf("快进!\n");Send_Cmd("seek +10\n");}if(pos_x>561 && pos_x<680 && pos_y>400 && pos_y<480){printf("快退!\n");Send_Cmd("seek -10\n");}if(pos_x>681 && pos_x<799 && pos_y>400 && pos_y<480){system("killall -9 mplayer");break;} }
}void guan(){if(access("/fifo",F_OK))// 默认管道文件创建在根目录 F_OK:判断是否存在{//如果没有创建mkfifo("/fifo",777); //创建管道文件函数}fd_fifo = open("/fifo",O_RDWR);if(fd_fifo == -1){printf("创建管道文件失败!\n");return -1;}
}int Send_Cmd(char *cmd)//写入管道文件
{write(fd_fifo,cmd,strlen(cmd));return 0;
}
三 实物展示
需要源码和答辩PPT的私信我
基于粤嵌gec6818开发板嵌入式开发电子相册,音乐播放,视频播放,2048游戏相关推荐
- linux-ARM开发板--嵌入式开发平台-选型
最近有一个项目以前一直在用工控机实现,现在需要优化功能.缩减成本,故有寻找linux-ARM开发板的需求:后期有很大可能还会自己会画PCB板.内核裁剪等设计的需求: 1.根据需求,限定了选型开发的基本 ...
- [6818开发板]八核开发板|4G开发板|GPS开发板|嵌入式开发平台
IMX6开发板(基本型):960元 IMX6开发板(豪华型):1460元 S5P4418 核心板可以无缝支持核心系统S5P6818,并保持底板设计不变,将兼顾更高端 的应用领域,为项目和产品提供更好的 ...
- ubuntu下S5PV210开发板嵌入式开发环境搭建
本教程所使用的开发板是GEC210开发板,核心板资源概述:CPU:S5PV210,SDRAM:512MB,Flash:8MB,NandFlash:256MB. 本教程搭建的环境可以用于uboot移植. ...
- 基于粤嵌gec6818开发板嵌入式电子相册,智能家居,音乐播放,灯光控制,2048游戏
需要完整项目源码和答辩PPT可以私信我! 展示项目内容:
- 硬件开发板-嵌入式开发
一.Raspberry Pi 4(树莓派) Raspberry Pi,是一款基于Linux系统的个人电脑,配备一枚700MHz的处理器,256Mb内存,支持SD卡和Ethernet,拥有两个USB接口 ...
- 粤嵌GEC6818开发板-入门感慨篇
第一次接触嵌入式开发,小脑袋是一篇空白,度娘各种资料,零零碎碎,似懂非懂,确实有点懵逼. 1.前期准备 粤嵌GEC6818开发板一套,USB转串口线一根(简称A线),网线一根(简称N线)(可选).用A ...
- 粤嵌gec6818开发板轮流显示颜色
粤嵌gec6818开发板轮流显示颜色 #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> ...
- 电脑向linux板卡传文件,ARM 开发板嵌入式linux系统与主机PC通过串口传输文件
ARM 开发板嵌入式linux系统与主机PC通过串口传输文件 本来以为按以下两篇文章就可以几步轻松搞定这个问题,没想到遇到两个小麻烦: 1,我用的xp虚拟机下redhat9.0做主机,按照下面第一篇文 ...
- 【华为云技术分享】【昇腾】【玩转Atlas200DK系列】基于Pycharm专业版构建开发板python开发运行环境
摘要:基于Pycharm专业版构建开发板python开发运行环境(自动同步爽歪歪) 既然Matrix提供了python接口,那咱们就要将方便的用起来,接下来分享一个利用pycharm直接搞定开发板开发 ...
最新文章
- 普通页面使用vue.js心得
- Yii2配置Nginx伪静态的方法
- 浙江万里学院计算机专业宿舍,浙江万里学院宿舍条件,宿舍几人间环境好不好(图片)...
- 获取iPhone型号
- CentOS6.4 Install FTP
- python软件如何安装方法_【新手必看】Python软件下载及安装教程
- jquery $.each遍历json数组方法
- 【图像处理基础知识】-傅里叶变换
- 【算法】八皇后问题 Python实现
- linux分区整数计算器,整数G分区计算工具
- 近期热门微信小程序demo源码下载汇总
- 32位win10服务器系统,win10原版32位
- ORBSLAM2 文章翻译
- Android 解决Dialog 样式的Activity 半透明背景失效问题
- 创建variation model (差异模型)
- CSS3实现闪烁动画效果
- Vector去除重复元素
- 有哪些靠谱的淘宝代运营公司?
- 自动化的内容生成语言模型如何帮助您赢得seo竞赛
- 【转】MAPI over HTTP协议
热门文章
- ZigBee系统初始化流程
- 前端报错Module not found: Error: Can‘t resolve巴拉巴拉的
- C语言实训——经典小游戏马里奥开发day 1
- hut第三次面试题解
- adb 最大连接_adb工具:
- 2023去水印小程序saas系统源码修复独立版v1.0.3+uniapp前端
- 数据科学中的陷阱:定性变量的处理
- 密码学基础之对称密码体制和公钥密码体制
- java输出数组的最大值_JAVA 键盘输入数组,输出数组内容和最大值、最小值(示例代码)...
- Github项目分享|第一期