1 import RPi.GPIO as GPIO
4 # Pins dont exist in CPython so...lets make our own!
18 def __init__(self, bcm_number):
24 def __eq__(self, other):
25 return self.id == other
27 def init(self, mode=IN, pull=None):
29 print("set %d to mode %d" % (self.id, mode))
32 GPIO.setup(self.id, GPIO.IN)
33 elif mode == self.OUT:
35 GPIO.setup(self.id, GPIO.OUT)
37 raise RuntimeError("Invalid mode for pin: %s" % self.id)
39 print("set %d to pull %d" % (self.id, pull))
40 if self._mode != self.IN:
41 raise RuntimeError("Cannot set pull resistor on output")
42 if pull == self.PULL_UP:
43 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
44 elif pull == self.PULL_DOWN:
45 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
47 raise RuntimeError("Invalid pull for pin: %s" % self.id)
49 def value(self, val=None):
51 print("set %d to value %d" %(self.id, val))
54 GPIO.output(self.id, val)
55 elif val == self.HIGH:
57 GPIO.output(self.id, val)
59 raise RuntimeError("Invalid value for pin")
61 return GPIO.input(self.id)
91 # ordered as spiId, sckId, mosiId, misoId
92 spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK_2, MOSI_2, MISO_2))
94 # ordered as uartId, txId, rxId