V1 switch.c: Move duplicate code into function
This commit is contained in:
15
V1/switch.c
15
V1/switch.c
@@ -33,20 +33,23 @@ void freePin(char *pin)
|
|||||||
writeFile(BASEPATH "unexport", pin, strlen(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)
|
void registerInput(char *pin)
|
||||||
{
|
{
|
||||||
registerPin(pin);
|
registerPin(pin);
|
||||||
char path[50];
|
setDirection(pin, "in", 2);
|
||||||
sprintf(path, BASEPATH GPIO_FOLDER "direction", pin);
|
|
||||||
writeFile(path, "in", 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerOutput(char *pin)
|
void registerOutput(char *pin)
|
||||||
{
|
{
|
||||||
registerPin(pin);
|
registerPin(pin);
|
||||||
char path[50];
|
setDirection(pin, "out", 3);
|
||||||
sprintf(path, BASEPATH GPIO_FOLDER "direction", pin);
|
|
||||||
writeFile(path, "out", 3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int readInput(char *pin)
|
int readInput(char *pin)
|
||||||
|
|||||||
Reference in New Issue
Block a user