diff --git a/V1/switch.c b/V1/switch.c index 3822b37..f933361 100644 --- a/V1/switch.c +++ b/V1/switch.c @@ -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)