分类: LINUX
2012-09-08 07:04:51
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
unsigned char *fbp;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
void drawpoint(unsigned int x,unsigned int y,unsigned int *color)
{
unsigned char *fbp0;
fbp0=fbp;
fbp0+=y*vinfo.xres*vinfo.bits_per_pixel/8+x*vinfo.bits_per_pixel/8;
memcpy(fbp0,color,vinfo.bits_per_pixel/8);
}
int mrand(int x,int y) //
{
int i;
time_t t;
srand((unsigned) time(&t));
return (rand()%(y-x+1)+x);
}
int main()
{
int fd;
unsigned int i=0;
int bgcolor;
long int screensize;
bgcolor=0;
int color;
//color=0x0000ff00;
int redcolor=0x00ff0000;
int greencolor=0x0000ff00;
int bluecolor=0x000000ff;
// int color[3]={0xff000000,0x00ff0000,0x0000ff00};
if((fd=open("/dev/fb0",O_RDWR))<0)
{
perror("fail to open");
return 0;
}
if (ioctl(fd,FBIOGET_FSCREENINFO, &finfo))
{
perror("fail to get");
return 0;
}
if (ioctl(fd,FBIOGET_VSCREENINFO, &vinfo))
{
perror("fail to get");
return 0;
}
screensize=vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8;
fbp=(unsigned char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd, 0);
for(i=0;i
usleep(10000);
int xrand=0;
int yrand=0;
int crand=0;
// drawpoint(100,100,&redcolor);
// drawpoint(200,200,&greencolor);
// drawpoint(300,300,&bluecolor);
while(1)
{
xrand=mrand(0,800);
yrand=mrand(0,480);
crand=mrand(0,2);
printf("xrand=%d\n",xrand);
printf("yrand=%d\n",yrand);
printf("crand=%d\n",crand);
switch(crand)
{
case 0: //red
color=0x00ff0000;
break;
case 1://green
color=0x0000ff00;
break;
default://blue
color=0x000000ff;
break;
}
usleep(10000);
drawpoint(xrand,yrand,&color);
//drawpoint(xrand+1,yrand,&color);
//drawpoint(xrand,yrand+1,&color);
//drawpoint(xrand+1,yrand+1,&color);
}
munmap(fbp,screensize);
close(fd);
return 0;
}