error correction in gpio class
This commit is contained in:
parent
93a7bc1792
commit
2e5e98dfe1
9
gpio.py
9
gpio.py
@ -1,22 +1,29 @@
|
|||||||
|
from os.path import islink, isfile
|
||||||
class gpio:
|
class gpio:
|
||||||
def __init__(self, pin):
|
def __init__(self, pin):
|
||||||
self.pin = pin
|
self.pin = pin
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
|
if not islink("/sys/class/gpio/gpio" + str(self.pin)):
|
||||||
f = open("/sys/class/gpio/export", "w")
|
f = open("/sys/class/gpio/export", "w")
|
||||||
f.write(str(self.pin))
|
f.write(str(self.pin))
|
||||||
|
|
||||||
def unexport(self):
|
def unexport(self):
|
||||||
|
if islink("/sys/class/gpio/gpio" + str(self.pin)):
|
||||||
f = open("/sys/class/gpio/unexport", "w")
|
f = open("/sys/class/gpio/unexport", "w")
|
||||||
f.write(str(self.pin))
|
f.write(str(self.pin))
|
||||||
|
|
||||||
def direction(self, direction = "out"):
|
def direction(self, direction = "out"):
|
||||||
|
if isfile("/sys/class/gpio/gpio" + str(self.pin) + \
|
||||||
|
"/direction"):
|
||||||
f = open("/sys/class/gpio/gpio" + str(self.pin) + \
|
f = open("/sys/class/gpio/gpio" + str(self.pin) + \
|
||||||
"/direction", "w")
|
"/direction", "w")
|
||||||
f.write(direction)
|
f.write(direction)
|
||||||
|
|
||||||
def set(self, value = 0):
|
def set(self, value = 0):
|
||||||
|
if isfile("/sys/class/gpio/gpio" + str(self.pin) + \
|
||||||
|
"/value"):
|
||||||
f = open("/sys/class/gpio/gpio" + str(self.pin) + \
|
f = open("/sys/class/gpio/gpio" + str(self.pin) + \
|
||||||
"/value", "w")
|
"/value", "w")
|
||||||
f.write(str(value))
|
f.write(str(value))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user