=====================LCD===============
lcd驱动文件或者它的路径:/dev/fb0
测试是否是lcd驱动文件:cat /smartHome/jpg_dir/10.jpg > /dev/fb0
触摸库安装
1、将触摸库放在ubuntu与windows共享目录中
2、sudo -s (密码:123456)
3、cp /mnt/hgfs/linuxshare/tslib-1.4.tar.bz2 /home/gec/ //将触摸库复制到家目录
4、cd /home/gec
5、tar -jxvf tslib-1.4.tar.bz2 //解压触摸库文件
6、cd tslib-1.4/ //进入触摸库目录
7、./configure --host=arm-linux --prefix=/usr/local/arm ac_cv_func_malloc_0_nonnull=yes
配置触摸库
8、编译:make
9、安装库:make install
linux下以so结尾的为动态库,以.a结尾的为静态库
存放坐标的相关信息的结构体
/usr/local/arm/include/tslib.h头文件
struct ts_sample {
int x; //x轴坐标
int y; //y轴坐标
unsigned int pressure;//压力值
struct timeval tv; //时间值
};
编译命令:arm-linux-gcc ts.c -o ts -I /usr/local/arm/include/ -L /usr/local/arm/lib -lts
指定头的路径 指定库存路径 指定库名
屏幕校准:
cd /tslib/bin/
./ts_calibrate
练习:
在屏幕上面自定义两个控制,通过控制来切换效果(一张横的七色图,一张是坚的八色图)
mmap() 文件映射:将一个文件或者其它对象映射进内存。
#include
void *mmap(void *addr, size_t len, int prot, int flags,
int fildes, off_t off);
返回值: 成功:映射内存的地址
失败: MAP_FAILED
void *addr:映射时给定的地址,如果设置为NULL,则系统会自动寻找最佳的映射起始地址
size_t len:映射内存的大小
int prot :
PROT_READ Data can be read.
PROT_WRITE Data can be written.
PROT_EXEC Data can be executed.
PROT_NONE Data cannot be accessed.
int flags:
MAP_SHARED Changes are shared.
MAP_PRIVATE Changes are private.
MAP_FIXED Interpret addr exactly.
int fildes:文件描述符
off_t off:文件映射开始区的偏移量
munmap 撤消映射
#include
int munmap(void *addr, size_t len);
void *addr:映射的地址
size_t len:映射的大小
练习:
1、在指向的区域(350,200)画一个(150x100)红色控件
2、划屏操作,向左划动蓝色,右划黄色
#include
#include "tslib.h"
#include
#include
#include
#include
#include
#define DEV_NAME "/dev/fb0"
int main(void)
{
int ts;
struct ts_sample samp;
int ret,i,j;
unsigned int *addr;
int color=0xFF0000;
//打开触摸屏
ts = open(DEV_NAME,O_RDWR);
if(ts == -1)
{
printf("open ts failed!\n");
return -1;
}
addr=(unsigned int *)mmap(NULL, 480*800*4,PROT_READ|PROT_WRITE,MAP_SHARED,ts,0);
if (addr == MAP_FAILED)
perror("error mmap");
for(j=200;j<300;j++)
for(i=0;i<150;i++)
*(addr+((800*j)+350+i))=color;
munmap(addr,480*800*4);
close(ts);
return 0;
}
22222222222222222222222222222222222
#include
#include "tslib.h"
#include
#include
#include
#include
#define DEV_NAME "/dev/event0"
left(void)
{
int lcd_fd,i,x,y,j,temp;
int color[8] = {0xFF0000,0xFF7F00,0xFFFF00,0x00FF00,0x00FFFF,0x0000FF,0x8B00FF,0xffffff}; //RGB
//打开屏幕Lcd
lcd_fd = open("/dev/fb0",O_RDWR);
if(lcd_fd == -1)
{
printf("open lcd failed!\n");
return -1;
}
for(x=0;x<480;x++)
{
for(j=0;j<8;j++)
{
temp=color[j];
for(i=0;i<100 ;i++)
{
write(lcd_fd,&temp,sizeof(int));
}
}
}
};
right(void)
{
int lcd_fd,i,x,y,j,temp;
int color[7] = {0xFF0000,0xFF7F00,0xFFFF00,0x00FF00,0x00FFFF,0x0000FF,0x8B00FF}; //RGB
//打开屏幕Lcd
lcd_fd = open("/dev/fb0",O_RDWR);
if(lcd_fd == -1)
{
printf("open lcd failed!\n");
return -1;
}
for(j=0;j<7;j++)
{
temp=color[j];
for(i=0;i<69*800 ;i++)
{
write(lcd_fd,&temp,sizeof(int));
}
}
close(lcd_fd);
lcd_fd=0;
return 0;
};
int main(void)
{
struct tsdev *ts;
struct ts_sample samp;
int ret;
int sub;
//打开触摸屏
ts = ts_open(DEV_NAME,0);
if(ts == NULL)
{
printf("open ts failed!\n");
return -1;
}
//配置触摸屏,配置插件
ret = ts_config(ts);
if(ret == -1)
{
printf("ts_config failed!\n");
ts_close(ts);
return -1;
}
while(1)
{
ts_read(ts,&samp,1);
printf("samp.x = %d,samp.y = %d,samp.pressure = %d\n",samp.x,samp.y,samp.pressure);//反馈触摸信息
//-------------滑动效果的判断---------------
sub=0;
if(samp.x<800 && samp.pressure==200)
{
sub=samp.x;
ts_read(ts,&samp,1);
printf("samp.x = %d,samp.y = %d,samp.pressure = %d\n",samp.x,samp.y,samp.pressure);
sub-=samp.x;
if(sub>0&&samp.pressure==200)
{
left();
continue;
}
if(sub<0&&samp.pressure==200)
right();
}
}
return 0;
}