[bug] short button
This commit is contained in:
parent
8734a8c12c
commit
36f0b09852
|
@ -78,10 +78,11 @@ class OrangePi(BaseHardware):
|
||||||
print(f"{datetime.now()}: press_duration: {press_duration}")
|
print(f"{datetime.now()}: press_duration: {press_duration}")
|
||||||
if press_duration > 1:
|
if press_duration > 1:
|
||||||
self.long_power_status = not self.long_power_status
|
self.long_power_status = not self.long_power_status
|
||||||
print(f"{datetime.now()}: long_power_status: {self.long_power_status} {self.short_power_status}")
|
# print(f"{datetime.now()}: long_power_status: {self.long_power_status} {self.short_power_status}")
|
||||||
else:
|
else:
|
||||||
self.short_power_status = not self.short_power_status
|
self.short_power_status = True
|
||||||
print(f"{datetime.now()}: short_power_status: {self.short_power_status} {self.long_power_status}")
|
# print(f"{datetime.now()}: short_power_status: {self.short_power_status} {self.long_power_status}")
|
||||||
|
print(f"{datetime.now()}: power_status: {self.long_power_status}, interrupt_status: {self.short_power_status}")
|
||||||
press_time_1 = None
|
press_time_1 = None
|
||||||
|
|
||||||
last_status_1 = button_status_1
|
last_status_1 = button_status_1
|
||||||
|
@ -89,14 +90,14 @@ class OrangePi(BaseHardware):
|
||||||
# 更新LED状态
|
# 更新LED状态
|
||||||
if self.long_power_status:
|
if self.long_power_status:
|
||||||
self.set_led_on('white')
|
self.set_led_on('white')
|
||||||
|
if self.short_power_status:
|
||||||
|
self.set_led_on('yellow')
|
||||||
|
else:
|
||||||
|
self.set_led_off('yellow')
|
||||||
else:
|
else:
|
||||||
self.short_power_status = False
|
self.short_power_status = False
|
||||||
self.set_led_off('white')
|
self.set_led_off('white')
|
||||||
|
|
||||||
if self.short_power_status:
|
|
||||||
self.set_led_on('yellow')
|
|
||||||
else:
|
|
||||||
self.set_led_off('yellow')
|
|
||||||
|
|
||||||
def set_led_on(self, color='red'):
|
def set_led_on(self, color='red'):
|
||||||
wiringpi.digitalWrite(getattr(self, f'LED_PIN_{color}'), GPIO.HIGH)
|
wiringpi.digitalWrite(getattr(self, f'LED_PIN_{color}'), GPIO.HIGH)
|
||||||
|
@ -107,9 +108,9 @@ class OrangePi(BaseHardware):
|
||||||
def start_status_light(self):
|
def start_status_light(self):
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
self.set_led_on("white")
|
self.set_led_on("white")
|
||||||
time.sleep(0.5)
|
time.sleep(1)
|
||||||
self.set_led_off("white")
|
self.set_led_off("white")
|
||||||
time.sleep(0.5)
|
time.sleep(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
orangepi = OrangePi()
|
orangepi = OrangePi()
|
||||||
|
|
|
@ -142,17 +142,12 @@ class WebSocketClinet:
|
||||||
if recorder.hardware.long_power_status:
|
if recorder.hardware.long_power_status:
|
||||||
self.wakeup_event.set()
|
self.wakeup_event.set()
|
||||||
# 短时按键被按下,打断
|
# 短时按键被按下,打断
|
||||||
try:
|
if recorder.hardware.short_power_status and not last_short_power_status:
|
||||||
if recorder.hardware.short_power_status and not last_short_power_status:
|
self.speaking_event.clear()
|
||||||
self.speaking_event.clear()
|
self.listening_event.set()
|
||||||
self.listening_event.set()
|
recorder.hardware.short_power_status = False
|
||||||
recorder.hardware.short_power_status = False
|
print("Interrupt conversation.")
|
||||||
print("Interrupt conversation.")
|
last_short_power_status = recorder.hardware.short_power_status
|
||||||
last_short_power_status = ~recorder.hardware.short_power_status
|
|
||||||
else:
|
|
||||||
last_short_power_status = recorder.hardware.short_power_status
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self.wakeup_event.clear()
|
self.wakeup_event.clear()
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
Loading…
Reference in New Issue