Created
March 12, 2020 19:00
-
-
Save Hermann-SW/966d7960ce79280deec3085c503ad733 to your computer and use it in GitHub Desktop.
toggle GPIO17 camera schedule every Nth frame, triggeded by Raspberry hardware camera sync pulses on GPIO18 (https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=267761)
This file contains hidden or 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
/* | |
$ gcc -O6 -Wall -pedantic -Wextra -o toggle toggle.c -lpigpio -lrt -lpthread | |
$ | |
Usage: | |
$ sudo killall pigpiod | |
$ sudo ./toggle 30 & | |
$ raspivid -md 1 -w 1920 -h 1080 -p 22,50,960,540 -o tst.h264 -fps 30 -t 8000 -pts tst.pts | |
$ ./ptsanalyze tst.pts 0 | |
$ # https://github.com/Hermann-SW/userland/blob/master/tools/ptsanalyze | |
$ | |
Captures 8s 1920x1080@30fps video, toggles camera 30th frame (every second), | |
then does frame delay and skip analysis. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <assert.h> | |
#include <pigpio.h> | |
#define gpioCAMsel 17 | |
#define gpioHWsync 18 | |
int main(int argc, char *argv[]) | |
{ | |
int N,i=0,sel=0; | |
assert(argc == 1+1); | |
assert(0 < (N = atoi(argv[1]))); | |
assert(gpioInitialise()>=0); | |
gpioSetMode(gpioHWsync, PI_OUTPUT); // needs to be OUTPUT although read | |
gpioSetMode(gpioCAMsel, PI_OUTPUT); | |
gpioWrite(gpioCAMsel, sel); | |
while (1) | |
{ | |
while (gpioRead(gpioHWsync) ==0) {} | |
while (gpioRead(gpioHWsync) ==1) {} | |
if (++i == N) | |
{ | |
i = 0; | |
sel = 1-sel; | |
gpioWrite(gpioCAMsel, sel); | |
} | |
} | |
// never reached | |
gpioTerminate(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment