def enable_rx(self): """Enable RX, set up GPIO and add event detection.""" if self.tx_enabled: _LOGGER.error("TX is enabled, not enabling RX") return False if not self.rx_enabled: self.rx_enabled = True GPIO.setup(self.gpio, GPIO.IN) GPIO.add_event_detect(self.gpio, GPIO.BOTH) GPIO.add_event_callback(self.gpio, self.rx_callback) _LOGGER.debug("RX enabled") return True
def configGPIO(pin): if not settings['triggerActive']: if not settings['SIMULATE']: import CHIP_IO.GPIO as GPIO # Config GPIO pin for pull down # and detection of rising edge GPIO.cleanup(pin) GPIO.setup(pin, GPIO.IN, GPIO.PUD_DOWN) GPIO.add_event_detect(pin, GPIO.RISING) GPIO.add_event_callback(pin, S0Trigger) settings['triggerActive'] = True logMsg("Setting up S0-Logger on " + pin) else: logMsg("Trigger already active on " + pin)
config = SafeConfigParser() config.read(sys.argv[1]) sensor_pin = "XIO-P1" #sensor_pin = config.getint('main', 'SENSOR_PIN') begin_seconds = config.getint('main', 'SECONDS_TO_START') end_seconds = config.getint('main', 'SECONDS_TO_END') pushbullet_api_key = config.get('pushbullet', 'API_KEY') pushbullet_api_key2 = config.get('pushbullet', 'API_KEY2') start_message = config.get('main', 'START_MESSAGE') end_message = config.get('main', 'END_MESSAGE') twitter_api_key = config.get('twitter', 'api_key') twitter_api_secret = config.get('twitter', 'api_secret') twitter_access_token = config.get('twitter', 'access_token') twitter_access_token_secret = config.get('twitter', 'access_token_secret') #slack_api_token = config.get('slack', 'api_token') #slack_webhook = config.get('slack','webhook_url') iftt_maker_channel_event = config.get('iftt', 'maker_channel_event') iftt_maker_channel_key = config.get('iftt', 'maker_channel_key') send_alert(config.get('main', 'BOOT_MESSAGE')) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(sensor_pin, GPIO.RISING) GPIO.add_event_callback(sensor_pin, vibrated) print 'Running config file {} monitoring GPIO pin {}'\ .format(sys.argv[1], str(sensor_pin)) threading.Timer(1, heartbeat).start()
def register_callbacks(self, turn=None, press=None): self.turn_cb = turn self.press_cb = press GPIO.add_event_detect(self.intr, GPIO.FALLING) GPIO.add_event_callback(self.intr, self._call_callbacks)
GPIO.output(D_PIN, GPIO.HIGH) time.sleep(0.5) GPIO.output(D_PIN, GPIO.LOW) ## Setup GPIOs GPIO.toggle_debug() try: # Window Sensors GPIO.setup("CSID0", GPIO.OUT) # Door Sensors GPIO.setup("CSID0", GPIO.OUT) # Motion Sensors GPIO.setup("CSID0", GPIO.OUT) # Input GPIO.setup("XIO-P0", GPIO.IN) # Motion detector, 5v GPIO.setup("XIO-P0", GPIO.IN) GPIO.add_event_detect("XIO-P0", GPIO.FALLING) GPIO.add_event_callback("XIO-P0", motion_callback) except: print "Error" # Clean up every exported GPIO Pin finally: GPIO.cleanup()