From: p15692025051 <846603105@qq.com> Date: Thu, 13 Jul 2023 03:16:31 +0000 (+0800) Subject: 新版按键调整 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=7dfb1b88b5659eec1bfba115aef90dbff92ecf4f;p=mirrors%2FASR1603_G5.git 新版按键调整 --- diff --git a/2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py b/2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py index 44cbe135..fa56877e 100644 --- a/2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py +++ b/2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py @@ -4,8 +4,8 @@ import osTimer from misc import PowerKey import EventMesh from machine import Pin - - +from machine import ExtInt +import constants class BtnDevice(Abstract): def __init__(self, tp=None): @@ -15,14 +15,52 @@ class BtnDevice(Abstract): self.keypad = machine.KeyPad(4, 1) self.__PowerDownTimeOut = 4000 self.__tp = tp - self.long_press = 0 + self.pwk_press = 0 + self.pwk_count = 0 + self.GPIO26_status = 0 + self.powerKey_status = 0 + self.pin_timer = osTimer() def post_processor_after_instantiation(self): self.keypad.init() self.keypad.set_callback(self.key_callback) - self.pk.powerKeyEventRegister(self.pwk_callback) + self.pk.powerKeyEventRegister(self.powerKey_callback) if self.__tp: self.__tp.set_callback(self.__ui_callback) + + self.extint = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_DISABLE, self.pwk_extint_cb) + self.extint.enable() + + + + def pwk_extint_cb(self,args): + #print('### interrupt {} '.format(args)) # args[0]:gpio号 args[1]:上升沿或下降沿 + + #print('==pwr:', status)# 0 1 0 + self.GPIO26_status = self.extint.read_level() + #print("1GPIO_extint_cb:self.GPIO26_status:{} self.pwk_press:{} args:{}".format(self.GPIO26_status,self.pwk_press,args)) + if self.GPIO26_status == 0:#按下 + if(self.pwk_press == 0) : + self.pwk_press = 1 + self.__pwk_timer.start(100, 1, self.pwk_press_cb) + print("1GPIO_extint_cb:self.__pwk_timer.start!!!!\n") + def pwk_press_cb(self, *args): + '''KEY2:联动屏幕右下角或返回键长按关机''' + if self.pwk_press == 1 : + #print("3pwk_press_cb:self.pwk_count:{} self.GPIO26_status:{}".format(self.pwk_count,self.GPIO26_status)) + self.pwk_count += 1 + # + if self.GPIO26_status == 1:#松开 + if(self.pwk_count >= 1): #防抖100ms + self.__pwk_timer.stop() + self.pwk_count = 0 + self.pwk_press = 0 + EventMesh.publish("btn8_press") + if self.pwk_count > (self.__PowerDownTimeOut//100): #长按 + self.__pwk_timer.stop() + self.pwk_count = 0 + self.pwk_press = 0 + EventMesh.publish("btn8_long_press") def __ui_callback(self, para): # print("para = {}".format(para)) @@ -58,7 +96,7 @@ class BtnDevice(Abstract): pass if (l_list[1] == 3) and (l_list[2] == 0): if l_list[0] == 1: - self.long_press = 0 + #self.pwk_press = 0 EventMesh.publish("btn1_press") else: pass @@ -67,22 +105,29 @@ class BtnDevice(Abstract): - def pwk_callback(self, status): + def powerKey_callback(self, status): print('==pwr:', status)# 0 1 0 - if status == 1:#按下 - self.__pwk_timer.start(self.__PowerDownTimeOut, 0, self.__pwk_long_press_cb) - elif status == 0:#松开 - self.__pwk_timer.stop() - # print("btn_back:{}".format(mdls.screen_size_style[mdls.models][1])) - if self.long_press != 0: - self.long_press = 0 - return - EventMesh.publish("btn8_press") + self.powerKey_status = status + if self.pwk_press == 1: #按按钮时不处理 + return + if status == 1:#拔出 + # if(self.GPIO26_status == 1): + # EventMesh.publish("btn8_press") + #self.__pwk_timer.start(self.__PowerDownTimeOut, 0, self.pwk_press_cb) + EventMesh.publish(constants.EVENT.SYSTEM_UP) + pass + elif status == 0:#插入usb + EventMesh.publish(constants.EVENT.SYSTEM_UP) + # self.__pwk_timer.stop() + # # print("btn_back:{}".format(mdls.screen_size_style[mdls.models][1])) + # if self.pwk_press != 0: + # self.pwk_press = 0 + # return + # if(self.GPIO26_status == 1): + # EventMesh.publish("btn8_press") + #pass - def __pwk_long_press_cb(self, *args): - '''KEY2:联动屏幕右下角或返回键长按关机''' - self.long_press = 1 - EventMesh.publish("btn8_long_press") + def start(self): self.post_processor_after_instantiation()