From 36f0b098524088a5aa29d07fcf300842ebd8a5f3 Mon Sep 17 00:00:00 2001 From: IrvingGao <1729854488@qq.com> Date: Thu, 30 May 2024 01:43:06 +0800 Subject: [PATCH] [bug] short button --- takway/board/orangepi.py | 19 ++++++++++--------- takway/clients/web_socket_client_utils.py | 17 ++++++----------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/takway/board/orangepi.py b/takway/board/orangepi.py index fc325c4..f748515 100644 --- a/takway/board/orangepi.py +++ b/takway/board/orangepi.py @@ -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') + 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') - if self.short_power_status: - self.set_led_on('yellow') - else: - self.set_led_off('yellow') 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() diff --git a/takway/clients/web_socket_client_utils.py b/takway/clients/web_socket_client_utils.py index 0a19331..112801e 100644 --- a/takway/clients/web_socket_client_utils.py +++ b/takway/clients/web_socket_client_utils.py @@ -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 + 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: self.wakeup_event.clear() time.sleep(0.01)