chickenhouse/gpio.py

30 lines
794 B
Python
Raw Normal View History

2016-03-21 08:45:52 +00:00
from os.path import islink, isfile
2016-03-20 13:06:07 +00:00
class gpio:
def __init__(self, pin):
self.pin = pin
def export(self):
2016-03-21 08:45:52 +00:00
if not islink("/sys/class/gpio/gpio" + str(self.pin)):
f = open("/sys/class/gpio/export", "w")
f.write(str(self.pin))
2016-03-20 13:06:07 +00:00
def unexport(self):
2016-03-21 08:45:52 +00:00
if islink("/sys/class/gpio/gpio" + str(self.pin)):
f = open("/sys/class/gpio/unexport", "w")
f.write(str(self.pin))
2016-03-20 13:06:07 +00:00
def direction(self, direction = "out"):
2016-03-21 08:45:52 +00:00
if isfile("/sys/class/gpio/gpio" + str(self.pin) + \
"/direction"):
f = open("/sys/class/gpio/gpio" + str(self.pin) + \
"/direction", "w")
f.write(direction)
2016-03-20 13:06:07 +00:00
def set(self, value = 0):
2016-03-21 08:45:52 +00:00
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))