From 623a7e73cf79ecdda28fe5d3ff429090dbae359d Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Fri, 10 Jul 2020 11:08:51 +0100 Subject: make GPIO a parameter --- pingid.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'pingid.c') diff --git a/pingid.c b/pingid.c index 6e33510..0dc182a 100644 --- a/pingid.c +++ b/pingid.c @@ -6,6 +6,14 @@ #include #include +#ifndef GPIO +#define GPIO 4 +#endif + +#define STRINGIFY(a) #a +#define STRINGIFY_HARDER(a) STRINGIFY(a) +#define GPIO_STR STRINGIFY_HARDER(GPIO) + char *names[KEY_MAX + 1] = { "", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "", @@ -132,16 +140,17 @@ main (int argc, char *argv[]) struct timeval tv; char ret[128]; - squirt ("/sys/class/gpio/export", "4"); - squirt ("/sys/class/gpio/gpio4/direction", "out"); - squirt ("/sys/class/gpio/gpio4/value", "0"); + + squirt ("/sys/class/gpio/export", GPIO_STR); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/direction", "out"); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/value", "0"); tv.tv_sec = 0; tv.tv_usec = 100; get_string_with_timeout (fd, &tv, NULL, 0); - squirt ("/sys/class/gpio/gpio4/value", "1"); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/value", "1"); tv.tv_sec = 2; @@ -149,7 +158,7 @@ main (int argc, char *argv[]) get_string_with_timeout (fd, &tv, ret, sizeof (ret)); - squirt ("/sys/class/gpio/gpio4/value", "0"); + squirt ("/sys/class/gpio/gpio" GPIO_STR "/value", "0"); printf ("Access-Control-Allow-Origin: *\n"); printf ("Content-Type: text/plain\n\n%s\n", ret); -- cgit v1.2.3