def event_detect(self, io_number):
if self.importlib is not None:
self.logger.debug('event_detect')
GPIO.add_event_detect(io_number, GPIO.RISING)
while True:
if GPIO.event_detected(io_number):
print("Bouton appuye")
python类event_detected()的实例源码
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()
def wait_for_press(self):
"""Waits for the button to be pressed.
This method blocks until the button is pressed.
"""
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)
def run(self):
while not self.quit:
button_pressed = False
if 0 != BUTTONPIN:
button_pressed = not GPIO.input(BUTTONPIN)
if button_pressed and self.core.current_call is None:
# We do not check the time here. They can keep "ringing" the doorbell if they want
# but it won't matter once a call is initiated.
if self.doorbell_sound:
self.doorbell_sound.play()
try:
if time.time() - self.lastMessageTicks > WAITSECONDS:
self.notify_chat_contacts(message_template="Doorbell ring on %s at %s")
params = self.core.create_call_params(None)
params.audio_enabled = True
params.video_enabled = True
params.audio_multicast_enabled = False # Set these = True if you want multiple
params.video_multicast_enabled = False # people to connect at once.
address = linphone.Address.new(doorbellToAddress)
logging.info('address = {address}, used_video_codec = {codec}'.format(
address=address,
codec=params.used_video_codec))
self.current_call = self.core.invite_address_with_params(address, params)
if None is self.current_call:
logging.error("Error creating call and inviting with params... outgoing call aborted.")
if time.time() - self.lastEmailTicks >= WAITEMAILSECONDS:
if LEDPINDOORBELL:
self.flash_led(ledpin=LEDPINDOORBELL, stay_on=True,
blink_cam_led=False, delay=0.25, blink_count=8)
else:
self.flash_led()
self.notify_email_contacts()
except KeyboardInterrupt:
self.quit = True
break
elif detectMotion and self.core.current_call is None:
motion_detected = False
# Incoming calls have been handled, so check the motion detector:
if 0 != PIRPIN:
# motion_detected = GPIO.wait_for_edge(PIRPIN,GPIO.RISING)
# motion_detected = GPIO.event_detected(PIRPIN)
motion_detected = GPIO.input(PIRPIN)
logging.debug("\rmotion_detected = %s, GPIO.input(PIRPIN) = %s" % (
str(motion_detected), str(GPIO.input(PIRPIN))))
elif 0 != MDPIN:
motion_detected = GPIO.input(MDPIN) == 0
if motion_detected:
self.motion_detected()
# else:
# time.sleep(0.01) #
self.core.iterate()
def openClose(number):
global condition, servoDeur
if GPIO.event_detected(knopBinnen):
if (condition == "closed"):
servoDeur.ChangeFrequency(50)
servoDeur.start(0)
print("Gedrukt Binnen")
condition = "opened"
connection.setDataToDatabaseMetingenMetVerandering(sensor.print_temp(), "temperature", "Door closed manually")
servoDeur.ChangeDutyCycle(2.5)
time.sleep(3)
servoDeur.stop()
else:
servoDeur.ChangeFrequency(50)
servoDeur.start(0)
print("Gedrukt Binnen 2")
condition = "closed"
connection.setDataToDatabaseMetingenMetVerandering(sensor.print_temp(), "temperature", "Door opened manually")
servoDeur.ChangeDutyCycle(6)
time.sleep(3)
servoDeur.stop()
time.sleep(0.0025)
if GPIO.event_detected(knopBuiten):
if (condition == "opened"):
servoDeur.ChangeFrequency(50)
servoDeur.start(0)
print("Gedrukt Buiten ")
condition = "opened"
connection.setDataToDatabaseMetingenMetVerandering(sensor.print_temp(), "temperature", "Door opened manually")
servoDeur.ChangeDutyCycle(6)
else:
servoDeur.ChangeFrequency(50)
servoDeur.start(0)
print("Gedrukt Buiten 2")
condition = "opened"
connection.setDataToDatabaseMetingenMetVerandering(sensor.print_temp(), "temperature", "Door closed manually")
servoDeur.ChangeDutyCycle(2.5) # turn towards 180 degree
time.sleep(3)
servoDeur.stop()
time.sleep(0.0025)