Last active
January 22, 2024 03:20
-
-
Save arpruss/44613d4a60cc1aa1175079cbea38e6c2 to your computer and use it in GitHub Desktop.
Measure screen lag on rpi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
instructions: hook up one oscilloscope channel to a photodiode circuit and the other to GPIO 21; trigger on GPIO 21 | |
*/ | |
#include <stdio.h> | |
#include <fcntl.h> | |
#include <sys/ioctl.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <linux/fb.h> | |
#include <pigpio.h> | |
#define PIN 21 | |
int main() { | |
char* fb; | |
int handle = open("/dev/fb0", O_RDWR); | |
struct fb_var_screeninfo vinfo; | |
struct fb_fix_screeninfo finfo; | |
ioctl(handle, FBIOGET_VSCREENINFO, &vinfo); | |
vinfo.xres_virtual = vinfo.xres; | |
vinfo.yres_virtual = vinfo.yres; | |
vinfo.xoffset = 0; | |
vinfo.bits_per_pixel = 16; | |
ioctl(handle, FBIOPUT_VSCREENINFO, &vinfo); | |
ioctl(handle, FBIOGET_FSCREENINFO, &finfo); | |
printf("%d\n", finfo.smem_len); | |
fb = (char*)mmap(0, finfo.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, handle, 0); | |
gpioInitialise(); | |
gpioSetMode(PIN,PI_OUTPUT); | |
while(1) { | |
unsigned dummy; | |
// ioctl(handle, FBIO_WAITFORVSYNC, &dummy); | |
gpioWrite(PIN,PI_HIGH); | |
memset(fb, 255, finfo.smem_len); | |
sleep(2); | |
// ioctl(handle, FBIO_WAITFORVSYNC, &dummy); | |
gpioWrite(PIN,PI_LOW); | |
memset(fb, 0, finfo.smem_len); | |
sleep(2); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment