Fix problem with start

This commit is contained in:
2020-10-29 19:26:25 +01:00
parent 0852a2c83e
commit 27905dc590
2 changed files with 7 additions and 9 deletions

View File

@@ -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);
}