Python RPi.GPIO.remove_event_detect() Examples

The following are 26 code examples of RPi.GPIO.remove_event_detect(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module RPi.GPIO , or try the search function .
Example #1
Source File: joystick.py    From displayotron with MIT License 7 votes vote down vote up
def on(buttons, bounce=BOUNCE):
    """Handle a joystick direction or button push

    Decorator. Use with @joystick.on(joystick.UP)

    :param buttons: List, or single instance of joystick button constant
    :param bounce: Debounce delay in milliseconds: default 300

    """

    buttons = buttons if isinstance(buttons, list) else [buttons]

    def register(handler):
        for button in buttons:
            GPIO.remove_event_detect(button)
            GPIO.add_event_detect(button, GPIO.FALLING, callback=handler, bouncetime=bounce)

    return register 
Example #2
Source File: gpio_sensor.py    From SecPi with GNU General Public License v3.0 6 votes vote down vote up
def cleanup_sensor(self):
		try:
			GPIO.remove_event_detect(self.gpio)
			GPIO.cleanup(self.gpio)
		except ValueError as ve: # GPIO pin number is not in valid range
			logging.error("GPIOSensor: The given pin number is not in a valid range: %s" % ve)
		logging.debug("GPIOSensor: Removed sensor at pin %s!" % self.gpio)
	
	# callback for alarm 
Example #3
Source File: main.py    From GassistPi with GNU General Public License v3.0 6 votes vote down vote up
def pushbutton(self):
        if GPIOcontrol:
            while mutestopbutton:
                time.sleep(.1)
                if GPIO.event_detected(stoppushbutton):
                    GPIO.remove_event_detect(stoppushbutton)
                    now = time.time()
                    count = 1
                    GPIO.add_event_detect(stoppushbutton,GPIO.RISING)
                    while time.time() < now + 1:
                         if GPIO.event_detected(stoppushbutton):
                             count +=1
                             time.sleep(.25)
                    if count == 2:
                        self.buttonsinglepress()
                        GPIO.remove_event_detect(stoppushbutton)
                        GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
                    elif count == 3:
                        self.buttondoublepress()
                        GPIO.remove_event_detect(stoppushbutton)
                        GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
                    elif count == 4:
                        self.buttontriplepress()
                        GPIO.remove_event_detect(stoppushbutton)
                        GPIO.add_event_detect(stoppushbutton,GPIO.FALLING) 
Example #4
Source File: _button.py    From ai-makers-kit with MIT License 6 votes vote down vote up
def wait_for_press(self):
        GPIO.add_event_detect(self.channel, self.polarity)
        while True:
            if GPIO.event_detected(self.channel) and self._debounce():
                GPIO.remove_event_detect(self.channel)
                return
            time.sleep(0.02) 
Example #5
Source File: __init__.py    From OctoPrint-Enclosure with GNU General Public License v3.0 6 votes vote down vote up
def clear_gpio(self):
        try:

            for gpio_out in list(filter(
                    lambda item: item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
                        'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct',
                    self.rpi_outputs)):
                gpio_pin = self.to_int(gpio_out['gpio_pin'])
                if gpio_pin not in self.rpi_outputs_not_changed:
                    GPIO.cleanup(gpio_pin)

            for gpio_in in list(filter(lambda item: item['input_type'] == 'gpio', self.rpi_inputs)):
                try:
                    GPIO.remove_event_detect(self.to_int(gpio_in['gpio_pin']))
                except:
                    pass
                GPIO.cleanup(self.to_int(gpio_in['gpio_pin']))
        except Exception as ex:
            self.log_error(ex) 
Example #6
Source File: Midi.py    From OP_Manager with MIT License 5 votes vote down vote up
def gpiocleanup(self):
        pins = [27, 23, 4, 17, 22, 5, 6]  # [L, R, C, U, D, A, B]
        for i in pins:
            GPIO.remove_event_detect(i) 
Example #7
Source File: gpio.py    From GPIOnext with MIT License 5 votes vote down vote up
def cleanup():
	global pins
	pinList = [p.number for p in pins]
	for p in pins:
		GPIO.remove_event_detect(p.number)
	GPIO.cleanup(pinList) 
Example #8
Source File: light.py    From nhl_goal_light with GNU General Public License v3.0 5 votes vote down vote up
def cleanup():
    """ Function to cleanup raspberry pi GPIO at end of code """

    # Restore GPIO to default state
    GPIO.remove_event_detect(15) #Add to end of function
    GPIO.cleanup()
    print("GPIO cleaned!") 
Example #9
Source File: __init__.py    From Octoprint-Filament-Reloaded with GNU General Public License v3.0 5 votes vote down vote up
def on_event(self, event, payload):
        # Early abort in case of out ot filament when start printing, as we
        # can't change with a cold nozzle
        if event is Events.PRINT_STARTED and self.no_filament():
            self._logger.info("Printing aborted: no filament detected!")
            self._printer.cancel_print()
        # Enable sensor
        if event in (
            Events.PRINT_STARTED,
            Events.PRINT_RESUMED
        ):
            self._logger.info("%s: Enabling filament sensor." % (event))
            if self.sensor_enabled():
                self.triggered = 0 # reset triggered state
                GPIO.remove_event_detect(self.pin)
                GPIO.add_event_detect(
                    self.pin, GPIO.BOTH,
                    callback=self.sensor_callback,
                    bouncetime=self.bounce
                )
        # Disable sensor
        elif event in (
            Events.PRINT_DONE,
            Events.PRINT_FAILED,
            Events.PRINT_CANCELLED,
            Events.ERROR
        ):
            self._logger.info("%s: Disabling filament sensor." % (event))
            GPIO.remove_event_detect(self.pin) 
Example #10
Source File: keypad.py    From rpieasy with GNU General Public License v3.0 5 votes vote down vote up
def stopscan(self):
  self.initialized = False
  try:
   for pi in self.rowpins:
    GPIO.remove_event_detect(pi)
  except:
   pass 
Example #11
Source File: keypad.py    From rpieasy with GNU General Public License v3.0 5 votes vote down vote up
def initpins(self):
#   GPIO.setwarnings(False)
#   GPIO.setmode(GPIO.BCM)
   for po in self.colpins:
    GPIO.setup(po,GPIO.OUT)
   for pi in self.rowpins:
    GPIO.setup(pi,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
    try:
     GPIO.remove_event_detect(pi)
    except:
     pass
    time.sleep(0.05)
    GPIO.add_event_detect(pi,GPIO.RISING, callback=self.inthandler,bouncetime=200) 
Example #12
Source File: lib_rpigpios.py    From rpieasy with GNU General Public License v3.0 5 votes vote down vote up
def remove_event_detect(self,pin):
  GPIO.remove_event_detect(pin) 
Example #13
Source File: __init__.py    From OctoPrint-Enclosure with GNU General Public License v3.0 5 votes vote down vote up
def stop_filament_detection(self):
        try:
            self.last_filament_end_detected = []
            for filament_sensor in list(filter(
                    lambda item: item['input_type'] == 'gpio' and item['action_type'] == 'printer_control' and item[
                        'printer_action'] == 'filament', self.rpi_inputs)):
                GPIO.remove_event_detect(self.to_int(filament_sensor['gpio_pin']))
        except Exception as ex:
            self.log_error(ex) 
Example #14
Source File: __init__.py    From explorer-hat with MIT License 5 votes vote down vote up
def clear_events(self):
        if self._is_gpio_setup():
            GPIO.remove_event_detect(self.pin)
        self.has_callback = False

    # Alias handlers 
Example #15
Source File: KY040.py    From KY040 with MIT License 5 votes vote down vote up
def stop(self):
        GPIO.remove_event_detect(self.clockPin)

        if None != self.switchPin:
            GPIO.remove_event_detect(self.switchPin) 
Example #16
Source File: io_raspberry.py    From foos with GNU General Public License v3.0 5 votes vote down vote up
def __del__(self):
        if self.pin:
            GPIO.remove_event_detect(self.pin) 
Example #17
Source File: io_raspberry.py    From foos with GNU General Public License v3.0 5 votes vote down vote up
def __del__(self):
        if self.pin:
            GPIO.remove_event_detect(self.pin) 
Example #18
Source File: assistant.py    From voicetools with Apache License 2.0 5 votes vote down vote up
def loop():
    # 初始化
    handler = BaseHandler()
    try:
        while True:
            # 下降沿检测
            if GPIO.event_detected(GPIOConfig.VOICE_SENSOR):
                GPIO.remove_event_detect(GPIOConfig.VOICE_SENSOR)
                handler.worker()
                GPIO.add_event_detect(GPIOConfig.VOICE_SENSOR, GPIO.FALLING)
            time.sleep(0.5)
    except KeyboardInterrupt:
        pass
    GPIO.cleanup() 
Example #19
Source File: _button.py    From ai-makers-kit with MIT License 5 votes vote down vote up
def on_press(self, callback):
        GPIO.remove_event_detect(self.channel)
        if callback is not None:
            self.callback = callback
            GPIO.add_event_detect(
                self.channel, self.polarity, callback=self._debounce_and_callback) 
Example #20
Source File: _button.py    From ai-makers-kit with MIT License 5 votes vote down vote up
def on_press(self, callback):
        GPIO.remove_event_detect(self.channel)
        if callback is not None:
            self.callback = callback
            GPIO.add_event_detect(
                self.channel, self.polarity, callback=self._debounce_and_callback) 
Example #21
Source File: _button.py    From ai-makers-kit with MIT License 5 votes vote down vote up
def wait_for_press(self):
        GPIO.add_event_detect(self.channel, self.polarity)
        while True:
            if GPIO.event_detected(self.channel) and self._debounce():
                GPIO.remove_event_detect(self.channel)
                return
            time.sleep(0.02) 
Example #22
Source File: gengpioin.py    From genmon with GNU General Public License v2.0 5 votes vote down vote up
def Close(self):
        try:
            self.Exiting = True
            if not self.UseLibCallbacks:
                self.KillThread("GPIOInputMonitor")
            GPIO.remove_event_detect(self.GPIO)

        except Exception as e1:
            self.LogErrorLine("Error in Close: " + str(e1))

#----------  Signal Handler ---------------------------------------------------- 
Example #23
Source File: controller_rpi.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_irq_pin(self, pin_id):
        pin = self.prepare_pin(pin_id, GPIO.IN)
        if pin:
            pin.set_handler_for_irq_on_rising_edge = \
                lambda handler: GPIO.add_event_detect(pin.pin_id,
                                                      GPIO.RISING,
                                                      callback = handler)
            pin.detach_irq = lambda: GPIO.remove_event_detect(pin.pin_id)
            return pin 
Example #24
Source File: controller_rpi.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_irq_pin(self, pin_id): 
        pin = self.prepare_pin(pin_id, GPIO.IN) 
        if pin:       
            pin.set_handler_for_irq_on_rising_edge = \
                lambda handler: GPIO.add_event_detect(pin.pin_id,
                                                      GPIO.RISING,
                                                      callback = handler)  
            pin.detach_irq = lambda : GPIO.remove_event_detect(pin.pin_id) 
            return pin 
Example #25
Source File: radiohackbox.py    From radio-hackbox with GNU General Public License v3.0 4 votes vote down vote up
def buttonCallback(self, channel):
        """Callback function for user input (pressed buttons)"""

        # record button state transitions
        if channel == RECORD_BUTTON:
            # if the current state is IDLE change it to RECORD
            if self.state == IDLE:
                # set RECORD state
                self.setState(RECORD)

                # empty payloads list
                self.payloads = []

            # if the current state is RECORD change it to IDLE
            elif self.state == RECORD:
                # set IDLE state
                self.setState(IDLE)

        # play button state transitions
        elif channel == REPLAY_BUTTON:
            # if the current state is IDLE change it to REPLAY
            if self.state == IDLE:
                # set REPLAY state
                self.setState(REPLAY)

        # scan button state transitions
        elif channel == SCAN_BUTTON:
            # wait a short a time to see whether the record button is also
            # press in order to perform a graceful shutdown

            # remove event detection for record button
            GPIO.remove_event_detect(RECORD_BUTTON)
            chan = GPIO.wait_for_edge(RECORD_BUTTON, GPIO.RISING, timeout=1000)
            if chan != None:
                # set SHUTDOWN state
                self.setState(SHUTDOWN)

            # set callback function for record button
            GPIO.remove_event_detect(RECORD_BUTTON)
            GPIO.add_event_detect(RECORD_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250)

            # if the current state is IDLE change it to SCAN
            if self.state == IDLE:
                # set SCAN state
                self.setState(SCAN)

        # attack button state transitions
        elif channel == ATTACK_BUTTON:
            # if the current state is IDLE change it to ATTACK
            if self.state == IDLE:
                # set ATTACK state
                self.setState(ATTACK)

        # debug output
        debug("State: {0}".format(self.state)) 
Example #26
Source File: __init__.py    From OctoPrint-Enclosure with GNU General Public License v3.0 4 votes vote down vote up
def configure_gpio(self):
        try:

            for gpio_out in list(
                    filter(lambda item: item['output_type'] == 'regular' or item['output_type'] == 'temp_hum_control',
                           self.rpi_outputs)):
                initial_value = GPIO.HIGH if gpio_out['active_low'] else GPIO.LOW
                pin = self.to_int(gpio_out['gpio_pin'])
                if pin not in self.rpi_outputs_not_changed:
                    self._logger.info("Setting GPIO pin %s as OUTPUT with initial value: %s", pin, initial_value)
                    GPIO.setup(pin, GPIO.OUT, initial=initial_value)
            for gpio_out_pwm in list(filter(lambda item: item['output_type'] == 'pwm', self.rpi_outputs)):
                pin = self.to_int(gpio_out_pwm['gpio_pin'])
                self._logger.info("Setting GPIO pin %s as PWM", pin)
                for pwm in (pwm_dict for pwm_dict in self.pwm_instances if pin in pwm_dict):
                    self.pwm_instances.remove(pwm)
                self.clear_channel(pin)
                GPIO.setup(pin, GPIO.OUT)
                pwm_instance = GPIO.PWM(pin, self.to_int(gpio_out_pwm['pwm_frequency']))
                self._logger.info("starting PWM on pin %s", pin)
                pwm_instance.start(0)
                self.pwm_instances.append({pin: pwm_instance})
            for gpio_out_neopixel in list(
                    filter(lambda item: item['output_type'] == 'neopixel_direct', self.rpi_outputs)):
                pin = self.to_int(gpio_out_neopixel['gpio_pin'])
                self.clear_channel(pin)

            for rpi_input in list(filter(lambda item: item['input_type'] == 'gpio', self.rpi_inputs)):
                gpio_pin = self.to_int(rpi_input['gpio_pin'])
                pull_resistor = GPIO.PUD_UP if rpi_input['input_pull_resistor'] == 'input_pull_up' else GPIO.PUD_DOWN
                GPIO.setup(gpio_pin, GPIO.IN, pull_resistor)
                edge = GPIO.RISING if rpi_input['edge'] == 'rise' else GPIO.FALLING

                inputs_same_gpio = list(
                    [r_inp for r_inp in self.rpi_inputs if self.to_int(r_inp['gpio_pin']) == gpio_pin])

                if len(inputs_same_gpio) > 1:
                    GPIO.remove_event_detect(gpio_pin)
                    for other_input in inputs_same_gpio:
                        if other_input['edge'] is not edge:
                            edge = GPIO.BOTH

                if rpi_input['action_type'] == 'output_control':
                    self._logger.info("Adding GPIO event detect on pin %s with edge: %s", gpio_pin, edge)
                    GPIO.add_event_detect(gpio_pin, edge, callback=self.handle_gpio_control, bouncetime=200)
                if (rpi_input['action_type'] == 'printer_control' and rpi_input['printer_action'] != 'filament'):
                    GPIO.add_event_detect(gpio_pin, edge, callback=self.handle_printer_action, bouncetime=200)
                    self._logger.info("Adding PRINTER CONTROL event detect on pin %s with edge: %s", gpio_pin, edge)
        except Exception as ex:
            self.log_error(ex)