#include #include #include #include #include #include int main() { const char *fb_path = "/dev/fb0"; const char *output_dir = "/mnt/onboard/screenshots/"; int fb = open(fb_path, O_RDONLY); if (fb < 0) { perror("open framebuffer"); return 1; } struct fb_var_screeninfo vinfo; if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo)) { perror("ioctl"); close(fb); return 1; } int width = vinfo.xres; int height = vinfo.yres; int bpp = vinfo.bits_per_pixel; size_t screensize = width * height * (bpp / 8); unsigned char *buffer = malloc(screensize); if (!buffer) { perror("malloc"); close(fb); return 1; } int counter = 0; while (1) { if (lseek(fb, 0, SEEK_SET) < 0) { // torna all'inizio del framebuffer perror("lseek"); break; } if (read(fb, buffer, screensize) != screensize) { perror("read"); break; } char filename[256]; snprintf(filename, sizeof(filename), "%s/screen%03d.raw", output_dir, counter++); FILE *out = fopen(filename, "wb"); if (!out) { perror("fopen"); break; } fwrite(buffer, 1, screensize, out); fclose(out); sleep(1); } free(buffer); close(fb); return 0; }