else:
# self.pwk_key = ExtInt(ExtInt.GPIO41, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
self.pwk_key = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
- self.extint_AI = ExtInt(ExtInt.GPIO22,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
+ # self.extint_AI = ExtInt(ExtInt.GPIO26,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
- self.extint_AI.enable()
+ # self.extint_AI.enable()
self.pwk_key_status = 0
self.pwk_key_timer_count = 0
self.pwk_key_long_press = 0
self.pwk_is_double_timer = osTimer()
self.double_click_threshold = 1000#双击间隔时间
self.pwk_press_count = 0#按下次数
+ self.pwk_timer_running = False # 定时器是否有效
self.last_key_time = 0 # 上一次有效触发时间
self.key_debounce_interval = 20 # 防抖窗口20ms,标准值
#self.pwk_key = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_DISABLE, self.pwk_extint_cb)
# 停止旧定时器,启动长按/单击判定定时器(100ms单次触发,循环靠回调自启)
self.pwk_key_timer.stop()
+ self.pwk_timer_running = True#定时器开始运行
self.pwk_key_timer.start(100, 1, self.pwk_key_timer_cb)
print("第一次按下,等待第二次按下")
#符合双击阈值:执行双击逻辑
if interval <= self.double_click_threshold:
self.pwk_key_timer.stop() # 停止长按定时器(关键:避免触发长按)
- self.pwk_key_double_press() # 执行双击业务
+ EventMesh.publish("publish_AI_btnInfo",{"func":self.pwk_key_release})
+ # self.pwk_key_double_press() # 执行双击业务
print("双击生效")
# 重置所有状态
self.pwk_press_count = 0
def pwk_key_timer_cb(self, *args, **kwargs):
+ if not self.pwk_timer_running:
+ return
EventMesh.publish("set_wait_first_flag",0)
EventMesh.publish("set_history_board_flag",0)
EventMesh.publish("set_play_new_voice_state",0)
key_count = 5
if dev_type == "7PIN_BK" or dev_type == "7PIN_BK_EU"or dev_type == "7PIN_BK_coze":
key_count = 3
- if self.pwk_key_timer_count >= key_count: #防抖200ms
+ if self.pwk_key_timer_count >= key_count: #防抖
#EventMesh.publish("AI_key_release")
- EventMesh.publish("publish_AI_btnInfo",{"func":self.pwk_key_release})
+ print("触发单击+1")
+ self.AI_key_press()#执行单击业务
+ self.pwk_key_timer.stop()
+ print("self.pwk_key_timer.stop状态:{}".format(self.pwk_key_timer.stop()))
+ self.pwk_timer_running = False
self.pwk_key.enable()
self.pwk_key_timer_count = 0
self.pwk_key_press = 0
self.pwk_press_count = 0#按下次数
- self.pwk_key_timer.stop()
+
except Exception as e:
usys.print_exception(e)