def setReadWrite(channelsToDown, channelsToUp): logging.info("switching rows/columns") for row in channelsToDown: #logging.info("Setting up channel " + str(row) + " to PUD_DOWN. ") GPIO.setup(row, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) for column in channelsToUp: #logging.info("Setting up channel " + str(column) + " to PUD_UP. ") #GPIO.setup(column, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(column, GPIO.OUT)
def row_changed(row): global rows GPIO.remove_event_detect(row) GPIO.setup(row, GPIO.OUT) for column in rows[row]: GPIO.setup(column, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Send signal from row to columns GPIO.output(row, 1) #sleep(0.05) # Read which column it was for column in rows[row]: columnValue = GPIO.input(column) if(columnValue): key = keys[str(row) + "," + str(column)] logging.info("row changed: " + str(row)) send_key(key) # Set row and columns back to original setup GPIO.setup(row, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) for column in rows[row]: GPIO.remove_event_detect(column) GPIO.setup(column, GPIO.OUT) GPIO.output(column, 1) GPIO.add_event_detect(row, GPIO.RISING, callback=row_changed)
def setRowEvents(row, mode): global bounceTime global rowsWithColumns if mode == KEYPAD_MODE_READROWS: # Set row to IN if GPIO.gpio_function(row) == GPIO.IN: logging.warning("Pin " + str(row) + " already set to IN") GPIO.setup(row, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # GPIO.add_event_detect(row, GPIO.RISING, callback=row_changed, bouncetime=bounceTime) # Set columns to OUT for column in rowsWithColumns[row]: if GPIO.gpio_function(column) == GPIO.OUT: logging.warning("Pin " + str(column) + " already set to OUT") else: GPIO.setup(column, GPIO.OUT, initial=1) else: # Set row to OUT # GPIO.remove_event_detect(row) if GPIO.gpio_function(row) == GPIO.OUT: logging.warning("Pin " + str(row) + " already set to OUT") else: GPIO.setup(row, GPIO.OUT, initial=1) # Set columns to IN for column in rowsWithColumns[row]: if GPIO.gpio_function(column) == GPIO.IN: logging.warning("Pin " + str(column) + " already set to IN") GPIO.setup(column, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def __init__(self, app): # initialize worker variables self.app = app self.requestOpening = False self.openingTimer = -1 self.requestTimer = 0 self.tagInfo = RfidTagInfo("", "") self.tagResetCount = 0 self.lock = False # setup gpio and set default (Low) GPIO.setmode(GPIO.BOARD) GPIO.setup(12,GPIO.OUT, initial=GPIO.HIGH) GPIO.output(12, GPIO.HIGH)
def __init__(self, app): # initialize worker variables self.LED_STATE_IDLE = 0 self.LED_STATE_ACCESS_GRANTED = 1 self.LED_STATE_ACCESS_DENIED = 2 self.LED_STATE_CLOSED = 3 self.first = True self.app = app self.requestOpening = False self.openingTimer = -1 self.requestTimer = 0 self.syncTimer = 0 self.ledStateTimer = 0 self.ledState = self.LED_STATE_IDLE self.ledStateCounter = 0 self.systemUp = True if config.NODE_SYNC_ON_STARTUP == True: self.forceSync = True else: self.forceSync = False self.forceBackup = False self.backupTimer = 0 self.cleanupTimer = 0 self.tagInfo = RfidTagInfo("", "") self.tagResetCount = 0 self.lock = False self.lastBackupTime = datetime.datetime.now() self.lastCleanupTime = datetime.datetime.now().replace(1910) self.lastSyncTime = datetime.datetime.now() # setup gpio and set default (Low) GPIO.setmode(GPIO.BOARD) GPIO.setup(GPIO_RELAY, GPIO.OUT, initial=GPIO.HIGH) GPIO.output(GPIO_RELAY, GPIO.HIGH) GPIO.setup(GPIO_LED_GREEN, GPIO.OUT, initial=GPIO.LOW) GPIO.output(GPIO_LED_GREEN, GPIO.LOW) GPIO.setup(GPIO_LED_YELLOW, GPIO.OUT, initial=GPIO.LOW) GPIO.output(GPIO_LED_YELLOW, GPIO.LOW) GPIO.setup(GPIO_LED_RED, GPIO.OUT, initial=GPIO.LOW) GPIO.output(GPIO_LED_RED, GPIO.LOW)
logging.info("adding " + option + " as " + str(row) + "," + str(column) + "") keys[config.get("gpiokeymapping", option)] = option if row not in rowsWithColumns: rowsWithColumns[row] = [column] else: rowsWithColumns[row].append(column) if column not in columns: columns.append(column) for row in rowsWithColumns: setRowEvents(row, KEYPAD_MODE_READROWS) GPIO.setup(hoorn, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) hoorn_previous_state = GPIO.input(hoorn) # GPIO.add_event_detect(hoorn, GPIO.BOTH, callback=phonePickedUp) threadRows = threading.Thread(target=listenToRows) threadHoorn = threading.Thread(target=listenToHoorn) threadRows.start() threadHoorn.start() def cleanup(): logging.info("Stopping threads...") global run run = False
GPIO.add_event_detect(row, GPIO.RISING, callback=row_changed) gpiokeymappings = config.options("gpiokeymapping") # Read all GPIO key mappings and ad them to the keys dictionary for option in gpiokeymappings: row = int(config.get("gpiokeymapping", option).split(",")[0]) column = int(config.get("gpiokeymapping", option).split(",")[1]) # define key for later retrieval keys[config.get("gpiokeymapping", option)] = option logging.info("setting up " + option + " as " + str(row) + "," + str(column) + "") if row not in rows: rows[row] = [column] GPIO.setup(row, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(row, GPIO.RISING, callback=row_changed) else: rows[row].append(column) if column not in columns: columns.append(column) GPIO.setup(column, GPIO.OUT) GPIO.output(column, 1) logging.info("Setting up Kodi client") host = config.get("xbmc", "host") port = config.getint("xbmc", "port") logging.info("host: " + str(host))
def setup(self): GPIO.setup(self.Pin, self.Type)
def __init__(self, context): gpio.setmode(gpio.BCM) gpio.setup(context.Config["gpio"]["hoorn"], gpio.IN, pull_up_down=gpio.PUD_DOWN)