Exemplo n.º 1
0
def initial_setup(): # Starts first to build live dictionary
    # Clean up GPIO at start
    GPIO.cleanup()

    # Read the config file to get devices and settings
    config.read(configPath)

    # Get the zone count from config to add to live dictionary
    zones = config.get('zones', 'zone_count')

    # loop through all devices in the config
    for device in config.sections()[1:]:
        # Nested dictionary for storing device options in the device dictionary
        deviceData = {}
        # loop through all device options for the current device
        for deviceOptions in config.options(device):
            # Add device options to deviceData dictionary
            deviceData[deviceOptions] = config.get(device, deviceOptions)
        # Add device and deviceData to live dictionary
        pass_data['devices'][device] = deviceData
        # Add a device dictionary to track the state of the device
        pass_data['devices'][device]['state'] = 'Off'
    # Add the number of zones from the config file
    pass_data['zone_count'] = (int(zones))
    # Setup devices after building live dictionary
    setup_devices()
Exemplo n.º 2
0
 def act(self, client_address, state, name):
     print "State", state, "from client @", client_address
     GPIO.setmode(GPIO.BOARD)  ## Use board pin numbering
     GPIO.setup(str(sys.argv[3]), GPIO.OUT)  ## Setup GPIO Pin to OUTPUT
     GPIO.output(str(sys.argv[3]), not state)  ## State is true/false
     GPIO.cleanup(str(sys.argv[3]))
     return True
Exemplo n.º 3
0
 def test_setup_expanded_gpio(self):
     GPIO.setup("XIO-P1", GPIO.OUT)
     base = GPIO.get_gpio_base() + 1
     gfile = '/sys/class/gpio/gpio%d' % base
     assert os.path.exists(gfile)
     GPIO.cleanup()
     assert not os.path.exists(gfile)
Exemplo n.º 4
0
 def test_setup_expanded_gpio(self):
     GPIO.setup("XIO-P1", GPIO.OUT)
     base = GPIO.get_gpio_base() + 1
     gfile = '/sys/class/gpio/gpio%d' % base
     assert os.path.exists(gfile)
     GPIO.cleanup()
     assert not os.path.exists(gfile)
Exemplo n.º 5
0
 def act(self, client_address, state, name):
     print "State", state, "from client @", client_address
     GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
     GPIO.setup(str(sys.argv[3]), GPIO.OUT)   ## Setup GPIO Pin to OUTPUT
     GPIO.output(str(sys.argv[3]), not state) ## State is true/false
     GPIO.cleanup(str(sys.argv[3]))
     return True
Exemplo n.º 6
0
def GPIOtest():

    initGPIO132()
    initGPIO133()
    readADC("CSID0","CSID1",64)
    GPIO.cleanup("CSID0")
    GPIO.cleanup("CSID1")
Exemplo n.º 7
0
def sig_handler(signal, frame):
    OM.unload("PWM0")
    GPIO.cleanup()
    PWM.cleanup()
    SPWM.cleanup()
    UT.disable_1v8_pin()
    sys.exit(0)
Exemplo n.º 8
0
def transmit_code(code):
    '''Transmit a chosen code string using the GPIO transmitter'''
    #    GPIO.setmode(GPIO.BCM)
    GPIO.setup(TRANSMIT_PIN, GPIO.OUT)
    for t in range(NUM_ATTEMPTS):
        for i in code:
            if i == '1':
                GPIO.output(TRANSMIT_PIN, 1)
                time.sleep(.00055)
                GPIO.output(TRANSMIT_PIN, 0)
            elif i == '2':
                GPIO.output(TRANSMIT_PIN, 0)
                time.sleep(.00011)
                GPIO.output(TRANSMIT_PIN, 1)
            elif i == '3':
                GPIO.output(TRANSMIT_PIN, 0)
                time.sleep(.000303)
                GPIO.output(TRANSMIT_PIN, 1)
            elif i == '4':
                GPIO.output(TRANSMIT_PIN, 1)
                time.sleep(.00011)
                GPIO.output(TRANSMIT_PIN, 0)
            elif i == '5':
                GPIO.output(TRANSMIT_PIN, 1)
                time.sleep(.00029)
                GPIO.output(TRANSMIT_PIN, 0)
            else:
                continue
        GPIO.output(TRANSMIT_PIN, 0)
    GPIO.cleanup()
Exemplo n.º 9
0
 def cleanup(self):
     """Disable TX and RX and clean up GPIO."""
     if self.tx_enabled:
         self.disable_tx()
     if self.rx_enabled:
         self.disable_rx()
     _LOGGER.debug("Cleanup")
     GPIO.cleanup()
Exemplo n.º 10
0
	def setup(self):
		GPIO.setwarnings(False)
		GPIO.cleanup()
		GPIO.setup(self.__pconfig['button'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
		GPIO.setup(self.__pconfig['rec_light'], GPIO.OUT) # lights'], GPIO.OUT)
		GPIO.setup(self.__pconfig['plb_light'], GPIO.OUT) # lights'], GPIO.OUT)
		GPIO.output(self.__pconfig['rec_light'], GPIO.LOW)
		GPIO.output(self.__pconfig['plb_light'], GPIO.LOW)
Exemplo n.º 11
0
def RestApp(host="0.0.0.0", port=1883, debug=False):
    try:
        app.run(host=host, port=port, debug=debug)
    except KeyboardInterrupt:
        GPIO.cleanup()
        PWM.cleanup()
        SPWM.cleanup()
        UT.disable_1v8_pin()
        sys.exit(0)
Exemplo n.º 12
0
def blinkLed(blinks):
    GPIO.setup("XIO-P0", GPIO.OUT)
    for j in range(1, blinks):
        GPIO.output("XIO-P0", GPIO.LOW)
        time.sleep(0.05)
        GPIO.output("XIO-P0", GPIO.HIGH)
        time.sleep(0.05)
    GPIO.cleanup()
    return
Exemplo n.º 13
0
    def api_digital_cleanup(self):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True
        resp["message"] = "All GPIO pins cleaned up"

        self.PINS_IN_USE = []
        GPIO.cleanup()

        return jsonify(resp)
 def test_input(self):
     GPIO.setup("CSID6", GPIO.IN)
     #returned as an int type
     input_value = GPIO.input("CSID6")
     #value read from the file will have a \n new line
     value = open('/sys/class/gpio/gpio138/value').read()
     assert int(value) == input_value
     # time.sleep(30) - what is this for?
     GPIO.cleanup()
Exemplo n.º 15
0
 def test_input(self):
     GPIO.setup("CSID6", GPIO.IN)
     #returned as an int type
     input_value = GPIO.input("CSID6")
     #value read from the file will have a \n new line
     value = open('/sys/class/gpio/gpio138/value').read()
     assert int(value) == input_value
     time.sleep(30)
     GPIO.cleanup()
Exemplo n.º 16
0
 def setup(self):
     GPIO.setwarnings(False)
     GPIO.cleanup()
     GPIO.setup(self.__pconfig['button'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
     GPIO.setup(self.__pconfig['rec_light'],
                GPIO.OUT)  # lights'], GPIO.OUT)
     GPIO.setup(self.__pconfig['plb_light'],
                GPIO.OUT)  # lights'], GPIO.OUT)
     GPIO.output(self.__pconfig['rec_light'], GPIO.LOW)
     GPIO.output(self.__pconfig['plb_light'], GPIO.LOW)
Exemplo n.º 17
0
    def __init__(self, channel, initial_state=False, open_value=True):
        self.chnl = channel

        init_val = 0
        if initial_state:
            init_val = 1

        self.ov = open_value

        gpio.cleanup(channel)
        gpio.setup(channel, gpio.OUT, initial=init_val)
Exemplo n.º 18
0
 def __init__(self, clk, dio):
     self.clk = clk
     self.dio = dio
     self.brightness = 0x0f
     
     GPIO.cleanup()
     self.SetupGpio(self.clk, GPIO.OUT)
     self.SetupGpio(self.dio, GPIO.OUT)
     GPIO.output(self.clk, GPIO.LOW)
     GPIO.output(self.dio, GPIO.LOW)
     GPIO.direction(self.clk, GPIO.IN)
     GPIO.direction(self.dio, GPIO.IN)
Exemplo n.º 19
0
    def GET(self, arguments):
        try:
            GPIO.cleanup()
            GPIO.setup("XIO-P0", GPIO.OUT)

            print "Toggling the door...."
            GPIO.output("XIO-P0", GPIO.HIGH)
            time.sleep(.5)
            GPIO.output("XIO-P0", GPIO.LOW)
            GPIO.cleanup()
            return "<html><body>Door was toggled!</body></html>"
        except:
            return "<html><bod>Error calling GPIO pin</bod></html>"
    def run(self, handleInterrupt=False, handleUpdate=False):
        while True:
            try:
                if handleInterrupt:
                    if GPIO.input(self._intPin) == 0:
                        self.handleInterrupt()
                if handleUpdate:
                    self.handleUpdate()

            except KeyboardInterrupt:
                self._tft.displayOn(False)
                GPIO.cleanup()
                raise
Exemplo n.º 21
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.º 22
0
    def setup(self):
        if not self.initialized:
            # reset gpio
            GPIO.cleanup(self.led)

            # init gpio
            pwm.start(self.led, 0, self.freq)
            self.currenta_angle = 0

            self.delta = self.max_value - self.min_value
            self.angle_increment = (self.update_delay *
                                    180) / (self.sweep_time * 60)

            self.initialized = True
Exemplo n.º 23
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.º 24
0
    def api_digital_pin_cleanup(self, pin):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True

        if not self.PINS_IN_USE:
            resp["message"] = "No pins currently setup"
        else:
            pin = pin.upper()

            if pin not in self.PINS_IN_USE:
                resp["message"] = "Pin not previously in use"
            else:
                resp["message"] = "Cleaning up %s" % pin
                GPIO.cleanup(pin)
                self.PINS_IN_USE.remove(pin)

        return jsonify(resp)
Exemplo n.º 25
0
    def setup(self):
        if not self.initialized:
            # reset gpio
            GPIO.cleanup(self.red)
            GPIO.cleanup(self.yellow)

            # init gpio
            pwm.start(self.red, 0, self.freq)
            pwm.start(self.yellow, 0, self.freq)

            self.initialized = True

            # init variables
            self.red_sweeping = False
            self.red_sweep_increment = 0
            self.red_duty = 0
            self.red_target = 0

            self.yellow_ud_percent = 0
            self.yellow_cooldown = 0
Exemplo n.º 26
0
def main():
	GPIO.setup("CSID0", GPIO.OUT)
	GPIO.setup("CSID1", GPIO.OUT)
	GPIO.setup("CSID2", GPIO.OUT)
	GPIO.setup("CSID3", GPIO.OUT)
	
	cmd = ""
	while cmd!="q":
  		cmd = raw_input("q,wasd,x? :")
  		if cmd=="w":
			forward()
  		if cmd=="a":
			steer_left()
		if cmd=="d":
			steer_right()
		if cmd=="s":
    			reverse()
		if cmd=="x":
			stop()
	stop()
	GPIO.cleanup()
Exemplo n.º 27
0
    def __init__(self, sensor_ctl, pud=gpio.PUD_UP, cooldown=None):
        self.callbacks_high = []
        self.callbacks_low = []
        self.sensor = sensor_ctl

        gpio.cleanup(sensor_ctl)
        gpio.setup(sensor_ctl, gpio.IN, pull_up_down=pud)

        self.state = None
        self.enabled = True

        try:
            tcool = float(cooldown)
        except:
            tcool = -1

        if tcool > 0:
            self.cooldown = Sensor.Cooldown(self, tcool)
            self.cooldown.start()
        else:
            self.cooldown = None
Exemplo n.º 28
0
def gpio_write(pin, value, verbose=False):
    if config.chip_platform:
        if verbose:
            print "DBG: CHIP platform detected"
        v = str_2_one_zero(value)

        import CHIP_IO.GPIO as GPIO
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, v)
        GPIO.cleanup()

        if verbose:
            print "DBG: {} written to PIN {}".format(v, pin)
    else:
        v = config.get_boolean_value(value)

        import Adafruit_GPIO.GPIO as GPIO
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, v)
        GPIO.cleanup()

        if verbose:
            print "DBG: {} written to PIN {}".format(v, pin)
Exemplo n.º 29
0
    def __init__(self):
        green = 'XIO-P0'
        blue = 'XIO-P1'
        red = 'XIO-P2'
        frequency = 100

        self.green = green
        self.red = red
        self.blue = blue

        GPIO.cleanup(red)
        GPIO.cleanup(green)
        GPIO.cleanup(blue)

        SPWM.start(red, 0)
        SPWM.set_frequency(red, frequency)
        SPWM.start(green, 0)
        SPWM.set_frequency(green, frequency)
        SPWM.start(blue, 0)
        SPWM.set_frequency(blue, frequency)
Exemplo n.º 30
0
isCHIP=False

# check CHIP or it is a raspberry Pi

f = open('/proc/cpuinfo','r')
cpuinfo = f.read()
f.close()


if cpuinfo.find('Allwinner') >0 :
   #  ------  chip  ------
   print('C.H.I.P GPIO')
   isCHIP=True
   import CHIP_IO.GPIO as MGPIO
   MGPIO.cleanup()
   #CLK GPIO
   PIC_CLK = 'LCD-D15'

   #DATA GPIO 
   PIC_DATA = 'LCD-D19'

   #MCLR GPIO
   PIC_MCLR = 'LCD-D21'

   #PGM
   PIC_PGM = 'LCD-D23'

else:
   #  ------ Raspberry Pi --
   print('Raspberry Pi GPIO')
Exemplo n.º 31
0
 def test_setup_failed_value_error(self):
     with pytest.raises(ValueError):
         GPIO.setup("U14_37", 3)
         GPIO.cleanup()
Exemplo n.º 32
0
def teardown_module(module):
    GPIO.cleanup()
Exemplo n.º 33
0
 def test_output_high(self):
     GPIO.setup("CSID6", GPIO.OUT)
     GPIO.output("CSID6", GPIO.HIGH)
     value = open('/sys/class/gpio/gpio138/value').read()
     assert int(value)
     GPIO.cleanup()
Exemplo n.º 34
0
def exit_gracefully(signal, frame):
  GPIO.cleanup()
  print "Clean exit"
  sys.exit(0)
Exemplo n.º 35
0
 def teardown():
     """ Cleanup GPIO and SpiDev """
     GPIO.cleanup()
     BOARD.spi.close()
Exemplo n.º 36
0
#!/usr/bin/env  python3

import CHIP_IO.GPIO as GPIO
import CHIP_IO.Utilities

red = "XIO-P1"
yellow = "XIO-P0"

GPIO.cleanup(red)
GPIO.cleanup(yellow)
CHIP_IO.Utilities.unexport_all()

GPIO.setup(red, GPIO.OUT)
GPIO.setup(yellow, GPIO.OUT)

GPIO.output(red, GPIO.LOW)
GPIO.output(yellow, GPIO.LOW)

GPIO.cleanup(red)
GPIO.cleanup(yellow)
CHIP_IO.Utilities.unexport_all()

Exemplo n.º 37
0
 def test_setup_input_name(self):
     GPIO.setup("CSID6", GPIO.IN)
     assert os.path.exists('/sys/class/gpio/gpio138')
     direction = open('/sys/class/gpio/gpio138/direction').read()
     assert direction == 'in\n'
     GPIO.cleanup()
Exemplo n.º 38
0
 def test_setup_input_pull_down(self):
     GPIO.setup("U14_37", GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
     assert os.path.exists('/sys/class/gpio/gpio138')
     direction = open('/sys/class/gpio/gpio138/direction').read()
     assert direction == 'in\n'
     GPIO.cleanup()
Exemplo n.º 39
0
 def test_output_greater_than_one(self):
     GPIO.setup("CSID6", GPIO.OUT)
     GPIO.output("CSID6", 2)
     value = open('/sys/class/gpio/gpio138/value').read()
     assert int(value)
     GPIO.cleanup()
Exemplo n.º 40
0
 def test_output_of_pin_not_setup(self):
     with pytest.raises(RuntimeError):
         GPIO.output("CSID7", GPIO.LOW)
         GPIO.cleanup()
Exemplo n.º 41
0
edge = f.read()
f.close()
print "EDGE: %s" % edge

# LOOP WRITING ON CSID0 TO HOPEFULLY GET CALLBACK TO WORK
print "WAITING FOR CALLBACKS"
loopfunction()

print "PRESS CONTROL-C TO EXIT IF SCRIPT GETS STUCK"
GPIO.remove_event_detect("XIO-P0")
try:
    # WAIT FOR EDGE
    t = threading.Thread(target=loopfunction)
    t.start()
    print "WAITING FOR EDGE"
    GPIO.wait_for_edge("XIO-P0",GPIO.FALLING)
    print "WE'VE FALLEN LIKE COOLIO'S CAREER"
    print "ATTEMPTING TO CANCEL THE TIMER"
    t.cancel()
except:
    pass

print "TESTING ERRORS THROWN WHEN SPECIFYING EDGE DETECTION ON UNAUTHORIZED GPIO"
GPIO.setup("CSID1",GPIO.IN)
GPIO.add_event_detect("CSID1",GPIO.FALLING,myfuncallback)

print "CLEANUP"
GPIO.remove_event_detect("XIO-P0")
GPIO.cleanup()

Exemplo n.º 42
0
	def setup(self):
		GPIO.setwarnings(False)
		GPIO.cleanup()

		super(ChipPlatform, self).setup()
Exemplo n.º 43
0
 def test_output_setup_as_input(self):
     GPIO.setup("CSID6", GPIO.IN)
     with pytest.raises(RuntimeError):
         GPIO.output("CSID6", GPIO.LOW)
         GPIO.cleanup()
Exemplo n.º 44
0
isCHIP = False

# check CHIP or it is a raspberry Pi

f = open('/proc/cpuinfo', 'r')
cpuinfo = f.read()
f.close()

if cpuinfo.find('Allwinner') > 0:
    #  ------  chip  ------
    print('C.H.I.P GPIO')
    isCHIP = True
    import CHIP_IO.GPIO as MGPIO
    #   MGPIO.toggle_debug()
    MGPIO.cleanup()
    #CLK GPIO
    PIC_CLK = 'I2C-SCL'

    #DATA GPIO
    PIC_DATA = 'I2C-SDA'

    #MCLR GPIO
    PIC_MCLR = 'UART1-RX'

    #PGM
    PIC_PGM = 'UART1-TX'

else:
    #  ------ Raspberry Pi --
    print('Raspberry Pi GPIO')
Exemplo n.º 45
0
 def cleanup(self):
     try:
         GPIO.cleanup()
     except Exception as e:
         app.logger.error("CLEAN UP OF GPIO FAILD " + str(e))
Exemplo n.º 46
0
def teardown_module(module):
    GPIO.cleanup()
Exemplo n.º 47
0
 def cleanup(self):
     self.listening = False
     GPIO.output(self.reset_pin, GPIO.LOW)
     GPIO.cleanup()
Exemplo n.º 48
0
 def test_direction_readback(self):
     GPIO.setup("CSID6", GPIO.OUT)
     direction = GPIO.gpio_function("CSID6")
     assert direction == GPIO.OUT
     GPIO.cleanup()
Exemplo n.º 49
0
 def test_setup_cleanup(self):
     GPIO.setup("U14_37", GPIO.OUT)
     assert os.path.exists('/sys/class/gpio/gpio138')
     GPIO.cleanup()
     assert not os.path.exists('/sys/class/gpio/gpio138')
Exemplo n.º 50
0
 def cleanup(self):
     GPIO.cleanup()
Exemplo n.º 51
0
 def test_setup_failed_type_error(self):
     with pytest.raises(TypeError):
         GPIO.setup("U14_37", "WEIRD")
         GPIO.cleanup()
Exemplo n.º 52
0
def close():
    GPIO.cleanup()
Exemplo n.º 53
0
 def test_setup_failed_value_error(self):
     with pytest.raises(ValueError):
         GPIO.setup("U14_37", 3)
         GPIO.cleanup()
Exemplo n.º 54
0
def configure_pins():
  GPIO.cleanup()
  for index in range(0,6):
    GPIO.setup(hour_leds[index], GPIO.OUT)
    GPIO.setup(minute_leds[index], GPIO.OUT)
    GPIO.setup(second_leds[index], GPIO.OUT)
Exemplo n.º 55
0
 def test_setup_expanded_gpio(self):
     GPIO.setup("XIO-P1", GPIO.OUT)
     assert os.path.exists('/sys/class/gpio/gpio409')
     GPIO.cleanup()
     assert not os.path.exists('/sys/class/gpio/gpio409')
Exemplo n.º 56
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")

GPIO.cleanup()
Exemplo n.º 57
0
 def test_setup_output_key(self):
     GPIO.setup("U14_37", GPIO.OUT)
     assert os.path.exists('/sys/class/gpio/gpio138')
     direction = open('/sys/class/gpio/gpio138/direction').read()
     assert direction == 'out\n'
     GPIO.cleanup()