linux下如何实现简单刷屏【转】

     今天为了测试我的LCD有没有坏点写了一个简单的刷屏程序,效果还不错,分析给大家。代码如下:

 #include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

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;

}















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5587254.html,如需转载请自行联系原作者

上一篇:Linux中实现一个简单的进度条【转】


下一篇:《HTML5 开发实例大全》——1.13 使用< progress >标记元素实现进度条效果