这个代码实测可用于GEC6818的开发板
单片机源程序如下:
#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 <strings.h>
#include &quot;jpeglib.h&quot;
#include &quot;api_v4l2.h&quot;
#include <stdlib.h>
#include <pthread.h>
#define LCD_WIDTH 800
#define LCD_HEIGHT 480
int *p = NULL;
int lcd_fd = -1;
int is_open_camera = 0;
int is_video_play = 0;
int is_vedio_record = 0;
int video_count=1;
FrameBuffer camera_buf;
int video_fd;
char bmp[3][10] =
{
&quot;1.bmp&quot;,
&quot;2.bmp&quot;,
&quot;girl.bmp&quot;
};
int lcd_open(void)
{
lcd_fd = open(&quot;/dev/fb0&quot;,O_RDWR);
if(lcd_fd < 0)
{
perror(&quot;lcd open failed&quot;);
return 0;
}
p = mmap(NULL, LCD_WIDTH*LCD_HEIGHT*4,
PROT_READ | PROT_WRITE,
MAP_SHARED,
lcd_fd,
0);
if (NULL == p)
{
perror(&quot;lcd mmap error: &quot;);
return -1;
}
return 0;
}
int lcd_draw_point(int x, int y, int color)
{
if (x > 800)
{
printf(&quot;value of X-coordinates is over: %d\n&quot;, LCD_WIDTH);
return -1;
}
if (y > 480)
{
printf(&quot;value of Y-coordinates is over: %d\n&quot;, LCD_HEIGHT);
return -1;
}
*(p + x + y*800) = color;
return 0;
}
void lcd_draw_bmp(const char *file_name, int x0, int y0)
{
int fd;
int bmp_width;
int bmp_height;
char buf[54];
fd = open(file_name, O_RDONLY);
if (fd < 0)
{
perror(&quot;open file error: &quot;);
return ;
}
/* 读取位图头部信息 */
read(fd,buf,54);
/* 宽度 */
bmp_width =buf[18];
bmp_width|=buf[19]<<8;
//printf(&quot;bmp_width=%d\r\n&quot;,bmp_width);
/* 高度 */
bmp_height =buf[22];
bmp_height|=buf[23]<<8;
//printf(&quot;bmp_height=%d\r\n&quot;,bmp_height);
int len;
len = bmp_width*bmp_height*3;
//跳过 前边54个字节,这54个字节是用来存储bmp图片的相关信息的
lseek(fd, 54, SEEK_SET);
//从第55个字节开始,读取bmp图片的像素数组
char bmp_buf[len];
read(fd, bmp_buf, len);//因为这个bmp图片是24位色
close(fd);
int color, x, y, i = 0;
unsigned char r, g, b;
for (y = 0; y < bmp_height; y++)
{
for (x = 0; x < bmp_width; x++)
{
//将一个24bit //bmp图片的像素点转换为LCD的一个像素点
b = bmp_buf[i++];
g = bmp_buf[i++];
r = bmp_buf[i++];
color = (r << 16) | (g << 8) | b;
lcd_draw_point(x + x0, bmp_height-y+y0-1, color);
}
}
}
int get_pos(int *pos_x,int *pos_y)
{
// 打开触摸屏设备
struct input_event buf;
bzero(&buf, sizeof(buf));
int ts = open(&quot;/dev/input/event0&quot;, O_RDONLY);
if(ts < 0)
{
perror(&quot;open touch srceen failed&quot;);
return -1;
}
while(1)
{
// 循环地读取触摸屏信息
read(ts, &buf, sizeof(buf));
// 遇到 X轴 坐标事件
if(buf.type == EV_ABS && buf.code == ABS_X)
{
*pos_x = buf.value;
printf(&quot;(%d, &quot;, *pos_x);
}
// 遇到 Y轴 坐标事件
if(buf.type == EV_ABS && buf.code == ABS_Y)
{
*pos_y = buf.value;
printf(&quot;%d)\n&quot;, *pos_y);
}
//判断手指松开
if (buf.value == 0)
break;
}
}
/****************************************************
*函数名称:file_size_get
*输入参数:pfile_path -文件路径
*返 回 值:-1 -失败
其他值 -文件大小
*说 明:获取文件大小
****************************************************/
unsigned long file_size_get(const char *pfile_path)
{
unsigned long filesize = -1;
struct stat statbuff;
if(stat(pfile_path, &statbuff) < 0)
{
return filesize;
}
else
{
filesize = statbuff.st_size;
}
return filesize;
}
/*
x :起点
y :起点
pjpg_path :图片路径
pjpg_buf :摄像头获取的图像数据,如果你没用摄像头一般设为NULL
jpg_buf_size:摄像头数据的大小,默认设为0
*/
int lcd_draw_jpg(unsigned int x,unsigned int y,const char *pjpg_path,char *pjpg_buf,unsigned int jpg_buf_size)
{
/*定义解码对象,错误处理对象*/
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
char g_color_buf[800*480*4];
char *pcolor_buf = g_color_buf;
char *pjpg;
unsigned int i=0;
unsigned int color =0;
unsigned int count =0;
unsigned int x_s = x;
unsigned int x_e ;
unsigned int y_e ;
int jpg_fd;
unsigned int jpg_size;
unsigned int jpg_width;
unsigned int jpg_height;
if(pjpg_path!=NULL)
{
/* 申请jpg资源,权限可读可写 */
jpg_fd=open(pjpg_path,O_RDWR);
if(jpg_fd == -1)
{
printf(&quot;open %s error\n&quot;,pjpg_path);
return -1;
} |