我正在使用 ioctl 写入 Framebuffer,效果很好。
但是,当我关闭它时,图像仍在屏幕上。我想将控制台文本恢复到写入缓冲区之前的状态。有人知道怎么做吗?下面的代码是我正在使用的;
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;
}