30 lines
794 B
Python
30 lines
794 B
Python
from os.path import islink, isfile
|
|
class gpio:
|
|
def __init__(self, pin):
|
|
self.pin = pin
|
|
|
|
def export(self):
|
|
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):
|
|
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"):
|
|
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):
|
|
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))
|
|
|