2 sys.path.append("/opt/nvidia/jetson-gpio/lib/python")
3 sys.path.append("/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO")
4 import Jetson.GPIO as GPIO
6 GPIO.setwarnings(False) # shh!
8 # Pins dont exist in CPython so...lets make our own!
22 def __init__(self, bcm_number):
28 def __eq__(self, other):
29 return self.id == other
31 def init(self, mode=IN, pull=None):
35 GPIO.setup(self.id, GPIO.IN)
36 elif mode == self.OUT:
38 GPIO.setup(self.id, GPIO.OUT)
40 raise RuntimeError("Invalid mode for pin: %s" % self.id)
42 if self._mode != self.IN:
43 raise RuntimeError("Cannot set pull resistor on output")
44 if pull == self.PULL_UP:
45 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
46 elif pull == self.PULL_DOWN:
47 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
49 raise RuntimeError("Invalid pull for pin: %s" % self.id)
51 def value(self, val=None):
55 GPIO.output(self.id, val)
56 elif val == self.HIGH:
58 GPIO.output(self.id, val)
60 raise RuntimeError("Invalid value for pin")
62 return GPIO.input(self.id)
64 def cleanup(self, channel=None):
70 raise RuntimeError("Invalid pin to cleanup")