Compare commits

..

2 Commits

Author SHA1 Message Date
IrvingGao a808d58758 [led] orangepi 2w 2024-06-09 02:37:17 +08:00
IrvingGao fa62c1b2ee [led] orangepi 2w 2024-06-09 02:37:05 +08:00
2 changed files with 21 additions and 14 deletions

View File

@ -12,9 +12,9 @@ except:
| GPIO | LED | | GPIO | LED |
| -- | - - | | -- | - - |
| 0 | 红色 | | 0 | 红色 |
| 1 | | | 1 | |
| 2 | 绿色 | | 2 | 绿色 |
| 3 | | | 3 | |
| 4 | 白色 | | 4 | 白色 |
| GPIO | BUTTON | | GPIO | BUTTON |
@ -28,9 +28,9 @@ class OrangePi(BaseHardware):
super().__init__(hd_trigger, hd_detect_threshold) super().__init__(hd_trigger, hd_detect_threshold)
self.LED_PIN_red = 0 self.LED_PIN_red = 0
self.LED_PIN_yellow = 1 self.LED_PIN_blue = 1
self.LED_PIN_green = 2 self.LED_PIN_green = 2
self.LED_PIN_blue = 3 self.LED_PIN_yellow = 3
self.LED_PIN_white = 4 self.LED_PIN_white = 4
self.BUTTON_PIN_1 = 6 self.BUTTON_PIN_1 = 6
@ -50,9 +50,9 @@ class OrangePi(BaseHardware):
wiringpi.wiringPiSetup() wiringpi.wiringPiSetup()
# GPIO 输出模式 # GPIO 输出模式
wiringpi.pinMode(self.LED_PIN_red, GPIO.OUTPUT) wiringpi.pinMode(self.LED_PIN_red, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_yellow, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_green, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_blue, GPIO.OUTPUT) wiringpi.pinMode(self.LED_PIN_blue, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_green, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_yellow, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_white, GPIO.OUTPUT) wiringpi.pinMode(self.LED_PIN_white, GPIO.OUTPUT)
# GPIO 输入模式 # GPIO 输入模式
wiringpi.pinMode(self.BUTTON_PIN_1, GPIO.INPUT) wiringpi.pinMode(self.BUTTON_PIN_1, GPIO.INPUT)
@ -80,6 +80,9 @@ class OrangePi(BaseHardware):
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}")
elif press_duration > 5:
time.sleep(1) # 防止短按误触发
subprocess.Popen('sudo shutdown now', shell=True)
else: else:
self.short_power_status = True 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}")
@ -90,14 +93,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('green')
if self.short_power_status: if self.short_power_status:
self.set_led_on('yellow') self.set_led_on('blue')
else: else:
self.set_led_off('yellow') self.set_led_off('blue')
else: else:
self.short_power_status = False self.short_power_status = False
self.set_led_off('white') self.set_led_off('green')
def set_led_on(self, color='red'): def set_led_on(self, color='red'):
@ -108,10 +111,10 @@ 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("green")
time.sleep(1) time.sleep(0.5)
self.set_led_off("white") self.set_led_off("green")
time.sleep(1) time.sleep(0.5)
if __name__ == '__main__': if __name__ == '__main__':
orangepi = OrangePi() orangepi = OrangePi()

View File

@ -258,7 +258,11 @@ class WebSocketClinet:
recorder.hardware.set_led_off("blue") recorder.hardware.set_led_off("blue")
elif self.speaking_event.is_set(): elif self.speaking_event.is_set():
print(f"{datetime.now()}: wait for speaking close and listening start.") print(f"{datetime.now()}: wait for speaking close and listening start.")
if board == 'orangepi':
recorder.hardware.set_led_on("red")
self.listening_event.wait() self.listening_event.wait()
if board == 'orangepi':
recorder.hardware.set_led_off("red")
# 重新计时 # 重新计时
slience_bgn_t = time.time() slience_bgn_t = time.time()