Exemplo n.º 1
0
 def add_event_detect(dio_number, callback):
     """ Wraps around the GPIO.add_event_detect function
     :param dio_number: DIO pin 0...5
     :param callback: The function to call when the DIO triggers an IRQ.
     :return: None
     """
     GPIO.add_event_detect(dio_number, GPIO.RISING, callback=callback)
Exemplo n.º 2
0
 def add_events(cb_dio0, cb_dio1, cb_dio2, cb_dio3, cb_dio4, cb_dio5, switch_cb=None):
     BOARD.add_event_detect(BOARD.DIO0, callback=cb_dio0)
     BOARD.add_event_detect(BOARD.DIO1, callback=cb_dio1)
     BOARD.add_event_detect(BOARD.DIO2, callback=cb_dio2)
     BOARD.add_event_detect(BOARD.DIO3, callback=cb_dio3)
     # the modtronix inAir9B does not expose DIO4 and DIO5
     if switch_cb is not None:
         GPIO.add_event_detect(BOARD.SWITCH, GPIO.RISING, callback=switch_cb, bouncetime=300)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def main():
    logging.basicConfig(level=logging.INFO,
                        format='%(levelname)s: %(message)s')

    GPIO.cleanup(pin)
    GPIO.setup(pin, GPIO.IN)

    # Add Callback for Both Edges using the add_event_detect() method
    GPIO.add_event_detect(pin, GPIO.FALLING, doorbell_handler)

    try:
        while (not time.sleep(5)):
            print("watching " + pin)
    except:
        GPIO.cleanup(pin)
Exemplo n.º 6
0
	def run(self):
		# GPIO.toggle_debug()

		try:
			# reset all
			ioutil.unexport_all()
			# GPIO.cleanup()  -- broken?

			# led
			GPIO.setup(LED, GPIO.OUT)
			GPIO.output(LED, GPIO.LOW)

			# handset
			GPIO.setup(HANDSET, GPIO.IN, pull_up_down=GPIO.PUD_UP, initial=1)
			GPIO.add_event_detect(HANDSET, GPIO.BOTH, self.off_hook)

			# rotary dial
			GPIO.setup(ROT_ENGAGED, GPIO.IN, pull_up_down=GPIO.PUD_UP)
			GPIO.add_event_detect(ROT_ENGAGED, GPIO.BOTH, self.rotary_engaged)
			GPIO.setup(ROT_PULSE, GPIO.IN, pull_up_down=GPIO.PUD_UP)
			GPIO.add_event_detect(ROT_PULSE, GPIO.FALLING, self.count_pulse)
		except Exception as e:
			logging.exception("exception encountered")

		GPIO.output(LED, GPIO.LOW) # signal process has started successfully

		# busy loop
		while True:
			time.sleep(0.02)
Exemplo n.º 7
0
 def __init__(self):
     self.nom = ''
     # Pin configuration.
     self.LS = "XIO-P2"  #left side
     self.RS = "XIO-P3"  #right side
     self.TL = "XIO-P4"  #top left
     self.MD = "XIO-P5"  #top mid
     self.TR = "XIO-P6"  #top right
     self.lookup = {
         "XIO-P2": "leftside",
         "XIO-P3": "rightside",
         "XIO-P4": "topleft",
         "XIO-P5": "mid",
         "XIO-P6": "topright"
     }
     # array makes setup a bit easier:
     self.buttons = [self.RS, self.LS, self.TL, self.MD, self.TR]
     for b in self.buttons:
         # Setup input for pin
         GPIO.setup(b, GPIO.IN)
         # Setup edge detects for pins. Rising and Both have different values for de-bounce time, for testing.
         GPIO.add_event_detect(b, GPIO.FALLING, self.fallcall, 300)
Exemplo n.º 8
0
 def __init__(self, pinA, pinB, button, callback):
     self.pinA = pinA
     self.pinB = pinB
     self.button = button
     self.callback = callback
     GPIO.setmode(GPIO.BCM)
     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)
     GPIO.add_event_detect(self.pinA, GPIO.FALLING, callback=self.switch_event)
     GPIO.add_event_detect(self.pinB, GPIO.FALLING, callback=self.switch_event)
     GPIO.add_event_detect(self.button, GPIO.BOTH, callback=self.button_event, bouncetime=200)
Exemplo n.º 9
0
        start = time.time()
        print "down " + channel
    bcount = bcount + 1
    print "CALLBACK FALL " + channel


def risecall(channel):
    print "CALLBACK RISE " + channel


def bothcall(channel):
    print "CALLBACK BOTH " + channel


# Setup edge detects for pins. Rising and Both have different values for de-bounce time, for testing.
GPIO.add_event_detect(pinA, GPIO.FALLING, fallcall)
GPIO.add_event_detect(pinB, GPIO.RISING, risecall, 200)
GPIO.add_event_detect(pinC, GPIO.BOTH, bothcall, 400)
GPIO.add_event_detect(pinD, GPIO.FALLING, fallcall)
GPIO.add_event_detect(pinE, GPIO.FALLING, fallcall)
GPIO.add_event_detect(pinF, GPIO.FALLING, fallcall)
GPIO.add_event_detect(pinG, GPIO.FALLING, fallcall)
GPIO.add_event_detect(pinH, GPIO.FALLING, fallcall)

# make a loop
try:
    while True:
        print "press a button..."
        time.sleep(1)

except KeyboardInterrupt:
Exemplo n.º 10
0
# VERIFY SIMPLE FUNCTIONALITY
print "VERIFY SIMPLE FUNCTIONALITY"

print "READING XIO-PI"
GPIO.output("CSID0", GPIO.HIGH)
print "HIGH", GPIO.input("XIO-P0")

GPIO.output("CSID0", GPIO.LOW)
print "LOW", GPIO.input("XIO-P0")

# ==============================================
# EDGE DETECTION - AP-EINT1
print "SETTING UP EDGE DETECTION ON AP-EINT1"
GPIO.setup("AP-EINT1", GPIO.IN)
GPIO.add_event_detect("AP-EINT1",GPIO.FALLING)

print "VERIFYING EDGE DETECT"
f = open("/sys/class/gpio/gpio193/edge","r")
edge = f.read()
f.close()
print "EDGE: %s" % edge
GPIO.remove_event_detect("AP-EINT1")

# ==============================================
# EDGE DETECTION - AP-EINT3
print "SETTING UP EDGE DETECTION ON AP-EINT3"
GPIO.setup("AP-EINT3", GPIO.IN)
GPIO.add_event_detect("AP-EINT3",GPIO.FALLING)

print "VERIFYING EDGE DETECT"
Exemplo n.º 11
0
GPIO.setup("XIO-P2", GPIO.IN)
GPIO.setup("U14_31", GPIO.OUT)  # CSID0

print("READING XIO-P2")
GPIO.output("CSID0", GPIO.HIGH)
assert(GPIO.input("XIO-P2") == GPIO.HIGH)

GPIO.output("CSID0", GPIO.LOW)
print "LOW", GPIO.input("GPIO1")
assert(GPIO.input("GPIO1") == GPIO.LOW)

# ==============================================
# EDGE DETECTION - AP-EINT1
print("\nSETTING UP RISING EDGE DETECTION ON AP-EINT1")
GPIO.setup("AP-EINT1", GPIO.IN)
GPIO.add_event_detect("AP-EINT1", GPIO.RISING, myfuncallback)
print("VERIFYING EDGE DETECT WAS SET PROPERLY")
f = open("/sys/class/gpio/gpio193/edge", "r")
edge = f.read()
f.close()
assert(edge == "rising\n")
GPIO.remove_event_detect("AP-EINT1")

# ==============================================
# EDGE DETECTION - AP-EINT3
print("\nSETTING UP BOTH EDGE DETECTION ON AP-EINT3")
GPIO.setup("AP-EINT3", GPIO.IN)
GPIO.add_event_detect("AP-EINT3", GPIO.BOTH, myfuncallback)
print("VERIFYING EDGE DETECT WAS SET PROPERLY")
f = open("/sys/class/gpio/gpio35/edge", "r")
edge = f.read()
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
	def after_setup(self):
		# threaded detection of button press
		GPIO.add_event_detect(self.__pconfig['button'], GPIO.FALLING, callback=self.detect_button, bouncetime=100)
Exemplo n.º 14
0
    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()
Exemplo n.º 15
0
def gpio_setup():
    GPIO.setup(BEAM_1, GPIO.IN)
    GPIO.add_event_detect(BEAM_1, GPIO.RISING)
    GPIO.setup(BEAM_2, GPIO.IN)
    GPIO.add_event_detect(BEAM_2, GPIO.RISING)
Exemplo n.º 16
0
GPIO.setup("XIO-P2", GPIO.IN)
GPIO.setup("U14_31", GPIO.OUT)  # CSID0

print("READING XIO-P2")
GPIO.output("CSID0", GPIO.HIGH)
assert (GPIO.input("XIO-P2") == GPIO.HIGH)

GPIO.output("CSID0", GPIO.LOW)
print "LOW", GPIO.input("GPIO1")
assert (GPIO.input("GPIO1") == GPIO.LOW)

# ==============================================
# EDGE DETECTION - AP-EINT1
print("\nSETTING UP RISING EDGE DETECTION ON AP-EINT1")
GPIO.setup("AP-EINT1", GPIO.IN)
GPIO.add_event_detect("AP-EINT1", GPIO.RISING, myfuncallback)
print("VERIFYING EDGE DETECT WAS SET PROPERLY")
f = open("/sys/class/gpio/gpio193/edge", "r")
edge = f.read()
f.close()
assert (edge == "rising\n")
GPIO.remove_event_detect("AP-EINT1")

# ==============================================
# EDGE DETECTION - AP-EINT3
print("\nSETTING UP BOTH EDGE DETECTION ON AP-EINT3")
GPIO.setup("AP-EINT3", GPIO.IN)
GPIO.add_event_detect("AP-EINT3", GPIO.BOTH, myfuncallback)
print("VERIFYING EDGE DETECT WAS SET PROPERLY")
f = open("/sys/class/gpio/gpio35/edge", "r")
edge = f.read()
Exemplo n.º 17
0
import CHIP_IO.GPIO as GPIO
import time


# Define callback function
def mycallback(channel):
    # Sample is just to print something, but other logic could go here
    print("Sensor Touch Activated!")


# GPIO3 = XIO-P4, using PocketCHIP nomenclature
GPIO.setup("GPIO1", GPIO.IN)
# Trigger when we go from LOW to HIGH to match code above
GPIO.add_event_detect("GPIO1", GPIO.RISING, mycallback)

# Dummy loop to keep the script alive
dead = False
while not dead:
    try:
        time.sleep(0.2)
    except KeyboardInterrupt:
        dead = True

# Cleanup
GPIO.remove_event_detect("GPIO1")
GPIO.cleanup()
Exemplo n.º 18
0
            processing_thread = threading.Thread(target=do_processing)
            processing_thread.start()


#Setup "record" button
pin_record = "XIO-P4"
pin_record_led = 'XIO-P6'

GPIO.setup(pin_record, GPIO.IN)
GPIO.setup(pin_record_led, GPIO.OUT)

# Specify pull up/pull down settings on a pin
#GPIO.setup(pin_record, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Add Callback for Both Edges using the add_event_detect() method
GPIO.add_event_detect(pin_record, GPIO.BOTH, pin_record_callback)

running = True

try:
    #main state
    while running:
        print("ready, acquiring recording_condition...")
        recording_condition.acquire()
        print("acquired...")
        recording_condition.wait()  # sleep until item becomes available
        print("recording notify receieved...")

finally:
    GPIO.cleanup()
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
import subprocess
import datetime
import serial
import random
import psutil
import sys
import os

GPIO.cleanup()
sing_channel = "XIO-P1"
record_channel = "XIO-P7"

GPIO.setup(record_channel, GPIO.IN)
GPIO.setup(sing_channel, GPIO.IN)

GPIO.add_event_detect(record_channel, GPIO.RISING)
GPIO.add_event_detect(sing_channel, GPIO.RISING)

# hardcoded file locations
codeLoc = "/home/chip/mewsician/"
audioLoc = "/home/chip/audio/"
queue = audioLoc + "queue"

# auth passed in from (../start)
authentication = sys.argv[1]
recording = False
listening = False
singing = False
play_pid = None
fname = None
bname = None
Exemplo n.º 21
0
 def after_setup(self):
     # threaded detection of button press
     GPIO.add_event_detect(self.__pconfig['button'],
                           GPIO.FALLING,
                           callback=self.detect_button,
                           bouncetime=100)
Exemplo n.º 22
0
        GPIO.output(LED1, ON)
        if updateScore(0):
            blink(FLASH_TIME, FLASH_COUNT, LED1)
        else:
            GPIO.output(LED1, OFF)
    else:
        printlog("TEAM 2 GOAL!")
        GPIO.output(LED2, ON)
        if updateScore(1):
            blink(FLASH_TIME, FLASH_COUNT, LED2)
        else:
            GPIO.output(LED2, OFF)
    flashing = False


GPIO.add_event_detect(BTN1, GPIO.FALLING, buttoncallback)
GPIO.add_event_detect(BTN2, GPIO.FALLING, buttoncallback)

printlog("Awaiting Button press")

try:
    GPIO.wait_for_edge(BTNRESET, GPIO.FALLING)
    printlog("Reset button pressed")
    blink(0.1, 20, LED1, LED2)
    os.system("reboot")
except:
    logging.exception("Exiting reset button loop:")
    GPIO.cleanup()

printlog("Cleaning up")
Exemplo n.º 23
0
 def set_callbacks(self, callback=None):
     GPIO.add_event_detect(self.pin_dt, GPIO.BOTH, callback=callback)
     GPIO.add_event_detect(self.pin_clk, GPIO.BOTH, callback=callback)