Skip to content

Instantly share code, notes, and snippets.

View Hermann-SW's full-sized avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / yuvrgbfb
Created February 5, 2020 14:37
profiling bash script for work with rgba2fb.c (https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=264109)
#!/bin/bash
if [[ rgb2fb.c -nt rgb2fb ]]; then
echo "compiling rgb2fb.c"; gcc -O6 -Wall -pedantic -Wextra rgb2fb.c -o rgb2fb
fi
if [[ "$#" > 0 ]]; then t=$1; else t=600000; fi
raspividyuv -fps 90 -rgb -o - -pts $0.pts \
-md 7 -w 640 -h 480 -n -t $t -awb greyworld | \
./rgb2fb 640 480 F 2> $0.txt
@Hermann-SW
Hermann-SW / rgb2fb.c
Last active February 6, 2020 11:02
High framerate drawing stream of RGB frames on Raspberry framebuffer (https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=264109)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
@Hermann-SW
Hermann-SW / yuvrgbfb0
Created February 6, 2020 11:08
profiling bash script for work with rgba2fb.c (https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=264109)
#!/bin/bash
if [[ rgb2fb.c -nt rgb2fb ]]; then
echo "compiling rgb2fb.c"; gcc -O6 -Wall -pedantic -Wextra rgb2fb.c -o rgb2fb
fi
if [[ "$#" > 0 ]]; then t=$1; else t=600000; fi
raspividyuv -fps 135 -rgb -o - -pts $0.pts \
-md 7 -w 640 -h 480 -n -t $t -awb greyworld | \
./rgb2fb 640 480 0 2> $0.txt
@Hermann-SW
Hermann-SW / toggle.c
Created March 12, 2020 19:00
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)
/*
$ 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
@Hermann-SW
Hermann-SW / dead-man_button.c
Created March 28, 2020 14:44
Raspberry Pi code for raspcatbot control by Wifi joystick (https://esp32.com/viewtopic.php?f=19&t=14803&p=57338#p57338)
/*
$ gcc -O6 -Wall -pedantic -Wextra -o dead-man_button dead-man_button.c -lpigpio -lrt -lpthread
$
Usage:
$ sudo killall pigpiod
$ sudo ./dead-man_button
$
*/
#include <stdio.h>
#!/bin/bash
while true
do
fin_wait2=`netstat 2>/dev/null | grep 1337`
if [[ "$fin_wait2" = "" ]]
then
sudo ./dead-man_button
else
sudo ./dead-man_button 1338
fi
@Hermann-SW
Hermann-SW / arduino_compile
Last active April 27, 2020 07:57
Simple Raspberry pigpio based Arduino sketch compiler
#!/bin/bash
if [[ "$1" == "" || ${1: -4} != ".ino" ]]; then
echo -e "Usage:\n"`basename $0`" file.ino\nsudo ./file"
exit
fi
wrapper=`cat << EndOfWrapper
#include <time.h>
#include <unistd.h>
/*
Compile and link
gcc -O6 -I/opt/vc/include -L/opt/vc/lib -lbcm_host -o nanoflash nanoflash.c
Run example (gpioDpin rising edge => o[ns] offset => d[ns] gpio18 pwm flash)
$ sudo killall pigpiod
$ sudo ./nanoflash o d
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define N (32768+18580480)
int main(int argc, char* argv[])
{
FILE *src;
@Hermann-SW
Hermann-SW / nanopulse.c
Created October 19, 2020 16:14
pigpio library example nanopulse.c, modified for working with PIs after Pi1, with 4/3 scaling for Pi4B
/*
Compile and link
gcc -I/opt/vc/include -L/opt/vc/lib -lbcm_host -o nanopulse nanopulse.c
Run example (10000 10 nanosecond pulses with 2000 nano second gap)
sudo ./nanopulse 10 10000 2000
*/