2013-09-01 7 views
2

J'utilise ioctl pour écrire dans le Framebuffer, qui fonctionne très bien. Toutefois, lorsque je le ferme, l'image est toujours affichée à l'écran. Je voudrais restaurer le texte de la console à ce qu'il était avant que j'écrive dans le tampon. Quelqu'un sait-il comment faire? Le code ci-dessous est ce que j'utilise;Comment restaurer le test de la console lorsque vous avez terminé avec le frambuffer?

struct fb_var_screeninfo vinfo; 


    fbfd = open("/dev/fb0", O_RDWR); 
    if (!fbfd) { 
    printf("Error: cannot open framebuffer device.\n"); 
    return(1); 
    } 

    // Get variable screen information 
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { 
    printf("Error reading variable information.\n"); 
    } 
    printf("Original %dx%d, %dbpp\n", vinfo.xres, vinfo.yres, 
     vinfo.bits_per_pixel); 


    // map fb to user mem 
    screensize = finfo.smem_len; 
    fbp = (char*)mmap(0, 
       screensize, 
       PROT_READ | PROT_WRITE, 
       MAP_SHARED, 
       fbfd, 
       0); 

    if ((int)fbp == -1) { 
    printf("Failed to mmap.\n"); 
    } 
    else { 
// draw...some lines 
    int x, y; 
    unsigned int pix_offset; 

    for (y = 0; y < (vinfo.yres/2); y++) { 
     for (x = 0; x < vinfo.xres; x++) { 

     // calculate the pixel's byte offset inside the buffer 
     // see the image above in the blog... 
     pix_offset = x + y * finfo.line_length; 

     // now this is about the same as fbp[pix_offset] = value 
     *((char*)(fbp + pix_offset)) = 16 * x/vinfo.xres; 

     } 
    } 

    sleep(5); 
    } 

    // cleanup 
    munmap(fbp, screensize); 
    if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &orig_vinfo)) { 
    printf("Error re-setting variable information.\n"); 
    } 
    close(fbfd); 

    return 0; 

} 

Répondre

0

Je sais que cette question est assez vieux, mais je vais offrir une solution à tous ceux qui vient à travers cette question (comme je l'ai fait).

Ce que je fais habituellement est d'obtenir une capture d'écran de l'écran avant d'écrire avec:

cp /dev/fb0 /tmp/orig_screen

Quand je suis fait à l'aide du framebuffer que je reconstitue l'écran précédent avec:

cp /tmp/orig_screen /dev/fb0

Questions connexes