From a808d58758472f5ead848ba34751c3345af2e017 Mon Sep 17 00:00:00 2001 From: IrvingGao <1729854488@qq.com> Date: Sun, 9 Jun 2024 02:37:17 +0800 Subject: [PATCH] [led] orangepi 2w --- takway/board/orangepi.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/takway/board/orangepi.py b/takway/board/orangepi.py index dd6d68f..5f8da90 100644 --- a/takway/board/orangepi.py +++ b/takway/board/orangepi.py @@ -12,9 +12,9 @@ except: | GPIO | LED | | -- | - - | | 0 | 红色 | -| 1 | 黄色 | +| 1 | 蓝色 | | 2 | 绿色 | -| 3 | 蓝色 | +| 3 | 黄色 | | 4 | 白色 | | GPIO | BUTTON | @@ -28,9 +28,9 @@ class OrangePi(BaseHardware): super().__init__(hd_trigger, hd_detect_threshold) self.LED_PIN_red = 0 - self.LED_PIN_yellow = 1 + self.LED_PIN_blue = 1 self.LED_PIN_green = 2 - self.LED_PIN_blue = 3 + self.LED_PIN_yellow = 3 self.LED_PIN_white = 4 self.BUTTON_PIN_1 = 6 @@ -50,9 +50,9 @@ class OrangePi(BaseHardware): wiringpi.wiringPiSetup() # GPIO 输出模式 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_green, GPIO.OUTPUT) + wiringpi.pinMode(self.LED_PIN_yellow, GPIO.OUTPUT) wiringpi.pinMode(self.LED_PIN_white, GPIO.OUTPUT) # GPIO 输入模式 wiringpi.pinMode(self.BUTTON_PIN_1, GPIO.INPUT) @@ -80,6 +80,9 @@ class OrangePi(BaseHardware): 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}") + elif press_duration > 5: + time.sleep(1) # 防止短按误触发 + subprocess.Popen('sudo shutdown now', shell=True) else: self.short_power_status = True # print(f"{datetime.now()}: short_power_status: {self.short_power_status} {self.long_power_status}") @@ -90,14 +93,14 @@ class OrangePi(BaseHardware): # 更新LED状态 if self.long_power_status: - self.set_led_on('white') + self.set_led_on('green') if self.short_power_status: - self.set_led_on('yellow') + self.set_led_on('blue') else: - self.set_led_off('yellow') + self.set_led_off('blue') else: self.short_power_status = False - self.set_led_off('white') + self.set_led_off('green') def set_led_on(self, color='red'): @@ -108,10 +111,10 @@ class OrangePi(BaseHardware): def start_status_light(self): for i in range(2): - self.set_led_on("white") - time.sleep(1) - self.set_led_off("white") - time.sleep(1) + self.set_led_on("green") + time.sleep(0.5) + self.set_led_off("green") + time.sleep(0.5) if __name__ == '__main__': orangepi = OrangePi()