From 27905dc59058e62eacc98e43465bc4e070d352ee Mon Sep 17 00:00:00 2001 From: Jaro Date: Thu, 29 Oct 2020 19:26:25 +0100 Subject: [PATCH] Fix problem with start --- Makefile | 4 ++-- gpiosysfs.c | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 92a4e83..cc0739c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 0.0.7 +VERSION = 0.0.11 # Global target; when 'make' is run without arguments, this is what it should do all: bell-mqtt-recv @@ -35,4 +35,4 @@ clean: rm bell-mqtt-recv -f *.o pack: - tar cvzf ../bell-rspro-$(VERSION).tar.gz $(DEPS) $(SRC) Makefile bell-rspro.init + tar cvzf ../bell-rspro-$(VERSION).tar.gz $(DEPS) $(SRC) Makefile Makefile.openwrt bell-rspro.init diff --git a/gpiosysfs.c b/gpiosysfs.c index 1efb33b..285c8f2 100644 --- a/gpiosysfs.c +++ b/gpiosysfs.c @@ -32,19 +32,17 @@ static void writeToFile(const char *absoluteFileName, const char *contents) { } void gpioSetup(const char *pin) { - // TODO only export if not already exported... - if (access("/sys/class/gpio/unexport",W_OK) == 0) - writeToFile("/sys/class/gpio/unexport", pin); - writeToFile("/sys/class/gpio/export", pin); - - char buf[33]; + char buf[64]; struct stat statBuf; int pinExported = -1; sprintf(buf, "/sys/class/gpio/gpio%s/direction", pin); + if (stat(buf, &statBuf) != 0) + writeToFile("/sys/class/gpio/export", pin); + // May have to briefly wait for OS to make symlink! - while (pinExported != 0) { + while (pinExported != 0) { msleep(1000); pinExported = stat(buf, &statBuf); }