1 import RPi.GPIO as GPIO
4 # Pins dont exist in CPython so...lets make our own!
18 def __init__(self, bcm_number):
22 return "BCM #%d" % self.id
24 def init(self, mode=IN, pull=None):
26 print("set %d to mode %d" % (self.id, mode))
29 GPIO.setup(self.id, GPIO.IN)
30 elif mode == self.OUT:
32 GPIO.setup(self.id, GPIO.OUT)
34 raise RuntimeError("Invalid mode for pin: %s" % self.id)
36 print("set %d to pull %d" % (self.id, pull))
37 if self._mode != self.IN:
38 raise RuntimeError("Cannot set pull resistor on output")
39 if pull == self.PULL_UP:
40 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
41 elif pull == self.PULL_DOWN:
42 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
44 raise RuntimeError("Invalid pull for pin: %s" % self.id)
46 def value(self, val=None):
48 print("set %d to value %d" %(self.id, val))
51 GPIO.output(self.id, val)
52 elif val == self.HIGH:
54 GPIO.output(self.id, val)
56 raise RuntimeError("Invalid value for pin")
58 return GPIO.input(self.id)
88 # ordered as spiId, sckId, mosiId, misoId
89 spiPorts = ((1, SCLK, MOSI, MISO), (2, SCLK_2, MOSI_2, MISO_2))
91 # ordered as uartId, txId, rxId