From 22398b03aa2bd8f122d90147c81389426ac84dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Mon, 3 Apr 2017 15:57:50 +0200 Subject: [PATCH] V1 switch.c: Move duplicate code into function --- V1/switch.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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)