大家好,又见面了,我是你们的朋友全栈君。
今天为了测试我的LCD有没有坏点写了一个简单的刷屏程序,效果还不错,分析给大家。代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
char inbuf[240*320*2];
int i = 0;
/*open /dev/fb0 */
fbfd = open(“/dev/fb0”,O_RDWR);
if(fbfd<=0)
{
printf(“Error:cannot open framebuffer devices./n”);
return -1;
}
printf(“The framebuffer devices was opened successfully./n”);
/*get framebuffer infomation*/
if(ioctl(fbfd,FBIOGET_FSCREENINFO,&finfo))
{
printf(“Error: reanding fixed informatin./n”);
return -1;
}
if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo))
{
printf(“Error: reanding var informatin./n”);
return -1;
}
/*set screensiez*/
screensize = vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8;
/*mmap*/
fbp = (char*)mmap(0,screensize,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);
if((int)fbp == -1)
{
printf(“Error: failed to map framebuffer device to memory./n”);
return -4;
}
printf(” The framebuffer device was mapped to memory sucessfully./n”);
memcpy(inbuf,fbp,screensize);//保存刷屏前显存中的数据
for(i = 0;i<0xff;i++)
{
memset(fbp,i,screensize);
sleep(1);
}
memcpy(fbp,inbuf,screensize);//将保存的显存数据复原回去
munmap(fbp,screensize);
printf(“The framebuffer device was munmaped successfully./n”);
close(fbfd);
printf(“The framebuffer device was closed successfully./n”);
return 0;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/136720.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...