def timer_cycle(self): self.thr = threading.Timer(1, BackgroundWorker.timer_cycle,[self]) self.thr.start() self.requestTimer += 1 if self.requestTimer >= 2: self.requestTimer = 0 self.resetTagInfo() self.readRFIDTag() #print "Check for opening request" if self.requestOpening == True: self.requestOpening = False self.openingTimer = 0; print "Opening request" if self.openingTimer >= 0: print "Opened door cycle" + "(" + ")" GPIO.output(12, GPIO.LOW) self.openingTimer += 1 if self.openingTimer >= 7: self.openingTimer = -1 print "Closing door" GPIO.output(12, GPIO.HIGH)
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 output(self, value): self.State = value if (value): print("BEEP") else: print("----") GPIO.output(self.Pin, value)
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)
def open_the_door(self): while True: print "Openening door" time.sleep(1.0) GPIO.output(GPIO_RELAY, GPIO.LOW) GPIO.output(GPIO_LED_GREEN, GPIO.HIGH)
def led_cycle(self): if self.systemUp == True: GPIO.output(GPIO_LED_YELLOW, GPIO.HIGH) else: GPIO.output(GPIO_LED_YELLOW, GPIO.LOW) if self.ledState == self.LED_STATE_IDLE: self.ledStateCounter = 0 if self.ledState == self.LED_STATE_ACCESS_GRANTED: if self.ledStateCounter % 2 == 0: GPIO.output(GPIO_LED_GREEN, GPIO.HIGH) else: GPIO.output(GPIO_LED_GREEN, GPIO.LOW) self.ledStateCounter += 1 if self.ledStateCounter > 15: self.ledState = self.LED_STATE_IDLE self.ledStateCounter = 0 if self.ledState == self.LED_STATE_ACCESS_DENIED: if self.ledStateCounter % 2 == 0: GPIO.output(GPIO_LED_RED, GPIO.HIGH) else: GPIO.output(GPIO_LED_RED, GPIO.LOW) self.ledStateCounter += 1 if self.ledStateCounter > 15: self.ledState = self.LED_STATE_IDLE self.ledStateCounter = 0 if self.ledState == self.LED_STATE_CLOSED: self.ledState = self.LED_STATE_IDLE self.ledStateCounter = 0 GPIO.output(GPIO_LED_RED, GPIO.LOW) GPIO.output(GPIO_LED_GREEN, GPIO.LOW)
0, "Internal", ) db.session.add(logentry) db.session.commit() # print "Check for opening request" if self.requestOpening == True: self.requestOpening = False self.openingTimer = 0 print "Opening request" if self.openingTimer >= 0: if self.openingTimer == 0: print "Openening door" GPIO.output(GPIO_RELAY, GPIO.LOW) self.openingTimer += 1 if self.openingTimer >= 16: self.openingTimer = -1 print "Closing door" GPIO.output(GPIO_RELAY, GPIO.HIGH) self.ledState = self.LED_STATE_CLOSED else: GPIO.output(GPIO_RELAY, GPIO.HIGH) self.ledStateTimer += 1 if self.ledStateTimer >= 0: self.ledStateTimer = 0 try: self.led_cycle()
# 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)) logging.info("port: " + str(port)) # Create an XBMCClient object and connect (needed because we don't run as the same user as Kodi) xbmc = XBMCClient("OldPhone", addonFolder + "/icon.png") xbmc.connect() #GPIO.setup(hoorn, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #GPIO.add_event_detect(hoorn, GPIO.RISING, callback=picked_up)
def open_the_door(self): while (True): print "Openening door" time.sleep(1.0) GPIO.output(GPIO_RELAY, GPIO.LOW) GPIO.output(GPIO_LED_GREEN, GPIO.HIGH)
'*****@*****.**', 'Error: ' + str(traceback.format_exc()), 'Error occured', 'L1', 0, 'Internal') db.session.add(logentry) db.session.commit() # print "Check for opening request" if self.requestOpening == True: self.requestOpening = False self.openingTimer = 0 print "Opening request" if self.openingTimer >= 0: if self.openingTimer == 0: print "Openening door" GPIO.output(GPIO_RELAY, GPIO.LOW) self.openingTimer += 1 if self.openingTimer >= 16: self.openingTimer = -1 print "Closing door" GPIO.output(GPIO_RELAY, GPIO.HIGH) self.ledState = self.LED_STATE_CLOSED else: GPIO.output(GPIO_RELAY, GPIO.HIGH) self.ledStateTimer += 1 if self.ledStateTimer >= 0: self.ledStateTimer = 0 try: self.led_cycle()
def output(self, value): if (self.Type == GPIO.OUT): GPIO.output(self.Pin, value)
def debugOutput(self, value): self.__Value = value GPIO.output(self.Pin, value)