[bug] short button

This commit is contained in:
IrvingGao 2024-05-30 01:43:06 +08:00
parent 8734a8c12c
commit 36f0b09852
2 changed files with 16 additions and 20 deletions

View File

@ -78,10 +78,11 @@ class OrangePi(BaseHardware):
print(f"{datetime.now()}: press_duration: {press_duration}")
if press_duration > 1:
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:
self.short_power_status = not self.short_power_status
print(f"{datetime.now()}: short_power_status: {self.short_power_status} {self.long_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()}: power_status: {self.long_power_status}, interrupt_status: {self.short_power_status}")
press_time_1 = None
last_status_1 = button_status_1
@ -89,14 +90,14 @@ class OrangePi(BaseHardware):
# 更新LED状态
if self.long_power_status:
self.set_led_on('white')
else:
self.short_power_status = False
self.set_led_off('white')
if self.short_power_status:
self.set_led_on('yellow')
else:
self.set_led_off('yellow')
else:
self.short_power_status = False
self.set_led_off('white')
def set_led_on(self, color='red'):
wiringpi.digitalWrite(getattr(self, f'LED_PIN_{color}'), GPIO.HIGH)
@ -107,9 +108,9 @@ class OrangePi(BaseHardware):
def start_status_light(self):
for i in range(2):
self.set_led_on("white")
time.sleep(0.5)
time.sleep(1)
self.set_led_off("white")
time.sleep(0.5)
time.sleep(1)
if __name__ == '__main__':
orangepi = OrangePi()

View File

@ -142,17 +142,12 @@ class WebSocketClinet:
if recorder.hardware.long_power_status:
self.wakeup_event.set()
# 短时按键被按下,打断
try:
if recorder.hardware.short_power_status and not last_short_power_status:
self.speaking_event.clear()
self.listening_event.set()
recorder.hardware.short_power_status = False
print("Interrupt conversation.")
last_short_power_status = ~recorder.hardware.short_power_status
else:
last_short_power_status = recorder.hardware.short_power_status
except:
pass
else:
self.wakeup_event.clear()
time.sleep(0.01)