1 import RPi.GPIO as GPIO
4 # Pins dont exist in CPython so...lets make our own!
18 def __init__(self, bcm_number):
21 def init(self, mode=IN, pull=None):
23 print("set %d to mode %d" % (self.id, mode))
26 GPIO.setup(self.id, GPIO.IN)
27 elif mode == self.OUT:
29 GPIO.setup(self.id, GPIO.OUT)
31 raise RuntimeError("Invalid mode for pin: %s" % self.id)
33 print("set %d to pull %d" % (self.id, pull))
34 if self._mode != self.IN:
35 raise RuntimeError("Cannot set pull resistor on output")
36 if pull == self.PULL_UP:
37 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
38 elif pull == self.PULL_DOWN:
39 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
41 raise RuntimeError("Invalid pull for pin: %s" % self.id)
43 def value(self, val=None):
45 print("set %d to value %d" %(self.id, val))
48 GPIO.output(self.id, val)
49 elif val == self.HIGH:
51 GPIO.output(self.id, val)
53 raise RuntimeError("Invalid value for pin")
55 return GPIO.input(self.id)
85 # ordered as spiId, sckId, mosiId, misoId
86 spiPorts = ((1, SCLK, MOSI, MISO), (2, SCLK_2, MOSI_2, MISO_2))
88 # ordered as uartId, txId, rxId