From 2e5e98dfe1960f76fb28db33235f612a3b07871b Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 21 Mar 2016 09:45:52 +0100 Subject: [PATCH] error correction in gpio class --- gpio.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/gpio.py b/gpio.py index 7cdad5a..e3645be 100644 --- a/gpio.py +++ b/gpio.py @@ -1,22 +1,29 @@ - +from os.path import islink, isfile class gpio: def __init__(self, pin): self.pin = pin def export(self): - f = open("/sys/class/gpio/export", "w") - f.write(str(self.pin)) + if not islink("/sys/class/gpio/gpio" + str(self.pin)): + f = open("/sys/class/gpio/export", "w") + f.write(str(self.pin)) def unexport(self): - f = open("/sys/class/gpio/unexport", "w") - f.write(str(self.pin)) + if islink("/sys/class/gpio/gpio" + str(self.pin)): + f = open("/sys/class/gpio/unexport", "w") + f.write(str(self.pin)) def direction(self, direction = "out"): - f = open("/sys/class/gpio/gpio" + str(self.pin) + \ - "/direction", "w") - f.write(direction) + if isfile("/sys/class/gpio/gpio" + str(self.pin) + \ + "/direction"): + f = open("/sys/class/gpio/gpio" + str(self.pin) + \ + "/direction", "w") + f.write(direction) def set(self, value = 0): - f = open("/sys/class/gpio/gpio" + str(self.pin) + \ - "/value", "w") - f.write(str(value)) + if isfile("/sys/class/gpio/gpio" + str(self.pin) + \ + "/value"): + f = open("/sys/class/gpio/gpio" + str(self.pin) + \ + "/value", "w") + f.write(str(value)) +