|
From: Hihn J. <Jas...@DA...> - 2002-01-23 16:29:50
|
> Whoops, I hit send accidentally.
>
> #include <unistd.h>
> #include <stdio.h>
> #include <fcntl.h>
> #include <linux/fb.h>
> #include <sys/mman.h>
>
> int main()
> {
> int fbfd = 0;
> struct fb_var_screeninfo vinfo;
> struct fb_fix_screeninfo finfo;
> struct fb_var_cursorinfo vcinfo;
> struct fb_fix_cursorinfo fcinfo;
> struct fb_cursorstate cstate;
>
> long int screensize = 0;
> char *fbp = 0;
> int x = 0, y = 0, bit, pow,c;
> long int location = 0; /* Open the file for reading and
> writing */
> fbfd = open("/dev/fb0", O_RDWR);
> if (!fbfd) {
> printf("Error: cannot open framebuffer device.\n");
> exit(1);
> }
> printf("The framebuffer device was opened successfully.\n");
> /* Get fixed screen information */
> if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
> printf("Error reading fixed information.\n");
> } else {
> printf("fixed screen
> info(%s):\n\ttype=%d\n\tvis=%d\n\tll=%d\n\taccel=%d\n",
> finfo.id, finfo.type, finfo.visual, finfo.line_length,
> finfo.accel);
> }
>
> /* Get variable screen information */
> if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
> printf("Error reading variable information.\n");
> } else {
> printf("variable screen
> info:\n\txres=%d\n\tyres=%d\n\tbpp=%d\n\tgrey=%d\n\tnonstd=%d\n\taccel_fla
> gs
> =%d\n",
> vinfo.xres, vinfo.yres, vinfo.bits_per_pixel,
> vinfo.grayscale, vinfo.nonstd, vinfo.accel_flags);
>
> /* Figure out the size of the screen in bytes */
> screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
> }
> if (ioctl(fbfd, FBIOGET_FCURSORINFO, &fcinfo)) {
> printf("Error reading Fixed Cursor information.\n");
> } else {
> printf("fcinfo:\tw=%d\n\th=%d\n\txs=%d\n\tys=%d\n\tc1=%dc2=%d\n",
> fcinfo.crsr_width,
> fcinfo.crsr_height,
> fcinfo.crsr_xsize,
> fcinfo.crsr_ysize,
> fcinfo.crsr_color1,
> fcinfo.crsr_color2);
> }
> if (ioctl(fbfd, FBIOGET_VCURSORINFO, &vcinfo)) {
> printf("Error reading Variable Cursor information.\n");
> } else {
> printf("vcinfo:\tx=%d\n\ty=%d\n", vcinfo.xspot, vcinfo.yspot);
> }
>
> if (ioctl(fbfd, FBIOGET_CURSORSTATE, &cstate)) {
> printf("Error reading Cursor State information.\n");
> }else {
> printf("vcinfo:\tx=%d\n\ty=%d\n\ts=%d\n", cstate.xoffset,
> cstate.yoffset, cstate.mode);
> }
>
> /* Map the device to memory */
> 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");
> exit(4);
> }
> printf("The framebuffer device was mapped to memory
> successfully.\n");
>
>
> /* Set variable screen information */
> vinfo.xres=320; vinfo.yres=240;
> vinfo.xres_virtual=320; vinfo.yres_virtual=240;
> vinfo.xoffset=0; vinfo.yoffset=0;
> vinfo.bits_per_pixel=1;
>
> if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &vinfo)) {
> printf("Error setting variable information.\n");
> }
>
> /* Get variable screen information */
> if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
> printf("Error reading variable information.\n");
> } else {
> printf("variable screen
> info:\n\txres=%d\n\tyres=%d\n\tbpp=%d\n\tgrey=%d\n\tnonstd=%d\n\taccel_fla
> gs
> =%d\n",
> vinfo.xres, vinfo.yres, vinfo.bits_per_pixel,
> vinfo.grayscale, vinfo.nonstd, vinfo.accel_flags);
>
> /* Figure out the size of the screen in bytes */
> screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
> }
>
>
>
> memset(fbp, time(NULL)%256, screensize);
>
>
>
> munmap(fbp, screensize);
> close(fbfd);
> return 0;
> }
>
|