def input(self, pin): if not self.PINS.has_key(pin): sys.stderr.write("pin %s does not exist\n" % (pin)) else: if not self.PINS[pin]['setup']: if not self.PINS[pin]['input']: sys.stderr.write("pin %s set as an output pin\n" % (pin)) else: if self.PINS[pin]['pup']: GPIO.setup(self.PINS[pin]['pin'], 1, pull_up_down=GPIO.PUD_UP) else: GPIO.setup(self.PINS[pin]['pin'], 1) if os.path.exists("ipc/manual_%s" % (pin)): os.unlink("ipc/manual_%s" % (pin)) print "file existed returning True", pin return True state = GPIO.input(self.PINS[pin]['pin']) # print "RAW STATE",self.PINS[pin]['pin'],state if self.PINS[pin]['inverse']: if state == True: return False else: return True return state
def input(self, pin): if not self.PINS.has_key(pin): sys.stderr.write("pin %s does not exist\n" % (pin)) else: if not self.PINS[pin]['setup']: if not self.PINS[pin]['input']: sys.stderr.write("pin %s set as an output pin\n" % (pin)) else: if self.PINS[pin]['pup']: GPIO.setup(self.PINS[pin]['pin'], 1, pull_up_down=GPIO.PUD_UP) else: GPIO.setup(self.PINS[pin]['pin'], 1) state = GPIO.input(self.PINS[pin]['pin']) if self.PINS[pin]['inverse']: if state == True: return False else: return True # self._log("gpio.input %s %s" %(pin,state),importance=1) return state
def output(self, pin, state=-1): if not self.PINS.has_key(pin): sys.stderr.write("pin %s does not exist state %s\n" % (pin, state)) else: if not self.PINS[pin]['setup']: if self.PINS[pin]['input']: sys.stderr.write("pin %s set as an input pin\n" % (pin)) else: GPIO.setup(self.PINS[pin]['pin'], 0) if self.simulator and state: o = open("ipc/pin%s" % (pin), "w") o.close() if self.simulator and not state: try: os.remove("ipc/pin%s" % (pin)) except: pass if self.PINS[pin]['inverse']: if state == 1: state = 0 else: state = 1 GPIO.output(self.PINS[pin]['pin'], state) self.PINS[pin]['state'] = state
def output(self, pin, state=-1): if not self.PINS.has_key(pin): sys.stderr.write("pin %s does not exist\n" % (pin)) else: if not self.PINS[pin]['setup']: if self.PINS[pin]['input']: sys.stderr.write("pin %s set as an input pin\n" % (pin)) else: GPIO.setup(self.PINS[pin]['pin'], 0) if self.PINS[pin]['inverse']: if state == 1: state = 0 else: state = 1 GPIO.output(self.PINS[pin]['pin'], state) self.PINS[pin]['state'] = state
def __init__(self): self.pinB = 11 self.pinA = 13 GPIO.setmode(GPIO.BOARD) # The following lines enable the internal pull-up resistors # on version 2 (latest) boards GPIO.setwarnings(False) GPIO.setup(self.pinA, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(self.pinB, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(self.button, GPIO.IN, pull_up_down=GPIO.PUD_UP self.encoder0Pos = 0 self.busy = False self.clockwise = None self.counterclockwise = None # Add event detection to the GPIO inputs GPIO.add_event_detect(self.pinA, GPIO.FALLING, callback=self.switch_eventA)
def __init__(self, callback): self.pinA = 10 # was 13 self.pinB = 9 #was 11 # self.button=27 # was 15 self.callback = callback GPIO.setmode(GPIO.BOARD) self.left = 0 self.right = 0 # The following lines enable the internal pull-up resistors # on version 2 (latest) boards GPIO.setwarnings(False) GPIO.setup(self.pinA, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(self.pinB, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(self.button, GPIO.IN, pull_up_down=GPIO.PUD_UP # Add event detection to the GPIO inputs GPIO.add_event_detect(self.pinA, GPIO.FALLING, callback=self.switch_event) GPIO.add_event_detect(self.pinB, GPIO.FALLING, callback=self.switch_event) return
def input(pin): GPIO.setup(pin, GPIO.IN) return GPIO.input(pin)
def turn_off(pin): GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.LOW)
def turn_on(pin): GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH)