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 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 switch_eventA(self, switch): # look r a low-to-high on channel A if GPIO.input(self.pinA): # check pin B to see which was we are turning if not GPIO.input(self.pinB): self.encoder0Pos = self.encoder0Pos + 1 #cw direction = "cw" else: self.encoder0Pos = self.encoder0Pos - 1 #ccw direction = "ccw" else: # // must be a high-to-low edge on channel A if GPIO.input(self.pinB): self.encoder0Pos = self.encoder0Pos + 1 #cw direction = "cw" else: self.encoder0Pos = self.encoder0Pos - 1 #ccw direction = "ccw" print "A", self.encoder0Pos, direction if not self.busy: self.busy = True if self.encoder0Pos < -1: print "Trigger Counter Clockwise", self.clockwise if self.clockwise: self.clockwise() self.encoder0Pos = 0 if self.encoder0Pos > 1: print "Trigger CLockwise", self.counterclockwise if self.counterclockwise: self.counterclockwise() self.encoder0Pos = 0 self.busy = False else: print "- skiping roatry event"
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 waitForChange(self, pin): self.input(pin) startstate = GPIO.input(self.PINS[pin]['pin']) newstate = startstate print "Startt State = ", startstate while newstate == startstate: newstate = GPIO.input(self.PINS[pin]['pin']) print newstate time.sleep(.1)
def __init__(self): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) print GPIO.RPI_REVISION print GPIO.VERSION self.PINS = { 'tBacklight': { 'input': False, 'pin': 11, 'setup': False, 'inverse': False, 'pup': False }, 'pLeft': { 'input': True, 'pin': 10, 'setup': False, 'inverse': True, 'pup': True }, 'pRight': { 'input': True, 'pin': 9, 'setup': False, 'inverse': True, 'pup': True }, 'pOk': { 'input': True, 'pin': 27, 'setup': False, 'inverse': True, 'pup': True }, 'pRotaryB': { 'input': True, 'pin': 22, 'setup': False, 'inverse': True, 'pup': True }, 'pRotaryA': { 'input': True, 'pin': 17, 'setup': False, 'inverse': True, 'pup': True }, }
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 switch_eventB(self, switch): # look r a low-to-high on channel A if GPIO.input(self.pinB): # check pin B to see which was we are turning if GPIO.input(self.pinA): self.encoder0Pos = self.encoder0Pos + 1 #cw direction = "cw" else: self.encoder0Pos = self.encoder0Pos - 1 #ccw direction = "ccw" else: # // must be a high-to-l2ow edge on channel A if not GPIO.input(self.pinA): self.encoder0Pos = self.encoder0Pos + 1 #cw direction = "cw" else: self.encoder0Pos = self.encoder0Pos - 1 #ccw direction = "ccw" print "B", self.encoder0Pos, direction
def switch_event(self, switch): if GPIO.input(self.pinA): self.rotary_a = 1 else: self.rotary_a = 0 if GPIO.input(self.pinB): self.rotary_b = 1 else: self.rotary_b = 0 self.rotary_c = self.rotary_a ^ self.rotary_b new_state = self.rotary_a * 4 + self.rotary_b * 2 + self.rotary_c * 1 delta = (new_state - self.last_state) % 4 self.last_state = new_state event = 0 if delta == 1: if self.direction == self.CLOCKWISE: print "Clockwise" event = self.direction else: self.right = self.right + 1 self.left = 0 self.direction = self.CLOCKWISE elif delta == 3: if self.direction == self.ANTICLOCKWISE: print "Anticlockwise" event = self.direction else: self.left = self.left + 1 self.right = 0 self.direction = self.ANTICLOCKWISE if delta > 0: if not self.callback: print "callback", self.direction, self.left, self.right if self.left > 0: print "LEFT" self.left = 0 if self.right > 0: print "RIGHT" self.right = 0
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 configure(): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False)
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 turn_on(pin): GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH)
def turn_off(pin): GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.LOW)
def __init__(self): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) self.PINS = { 'swFerm': { 'input': True, 'pin': 5, 'setup': False, 'inverse': True, 'pup': True }, 'swHlt': { 'input': True, 'pin': 6, 'setup': False, 'inverse': True, 'pup': True }, 'swMash': { 'input': True, 'pin': 12, 'setup': False, 'inverse': True, 'pup': True }, 'swPump': { 'input': True, 'pin': 13, 'setup': False, 'inverse': True, 'pup': True }, 'swSparge': { 'input': True, 'pin': 19, 'setup': False, 'inverse': True, 'pup': True }, 'swBoil': { 'input': True, 'pin': 16, 'setup': False, 'inverse': True, 'pup': True }, 'tBacklight': { 'input': False, 'pin': 18, 'setup': False, 'inverse': False, 'pup': False }, 'pLeft': { 'input': True, 'pin': 10, 'setup': False, 'inverse': True, 'pup': True }, 'pRight': { 'input': True, 'pin': 9, 'setup': False, 'inverse': True, 'pup': True }, 'pOk': { 'input': True, 'pin': 27, 'setup': False, 'inverse': True, 'pup': True }, 'pRotaryA': { 'input': True, 'pin': 22, 'setup': False, 'inverse': True, 'pup': True }, 'pRotaryB': { 'input': True, 'pin': 17, 'setup': False, 'inverse': True, 'pup': True }, }
def input(pin): GPIO.setup(pin, GPIO.IN) return GPIO.input(pin)
def __init__(self): self.logging = 3 self.lastLog = ["", "", "", "", "", "", "", "", "", "", ""] GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) if os.path.exists("simulator"): self.simulator = True else: self.simulator = False self.PINS = { 'ssrZoneA': { 'input': False, 'pin': 19, 'setup': False, 'inverse': False, 'pup': True }, # turns on/off power through the SSR 'ssrZoneB': { 'input': False, 'pin': 23, 'setup': False, 'inverse': False, 'pup': True }, # turns on/off power through the SSR 'zoneA': { 'input': False, 'pin': 10, 'setup': False, 'inverse': True, 'pup': True }, # turns on/off power through the SSR 'zoneAuse': { 'input': False, 'pin': 13, 'setup': False, 'inverse': True, 'pup': True }, # NO of the relay for HLT # NC of the relay for Boiler 'extractor': { 'input': False, 'pin': 18, 'setup': False, 'inverse': True, 'pup': True }, 'recircfan': { 'input': False, 'pin': 12, 'setup': False, 'inverse': True, 'pup': True }, 'pump': #DEPRECATED, USED FOR RE-CIRCULATING FAN { 'input': False, 'pin': 12, 'setup': False, 'inverse': True, 'pup': True }, 'zoneB': { 'input': False, 'pin': 26, 'setup': False, 'inverse': True, 'pup': True }, # turns on/off power through the SSR 'zoneBuse': { 'input': False, 'pin': 24, 'setup': False, 'inverse': True, 'pup': True }, # NO of the relay for HLT # NC of the relay for Boiler 'fermHeat': { 'input': False, 'pin': 22, 'setup': False, 'inverse': True, 'pup': True }, 'fermCool': { 'input': False, 'pin': 16, 'setup': False, 'inverse': True, 'pup': True }, 'tempProbes': #DEPRECATED { 'input': False, 'pin': 5, 'setup': False, 'inverse': True, 'pup': True }, }