1 # Pins dont exist in CPython so...lets make our own!
15 def __init__(self, pin_name):
21 def __eq__(self, other):
22 return self.id == other
24 def init(self, mode=IN, pull=None):
28 GPIO.setup(self.id, GPIO.IN)
29 elif mode == self.OUT:
31 GPIO.setup(self.id, GPIO.OUT)
33 raise RuntimeError("Invalid mode for pin: %s" % self.id)
35 if self._mode != self.IN:
36 raise RuntimeError("Cannot set pull resistor on output")
37 if pull == self.PULL_UP:
38 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_UP)
39 elif pull == self.PULL_DOWN:
40 GPIO.setup(self.id, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
42 raise RuntimeError("Invalid pull for pin: %s" % self.id)
44 def value(self, val=None):
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)
61 # ordered as spiId, sckId, mosiId, misoId
64 # ordered as uartId, txId, rxId