V1 switch.c: Move duplicate code into function

This commit is contained in:
2017-04-03 15:57:50 +02:00
parent ae5d5b638f
commit 22398b03aa

View File

@@ -33,20 +33,23 @@ void freePin(char *pin)
writeFile(BASEPATH "unexport", pin, strlen(pin));
}
void setDirection(char *pin, char *direction, int dirlen)
{
char path[50];
sprintf(path, BASEPATH GPIO_FOLDER "direction", pin);
writeFile(path, direction, dirlen);
}
void registerInput(char *pin)
{
registerPin(pin);
char path[50];
sprintf(path, BASEPATH GPIO_FOLDER "direction", pin);
writeFile(path, "in", 2);
setDirection(pin, "in", 2);
}
void registerOutput(char *pin)
{
registerPin(pin);
char path[50];
sprintf(path, BASEPATH GPIO_FOLDER "direction", pin);
writeFile(path, "out", 3);
setDirection(pin, "out", 3);
}
int readInput(char *pin)