Last active
April 27, 2020 07:57
-
-
Save Hermann-SW/3b30a7d3e7b6dc39aeae15774bf677c9 to your computer and use it in GitHub Desktop.
Simple Raspberry pigpio based Arduino sketch compiler
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
#!/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> | |
#include <assert.h> | |
#include <pigpio.h> | |
#define LED_BUILTIN 18 | |
#define OUTPUT PI_OUTPUT | |
#define HIGH PI_HIGH | |
#define LOW PI_LOW | |
#define digitalWrite gpioWrite | |
#define pinMode gpioSetMode | |
static struct timespec time0 = { .tv_sec=0, .tv_nsec=0 }; | |
void delayMicroseconds(unsigned int us) { usleep(us); } | |
void delay(unsigned int ms) { delayMicroseconds(1000*ms); } | |
unsigned long micros(); | |
unsigned long millis() { return micros()/1000; } | |
unsigned long micros() | |
{ | |
struct timespec time1; | |
clock_gettime(CLOCK_REALTIME, &time1); | |
if (time0.tv_sec==0 && time0.tv_nsec==0) | |
{ | |
time0.tv_sec =time1.tv_sec; | |
time0.tv_nsec=time1.tv_nsec; | |
} | |
return 1000000*(time1.tv_sec-(long long)time0.tv_sec) + (time1.tv_nsec-(long)time0.tv_nsec)/1000; | |
} | |
EndOfWrapper | |
` | |
echo -e "$wrapper\n#include \"$1\"\nint main() { assert(gpioInitialise()>=0); micros(); setup(); while (1) loop(); }" | gcc -x c -Wall -pedantic -Wextra - -o `basename $1 .ino` -lpigpio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment