[button] fix bugs

This commit is contained in:
IrvingGao 2024-06-18 22:04:58 +08:00
parent ae5d9bb3f5
commit bf5e27f9e0
1 changed files with 9 additions and 9 deletions

View File

@ -41,7 +41,7 @@ class OrangePi(BaseHardware):
self.power_status = False # 单次触发按键状态 self.power_status = False # 单次触发按键状态
self.long_power_status = False self.long_power_status = False
self.short_power_status = False # self.short_power_status = False
self.button_init() self.button_init()
self.init_hd_thread() self.init_hd_thread()
@ -76,13 +76,13 @@ class OrangePi(BaseHardware):
elif button_status_1 and not last_status_1: elif button_status_1 and not last_status_1:
if press_time_1: if press_time_1:
press_duration = (datetime.now() - press_time_1).total_seconds() press_duration = (datetime.now() - press_time_1).total_seconds()
if press_duration > 0.01: # if press_duration > 0.01:
self.long_power_status = not self.long_power_status if press_duration > 5:
elif press_duration > 5:
time.sleep(1) # 防止短按误触发 time.sleep(1) # 防止短按误触发
subprocess.Popen('sudo shutdown now', shell=True) subprocess.Popen('sudo shutdown now', shell=True)
else: else:
self.short_power_status = True self.long_power_status = not self.long_power_status
# self.short_power_status = True
print(f"{datetime.now()}: press_duration: {press_duration}") print(f"{datetime.now()}: press_duration: {press_duration}")
print(f"{datetime.now()}: button_status: {button_status_1}, last_button_status: {last_status_1}, power_status: {self.long_power_status}, interrupt_status: {self.short_power_status}") print(f"{datetime.now()}: button_status: {button_status_1}, last_button_status: {last_status_1}, power_status: {self.long_power_status}, interrupt_status: {self.short_power_status}")
press_time_1 = None press_time_1 = None
@ -92,10 +92,10 @@ class OrangePi(BaseHardware):
# 更新LED状态 # 更新LED状态
if self.long_power_status: if self.long_power_status:
self.set_led_on('green') self.set_led_on('green')
if self.short_power_status: # if self.short_power_status:
self.set_led_on('blue') # self.set_led_on('blue')
else: # else:
self.set_led_off('blue') # self.set_led_off('blue')
else: else:
self.short_power_status = False self.short_power_status = False
self.set_led_off('green') self.set_led_off('green')