本文整理汇总了Python中RPi.GPIO.event_detected方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.event_detected方法的具体用法?Python GPIO.event_detected怎么用?Python GPIO.event_detected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.event_detected方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadFirmware
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
def loadFirmware(device):
if os.path.exists("/media/pi/OP-1")==1:
drawText(device,["op1 connection success","load firmware?"," -yup"," -back"])
while True:
if GPIO.event_detected(key['key2']):
print "copying firmware"
drawText(device,["copying firmware..."])
spath="/home/pi/Desktop/misc/op1_225.op1"
dpath="/media/pi/OP-1/"
sh.copy(spath,dpath)
return
elif GPIO.event_detected(key['key1']):
return
else:
drawText(device,["op1 not detected","","returning to menu..."])
time.sleep(1)
return
示例2: pushbutton
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
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)
示例3: GPIOInputMonitor
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
def GPIOInputMonitor(self):
try:
while not self.Exiting:
if GPIO.event_detected(self.GPIO):
self.LogError('Edge detected on pin ' + str(self.GPIO))
if self.Callback != None and callable(self.Callback):
self.Callback(self.GPIO)
if self.WaitForExit("GPIOInputMonitor", 1):
return
except Exception as e1:
self.LogErrorLine("Error GPIOInputMonitor: " + str(self.GPIO) + ": "+ str(e1))
#-----------------Close-----------------------------------------------------
示例4: wait_for_press
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
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)
示例5: loop
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
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()
示例6: read
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
def read(self):
#Read the sensor(s), parse the data and store it in redis if redis is configured
#If edge detection is being used return the detection event instead
return self.readPin() if self.edge_detection is None else GPIO.event_detected(self.pin)
示例7: wait
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
def wait(keys,waitkey):
done=0
while done==0:
if GPIO.event_detected(key[waitkey]):
done=1
time.sleep(.01)
return
示例8: handle_button
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import event_detected [as 别名]
def handle_button(self, message):
longpress_threshold = 2
if GPIO.event_detected(BUTTON):
self.log.info("GPIO.event_detected")
pressed_time = time.time()
while not GPIO.input(BUTTON):
time.sleep(0.2)
pressed_time = time.time() - pressed_time
if pressed_time < longpress_threshold:
self.bus.emit(Message("mycroft.mic.listen"))
else:
self.bus.emit(Message("mycroft.stop"))