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()
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
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)
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)
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
def GPIOtest(): initGPIO132() initGPIO133() readADC("CSID0","CSID1",64) GPIO.cleanup("CSID0") GPIO.cleanup("CSID1")
def sig_handler(signal, frame): OM.unload("PWM0") GPIO.cleanup() PWM.cleanup() SPWM.cleanup() UT.disable_1v8_pin() sys.exit(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()
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()
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)
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)
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
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()
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()
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)
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)
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)
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
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)
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
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)
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)
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
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()
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
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)
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)
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')
def test_setup_failed_value_error(self): with pytest.raises(ValueError): GPIO.setup("U14_37", 3) GPIO.cleanup()
def teardown_module(module): GPIO.cleanup()
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()
def exit_gracefully(signal, frame): GPIO.cleanup() print "Clean exit" sys.exit(0)
def teardown(): """ Cleanup GPIO and SpiDev """ GPIO.cleanup() BOARD.spi.close()
#!/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()
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()
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()
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()
def test_output_of_pin_not_setup(self): with pytest.raises(RuntimeError): GPIO.output("CSID7", GPIO.LOW) GPIO.cleanup()
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()
def setup(self): GPIO.setwarnings(False) GPIO.cleanup() super(ChipPlatform, self).setup()
def test_output_setup_as_input(self): GPIO.setup("CSID6", GPIO.IN) with pytest.raises(RuntimeError): GPIO.output("CSID6", GPIO.LOW) GPIO.cleanup()
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')
def cleanup(self): try: GPIO.cleanup() except Exception as e: app.logger.error("CLEAN UP OF GPIO FAILD " + str(e))
def teardown_module(module): GPIO.cleanup()
def cleanup(self): self.listening = False GPIO.output(self.reset_pin, GPIO.LOW) GPIO.cleanup()
def test_direction_readback(self): GPIO.setup("CSID6", GPIO.OUT) direction = GPIO.gpio_function("CSID6") assert direction == GPIO.OUT GPIO.cleanup()
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')
def cleanup(self): GPIO.cleanup()
def test_setup_failed_type_error(self): with pytest.raises(TypeError): GPIO.setup("U14_37", "WEIRD") GPIO.cleanup()
def close(): GPIO.cleanup()
def test_setup_failed_value_error(self): with pytest.raises(ValueError): GPIO.setup("U14_37", 3) GPIO.cleanup()
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)
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')
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()
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()