1.微聊语音键功能增加已基本完善
authordxy15521469561 <1731678236@qq.com>
Thu, 27 Jul 2023 02:47:28 +0000 (10:47 +0800)
committerdxy15521469561 <1731678236@qq.com>
Thu, 27 Jul 2023 02:47:28 +0000 (10:47 +0800)
2.灯得逻辑未做完善
3.sos键还未做完善

2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/Makefile
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/appWechat.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_1.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/sleep_test.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/ui.py
2.sdk/project/D10/usr/main.py

index d8b4f8a..a1e1e9f 100644 (file)
@@ -947,17 +947,28 @@ frozen_mpy_list =         $(BUILD)/_boot.mpy \
                                        $(BUILD)/uping.mpy \
                                        $(BUILD)/ymodem.mpy \
                                        $(BUILD)/alarm.mpy \
+                                       $(BUILD)/appAlipay.mpy \
+                                       $(BUILD)/appFactoryMode.mpy \
                                        $(BUILD)/appWechat.mpy \
                                        $(BUILD)/btn_device_ec800m.mpy \
+                                       $(BUILD)/capacitive_hynitron_cst816d_update.mpy \
+                                       $(BUILD)/code.mpy \
                                        $(BUILD)/common.mpy \
                                        $(BUILD)/constants.mpy \
                                        $(BUILD)/EventMesh.mpy \
+                                       $(BUILD)/initTP.mpy \
+                                       $(BUILD)/lcd.mpy \
                                        $(BUILD)/location.mpy \
                                        $(BUILD)/mgr.mpy \
                                        $(BUILD)/protocol.mpy \
                                        $(BUILD)/ui.mpy \
+                                       $(BUILD)/ui_main_menu.mpy \
+                                       $(BUILD)/ui_setting.mpy \
+                                       $(BUILD)/ui_WatchFaceScreen.mpy \
+                                       $(BUILD)/ui_health.mpy \
                                        $(BUILD)/main_init.mpy \
                                        $(BUILD)/versions.mpy \
+                                       $(BUILD)/led.mpy \
 
 endif
 
index bb99d19..e1391a3 100644 (file)
@@ -180,8 +180,8 @@ class WechatScreen(Screen):
             self.wechat_list_dict.append({"num":i,"wechat_btn":wechat_btn,"_btn_label1":_btn_label1,"_btn_label2":_btn_label2,"_btn_img":_btn_img})
 
         EventMesh.subscribe("wechat_updata_list_show", self.wechat_updata_list_show)
-        EventMesh.subscribe("get_wechat_data", self.get_wechat_data)
-        EventMesh.subscribe("set_wechat_data", self.set_wechat_data)
+        # EventMesh.subscribe("get_wechat_data", self.get_wechat_data)
+        # EventMesh.subscribe("set_wechat_data", self.set_wechat_data)
 
         EventMesh.subscribe("get_aduio_state", self.get_aduio_state)
         EventMesh.subscribe("get_send_state", self.get_send_state)
@@ -655,174 +655,174 @@ class NewWechatPopupScreen(Screen):
 
 
 
-class TK_ProtoCol(ProtoCol):
-    """微聊"""
-    TYPE = "TK"
+# class TK_ProtoCol(ProtoCol):
+#     """微聊"""
+#     TYPE = "TK"
     
 
-    def send(self, event, msg):
-        # [SZKW*YYYYYYYYYYYYYYY*LEN*TK,AMR 格式音频数据]
-        #[XT*YYYYYYYYYYYYYYY*LEN*TKS,秒数(十进制),AMR 格式音频数据]
-        arm_data = msg[1]
-        arm_sec = msg[0]
-        Wechat_log("TK_ProtoCol:msgtype:{} arm_sec:{}".format(type(msg),arm_sec))
-
-        arm = bytearray()
-        for i in range(len(arm_data)):
-            if arm_data[i] == 0x7d:
-                arm.extend(b'\x7d\x01')
-            elif arm_data[i] == 0x5b :
-                arm.extend(b'\x7d\x02')
-            elif arm_data[i] == 0x5d :
-                arm.extend(b'\x7d\x03')
-            elif arm_data[i] == 0x2c :
-                arm.extend(b'\x7d\x04')
-            elif arm_data[i] == 0x2a :
-                arm.extend(b'\x7d\x05')
-            else :
-                arm.append(arm_data[i])
+#     def send(self, event, msg):
+#         # [SZKW*YYYYYYYYYYYYYYY*LEN*TK,AMR 格式音频数据]
+#         #[XT*YYYYYYYYYYYYYYY*LEN*TKS,秒数(十进制),AMR 格式音频数据]
+#         arm_data = msg[1]
+#         arm_sec = msg[0]
+#         Wechat_log("TK_ProtoCol:msgtype:{} arm_sec:{}".format(type(msg),arm_sec))
+
+#         arm = bytearray()
+#         for i in range(len(arm_data)):
+#             if arm_data[i] == 0x7d:
+#                 arm.extend(b'\x7d\x01')
+#             elif arm_data[i] == 0x5b :
+#                 arm.extend(b'\x7d\x02')
+#             elif arm_data[i] == 0x5d :
+#                 arm.extend(b'\x7d\x03')
+#             elif arm_data[i] == 0x2c :
+#                 arm.extend(b'\x7d\x04')
+#             elif arm_data[i] == 0x2a :
+#                 arm.extend(b'\x7d\x05')
+#             else :
+#                 arm.append(arm_data[i])
                
-        datalen = len(arm) + 4+len(str(arm_sec))+1
-        #Wechat_log("len(str(arm_sec)):{}".format(len(str(arm_sec))+1))
-        send_data = bytearray("SZKW*%s*%04X*TKS,%d,"%(self.imei,datalen,arm_sec))
-        send_data.extend(arm)
-        MD5_SIGN = self.pack_MD5_head(send_data)
-        data = bytearray('[')
-        data.extend(MD5_SIGN)
-        data.extend(send_data)
-        data.extend(']')
-        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
-
-    def recv(self, event, msg):
-        """
+#         datalen = len(arm) + 4+len(str(arm_sec))+1
+#         #Wechat_log("len(str(arm_sec)):{}".format(len(str(arm_sec))+1))
+#         send_data = bytearray("SZKW*%s*%04X*TKS,%d,"%(self.imei,datalen,arm_sec))
+#         send_data.extend(arm)
+#         MD5_SIGN = self.pack_MD5_head(send_data)
+#         data = bytearray('[')
+#         data.extend(MD5_SIGN)
+#         data.extend(send_data)
+#         data.extend(']')
+#         EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+
+#     def recv(self, event, msg):
+#         """
 
         
-        @param event: 微聊
-        @param msg: 接收到的下行数据
-        [SZKW*860132060004322*20BD*TK,#!AMR...]
-        """
-        #Wechat_log("K_ProtoCol:recv:data:{}".format(msg))
-        msg_tmp = msg.decode('ascii')
-        str = msg_tmp.split('TK,')
-        # Wechat_log("TK_ProtoCol:recv:len:{} {} {}".format(len(msg),len(str),msg_tmp.find("#!AMR")))
-        if  msg_tmp.find("#!AMR") != -1: #是否是服务器下发音频数据
-            # Wechat_log("TK_ProtoCol:recv:datalen{}".format(len(msg)))
-            arm_data = bytearray(str[1])#获取amr输出
-            get_wechat_data = EventMesh.publish("get_wechat_data")
+#         @param event: 微聊
+#         @param msg: 接收到的下行数据
+#         [SZKW*860132060004322*20BD*TK,#!AMR...]
+#         """
+#         #Wechat_log("K_ProtoCol:recv:data:{}".format(msg))
+#         msg_tmp = msg.decode('ascii')
+#         str = msg_tmp.split('TK,')
+#         # Wechat_log("TK_ProtoCol:recv:len:{} {} {}".format(len(msg),len(str),msg_tmp.find("#!AMR")))
+#         if  msg_tmp.find("#!AMR") != -1: #是否是服务器下发音频数据
+#             # Wechat_log("TK_ProtoCol:recv:datalen{}".format(len(msg)))
+#             arm_data = bytearray(str[1])#获取amr输出
+#             get_wechat_data = EventMesh.publish("get_wechat_data")
             
-            MXA_MSG = get_wechat_data[0]
-            wechat_recode_list = get_wechat_data[1]
-            wechat_num = wechat_recode_list["num"]
-            # Wechat_log("TK_ProtoCol:datalen:{} {} {}".format(wechat_num,MXA_MSG,wechat_recode_list))
+#             MXA_MSG = get_wechat_data[0]
+#             wechat_recode_list = get_wechat_data[1]
+#             wechat_num = wechat_recode_list["num"]
+#             # Wechat_log("TK_ProtoCol:datalen:{} {} {}".format(wechat_num,MXA_MSG,wechat_recode_list))
             
-            if wechat_num >= MXA_MSG:
-                wechat_num = 0 
-            if wechat_num == 0:
-                wechat_num += 1 
-            elif wechat_num > 0:
-                wechat_num += 1 
+#             if wechat_num >= MXA_MSG:
+#                 wechat_num = 0 
+#             if wechat_num == 0:
+#                 wechat_num += 1 
+#             elif wechat_num > 0:
+#                 wechat_num += 1 
           
 
-            Wechat_log("num_total:datalen:{} {}".format(MXA_MSG,wechat_recode_list))
-            wechat_recode_list["%02d"%(wechat_num)] = "R:{}".format(3)
-            wechat_recode_list['num'] = wechat_num
-            EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_recode_list])
-            #写语音文件数据
-            screen_NAME = EventMesh.publish("get_screen_NAME")
-            get_lcd_state = EventMesh.publish("get_lcd_state")
-            if screen_NAME != "wechat" or get_lcd_state == 0:
-                EventMesh.publish("load_screen", {"screen": "wechat_popup"})
-            else:
-                EventMesh.publish("wechat_updata_list_show")
-            # path = "/usr/static/storage_file/audio_amr/amr/{}.amr".format(wechat_num)
-            path = "/usr/static/storage_file/{}.amr".format(wechat_num)
-            with open(path,"w") as fd:
-                arm = bytearray()
-                j = 0
-                for i in range(len(arm_data)):
-                    if arm_data[j] == 0x7d and arm_data[j+1] == 0x01:
-                        arm.extend(b'\x7d')
-                        j+=1
-                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x02:
-                        arm.extend(b'\x5b')
-                        j+=1
-                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x03:
-                        arm.extend(b'\x5d')
-                        j+=1
-                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x04:
-                        arm.extend(b'\x2c')
-                        j+=1
-                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x05:
-                        arm.extend(b'\x2a')
-                        j+=1
-                    else :
-                        arm.append(arm_data[j])
-                    j+=1
-                    if j >= len(arm_data):
-                        break
-                fd.write(arm)
+#             Wechat_log("num_total:datalen:{} {}".format(MXA_MSG,wechat_recode_list))
+#             wechat_recode_list["%02d"%(wechat_num)] = "R:{}".format(3)
+#             wechat_recode_list['num'] = wechat_num
+#             EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_recode_list])
+#             #写语音文件数据
+#             screen_NAME = EventMesh.publish("get_screen_NAME")
+#             get_lcd_state = EventMesh.publish("get_lcd_state")
+#             if screen_NAME != "wechat" or get_lcd_state == 0:
+#                 EventMesh.publish("load_screen", {"screen": "wechat_popup"})
+#             else:
+#                 EventMesh.publish("wechat_updata_list_show")
+#             # path = "/usr/static/storage_file/audio_amr/amr/{}.amr".format(wechat_num)
+#             path = "/usr/static/storage_file/{}.amr".format(wechat_num)
+#             with open(path,"w") as fd:
+#                 arm = bytearray()
+#                 j = 0
+#                 for i in range(len(arm_data)):
+#                     if arm_data[j] == 0x7d and arm_data[j+1] == 0x01:
+#                         arm.extend(b'\x7d')
+#                         j+=1
+#                     elif arm_data[j] == 0x7d and arm_data[j+1] == 0x02:
+#                         arm.extend(b'\x5b')
+#                         j+=1
+#                     elif arm_data[j] == 0x7d and arm_data[j+1] == 0x03:
+#                         arm.extend(b'\x5d')
+#                         j+=1
+#                     elif arm_data[j] == 0x7d and arm_data[j+1] == 0x04:
+#                         arm.extend(b'\x2c')
+#                         j+=1
+#                     elif arm_data[j] == 0x7d and arm_data[j+1] == 0x05:
+#                         arm.extend(b'\x2a')
+#                         j+=1
+#                     else :
+#                         arm.append(arm_data[j])
+#                     j+=1
+#                     if j >= len(arm_data):
+#                         break
+#                 fd.write(arm)
             
             
             
 
-class MESSAGE_ProtoCol(ProtoCol):
-    """微聊"""
-    TYPE = "MESSAGE"
+# class MESSAGE_ProtoCol(ProtoCol):
+#     """微聊"""
+#     TYPE = "MESSAGE"
     
 
-    def send(self, event, msg):
+#     def send(self, event, msg):
        
-        #[XT*334588000000156*0007*MESSAGE]
-        send_data = "SZKW*%s*0007*MESSAGE"%(self.imei)
-        MD5_SIGN = self.pack_MD5_head(send_data)
-        data = "[%s%s]"%(str(MD5_SIGN),send_data)
-        #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data))
-        # 通过socket发送到服务器端
-        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
-
-    def recv(self, event, msg):
-        """
-
-        @param event: 微聊文字
-        @param msg: 接收到的下行数据
-        """
-        msg = msg[1:-1]
-
-        msg_s = msg.decode('ascii')
-        msg_s = msg_s.split(',')
-        msg_s = msg_s[1]
-        # Wechat_log("msg_tmp:len:{}\r\n data:{}".format(len(msg_s),msg_s))
+#         #[XT*334588000000156*0007*MESSAGE]
+#         send_data = "SZKW*%s*0007*MESSAGE"%(self.imei)
+#         MD5_SIGN = self.pack_MD5_head(send_data)
+#         data = "[%s%s]"%(str(MD5_SIGN),send_data)
+#         #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data))
+#         # 通过socket发送到服务器端
+#         EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+
+#     def recv(self, event, msg):
+#         """
+
+#         @param event: 微聊文字
+#         @param msg: 接收到的下行数据
+#         """
+#         msg = msg[1:-1]
+
+#         msg_s = msg.decode('ascii')
+#         msg_s = msg_s.split(',')
+#         msg_s = msg_s[1]
+#         # Wechat_log("msg_tmp:len:{}\r\n data:{}".format(len(msg_s),msg_s))
         
 
-        get_wechat_data = EventMesh.publish("get_wechat_data")
+#         get_wechat_data = EventMesh.publish("get_wechat_data")
         
-        MXA_MSG = get_wechat_data[0]
-        wechat_recode_list = get_wechat_data[1]
-        wechat_num = wechat_recode_list["num"]
-        # Wechat_log("TK_ProtoCol:datalen:{} {} {}".format(wechat_num,MXA_MSG,wechat_recode_list))
+#         MXA_MSG = get_wechat_data[0]
+#         wechat_recode_list = get_wechat_data[1]
+#         wechat_num = wechat_recode_list["num"]
+#         # Wechat_log("TK_ProtoCol:datalen:{} {} {}".format(wechat_num,MXA_MSG,wechat_recode_list))
         
-        if wechat_num >= MXA_MSG:
-            wechat_num = 0 
-        if wechat_num == 0:
-            wechat_num += 1 
-        elif wechat_num > 0:
-            wechat_num += 1 
-        msg_txt = {}
-        # 0 1 2 3
-        Wechat_log("wechat_num:init {}".format(wechat_num))
-        msg_txt = UnicodeHexStr_To_Utf8Str(msg_s)
-        # Wechat_log("msg_txt:{}".format(msg_txt))
-        wechat_recode_list["%02d"%(wechat_num)] = "T:{}".format(msg_txt)
-        wechat_recode_list['num'] = wechat_num
-        EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_recode_list])
-        # Wechat_log("wechat_recode_list:len data:{}".format(wechat_recode_list))
-        EventMesh.publish(constants.PROTOCOL.MESSAGE_SEND)
-        screen_NAME = EventMesh.publish("get_screen_NAME")
-        get_lcd_state = EventMesh.publish("get_lcd_state")
-        if screen_NAME != "wechat" or get_lcd_state == 0:
-            EventMesh.publish("load_screen", {"screen": "wechat_popup"})
-        else:
-            EventMesh.publish("wechat_updata_list_show")
+#         if wechat_num >= MXA_MSG:
+#             wechat_num = 0 
+#         if wechat_num == 0:
+#             wechat_num += 1 
+#         elif wechat_num > 0:
+#             wechat_num += 1 
+#         msg_txt = {}
+#         # 0 1 2 3
+#         Wechat_log("wechat_num:init {}".format(wechat_num))
+#         msg_txt = UnicodeHexStr_To_Utf8Str(msg_s)
+#         # Wechat_log("msg_txt:{}".format(msg_txt))
+#         wechat_recode_list["%02d"%(wechat_num)] = "T:{}".format(msg_txt)
+#         wechat_recode_list['num'] = wechat_num
+#         EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_recode_list])
+#         # Wechat_log("wechat_recode_list:len data:{}".format(wechat_recode_list))
+#         EventMesh.publish(constants.PROTOCOL.MESSAGE_SEND)
+#         screen_NAME = EventMesh.publish("get_screen_NAME")
+#         get_lcd_state = EventMesh.publish("get_lcd_state")
+#         if screen_NAME != "wechat" or get_lcd_state == 0:
+#             EventMesh.publish("load_screen", {"screen": "wechat_popup"})
+#         else:
+#             EventMesh.publish("wechat_updata_list_show")
             
 
 
index 1b022b6..8bdee13 100644 (file)
@@ -6,13 +6,820 @@ import EventMesh
 from machine import Pin
 from machine import ExtInt
 import constants
+import utime
+import audio
+import ql_fs
+import ujson
+import voiceCall
+from misc import Power
+from usr.led import red_green_light,green_light_fast,led_mode,open_led_red,close_led_red,open_led_green,close_led_green
+
+class powerOFFManager(Abstract):#关机
+    def __init__(self):
+        self.timer = osTimer()
+        
+        pass
+        
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("long_press_power_off", self.long_press_power_off)#
+
+
+    def long_press_power_off(self, event, msg): #msg 1 开始测量 2 测量成功 3 测量失败未出值
+        self.timer.start(5000,0,self.fun)
+        EventMesh.publish("set_led_time_arg",[1000,200,6,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE])#測量失敗
+        
+
+    def fun(self, *args):
+        Power.powerDown()
+
+class playCurStepManager(Abstract):#播报当前步数
+    def __init__(self):
+        self.timer = osTimer()
+        self.count = 0
+        self.setp_old = 0
+        self.aud = audio.Audio(0)
+        self.aud.set_pa(Pin.GPIO29)
+        self.aud.setVolume(11)
+        self.step_tmp = ""
+        self.step_num = 0
+        pass
+        
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("play_cur_step_event", self.play_cur_step_event)#
+
+
+    def play_cur_step_event(self, event, msg): #msg 1 开始测量 2 测量成功 3 测量失败未出值
+        self.count = 0
+        self.timer.start(200,1,self.fun)
+    
+    def fun(self, *args):
+        step = EventMesh.publish("get_old_step_value")
+        play_state = EventMesh.publish("get_audio_state")#音频播放状态
+        # print("step fun!!!!!!!!!!!")
+        if self.setp_old != step:
+            self.count = 0
+            self.step_num = 0
+        self.setp_old = step
+        step = 11
+        if step <= 10:#个
+            if play_state != None:
+                if play_state == 0:
+                    self.count+=1
+                    # print("step self.count!!!!!!!!!!",self.count)
+                    if self.count == 1:
+                        if step == 10:
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #播放imei号
+                        else:
+                            self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(step))  #播放imei号
+                    elif self.count == 2:
+                        self.count = 0
+                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #播放imei号
+                        self.timer.stop()
+                        
+        elif step <= 100:#十 90
+            if step >= 100:
+                if play_state != None:
+                    if play_state == 0:
+                        self.count+=1
+                        if self.count == 1:
+                            self.aud.play(1, 1, 'U:/static/R_READ_TIME_1.mp3')  #1
+                        elif self.count == 2:
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                        elif self.count == 3:
+                            self.count = 0
+                            self.timer.stop()
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #播放步音频
+                pass
+            else:
+                self.step_tmp = str(step)
+                shi_value = int(self.step_tmp[0])#十
+                ge_value = int(self.step_tmp[1])#个
+                if play_state != None:
+                    if play_state == 0:
+                        if shi_value > 1:
+                            self.count+=1
+                            if self.count == 1:
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #9 90
+                            elif self.count == 2:
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                            elif self.count == 3 or self.count == 4:
+                                if ge_value == 0 or self.count == 4:
+                                    self.count = 0
+                                    self.timer.stop()
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #播放步音频
+                                else:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #播放
+                        else:
+                            self.count+=1
+                            if self.count == 1:
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                            elif self.count == 2:
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #播放
+                            elif self.count == 3:
+                                self.count = 0
+                                self.timer.stop()
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #播放步音频放
+        elif step <= 1000:#百
+            if step >= 1000:
+                if play_state != None:
+                    if play_state == 0:
+                        self.count+=1
+                        if self.count == 1:#1 109步 110步 114步 
+                            self.aud.play(1, 1, 'U:/static/R_READ_TIME_1.mp3')  #播放
+                        elif self.count == 2:#百
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千
+                        elif self.count == 3:#1
+                            self.count = 0
+                            self.timer.stop()
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+            else:
+                self.step_tmp = str(step)
+                bai_value = int(self.step_tmp[0])#百
+                shi_value = int(self.step_tmp[1])#十
+                ge_value = int(self.step_tmp[2])#个
+                #101 110 1
+                if shi_value > 0:#110
+                    if play_state != None:
+                        if play_state == 0:
+                            self.count+=1
+                            if self.count == 1:
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))  #2
+                            elif self.count == 2:
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                            elif self.count == 3:
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #1
+                            elif self.count == 4:
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                            elif self.count == 5 or self.count == 6:
+                                if ge_value == 0 or self.count == 6:
+                                    self.count = 0
+                                    self.timer.stop()
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                else:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #1
+                else:
+                    if play_state != None:
+                        if play_state == 0:
+                            self.count+=1
+                            if self.count == 1:
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))  #2
+                            elif self.count == 2:
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                            elif self.count == 3:
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                            elif self.count == 4 :
+                                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #1
+                            elif self.count == 5:
+                                self.count = 0
+                                self.timer.stop()
+                                self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+        elif step <= 10000:#千
+            if step >= 10000:
+                if play_state != None:
+                    if play_state == 0:
+                        self.count+=1
+                        if self.count == 1:#1 109步 110步 114步 
+                            self.aud.play(1, 1, 'U:/static/R_READ_TIME_1.mp3')  #播放
+                        elif self.count == 2:#百
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #千
+                        elif self.count == 3:#1
+                            self.count = 0
+                            self.timer.stop()
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                pass
+            else:
+                one_thousand = step//1000 #千
+                one_hundred = step%1000 #百
+                baishu = step%100 #十
+                shishu = step%10 #个
+                print(one_thousand,one_hundred,baishu,shishu)
+
+                if play_state != None:
+                    if play_state == 0:
+                        self.count += 1
+                        self.step_tmp = str(step)
+                        qian = int(self.step_tmp[0])#千
+                        bai_value = int(self.step_tmp[1])#百
+                        shi_value = int(self.step_tmp[2])#十
+                        ge_value = int(self.step_tmp[3])#个
+                        # 1009
+                        # 1010
+                        # 1109
+                        # 1110
+                        if bai_value <= 0:
+                            if shi_value <= 0:
+                                if self.count == 1:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1  
+                                elif self.count == 2:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千 
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0  
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #0  
+                                elif self.count == 5:
+                                    self.count = 0
+                                    self.timer.stop()
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                pass
+                            else:
+                                if self.count == 1:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1  
+                                elif self.count == 2:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千 
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0  
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #0  
+                                elif self.count == 5:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                                elif self.count == 6:
+                                    if ge_value == 0:
+                                        self.count = 0
+                                        self.timer.stop()
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                    else:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #0  
+                                elif self.count == 7:
+                                    self.count = 0
+                                    self.timer.stop()
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                        else:
+                            if shi_value <= 0:#11
+                                if self.count == 1:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1  
+                                elif self.count == 2:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千 
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))  #0
+                                    # self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0  
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                                elif self.count == 5:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                elif self.count == 6:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #0
+                                elif self.count == 7:
+                                    self.count = 0
+                                    self.timer.stop()
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                pass
+                            else:
+                                if self.count == 1:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1  
+                                elif self.count == 2:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千 
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))  #0
+                                    # self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0  
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                                elif self.count == 5:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #0
+                                    # self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                elif self.count == 6:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                                    # self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #0
+                                elif self.count == 7 or self.count == 8:
+                                    if ge_value == 0 or self.count == 8:
+                                        self.count = 0
+                                        self.timer.stop()
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步    
+                                    else:
+                                       self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #0               
+
+
+            pass
+        elif step <= 100000:#万
+            if step >= 100000:#10万步
+                if play_state != None:
+                    if play_state == 0:
+                        self.count += 1
+                        if self.count == 1:
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十   
+                        elif self.count == 2:
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                        elif self.count == 3:
+                            self.count = 0
+                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                            self.timer.stop()
+            else:
+                if play_state != None:
+                    if play_state == 0:
+                        self.count += 1
+                        self.step_tmp = str(step)
+                        wang = int(self.step_tmp[0])#万
+                        qian = int(self.step_tmp[1])#千
+                        bai_value = int(self.step_tmp[2])#百
+                        shi_value = int(self.step_tmp[3])#十
+                        ge_value = int(self.step_tmp[4])#个
+                        if wang > 0 and qian > 0 and bai_value > 0:#11109 11111
+                            if shi_value <= 0:
+                                if self.count ==1:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                elif self.count == 2:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1  self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')    #千
+                                elif self.count == 5:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))
+                                    # self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')#0
+                                elif self.count == 6:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')#百
+                                elif self.count == 7:
+                                    if ge_value == 0:
+                                        self.count = 0
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                        self.timer.stop()
+                                    else:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')
+                                elif self.count == 8:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))
+                                elif self.count == 9:
+                                    self.count = 0
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                    self.timer.stop()
+                            else:
+                                if self.count ==1:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                elif self.count == 2:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1  self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')    #千
+                                elif self.count == 5:#1
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))
+                                elif self.count == 6:#百
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')
+                                elif self.count == 7:#1
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))
+                                elif self.count == 8 :#十
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')
+                                if self.count == 9 or self.count == 10:#十
+                                    if ge_value == 0 or self.count == 10:
+                                        self.count = 0
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                        self.timer.stop()
+                                    else:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))
+                        elif wang > 0 and qian > 0:#11000 11010 11012
+                            if shi_value > 0:
+                                if self.count == 1:#
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                elif self.count == 2:#万
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1 
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千
+                                elif self.count == 5:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                elif self.count == 6:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #9
+                                elif self.count == 7:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                                elif  self.count == 8 or self.count == 9:
+                                    if ge_value == 0 or self.count == 9:
+                                        self.count = 0
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                        self.timer.stop()
+                                    else:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #个
+                            else:   
+                                if self.count == 1:#
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                elif self.count == 2:#万
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                elif self.count == 3:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(qian))  #1 
+
+                                elif self.count == 4:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_1.mp3')  #千
+                                elif self.count == 5:
+                                    if shi_value == 0 and ge_value == 0:
+                                        self.count = 0
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                        self.timer.stop()
+                                    else:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                elif self.count == 6:
+                                    self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #9
+                                elif self.count == 7:
+                                    self.count = 0
+                                    self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                    self.timer.stop()
+                                pass   
+
+                        elif wang > 0:#
+                            if bai_value > 0:#百
+                                if shi_value > 0:#10110
+                                    if self.count == 1:#
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                    elif self.count == 2:#万
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                    elif self.count == 3:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                    elif self.count == 4:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))  #1
+                                    elif self.count == 5:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                                    elif self.count == 6:
+                                        
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #9
+                                    elif self.count == 7:
+
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                                    elif  self.count == 8 or self.count == 9:
+                                        if ge_value == 0 or self.count == 9:
+                                            self.count = 0
+                                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                            self.timer.stop()
+                                        else:
+                                            self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #个
+                                else:#10109
+                                    if self.count == 1:#
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                    elif self.count == 2:#万
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                    elif self.count == 3:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                    elif self.count == 4:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(bai_value))  #1
+                                    elif self.count == 5:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_2.mp3')  #百
+                                    elif self.count == 6:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+                                        
+                                    elif self.count == 7:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #1
+                                        # self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                                    elif  self.count == 8:
+                                        self.count = 0
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                        self.timer.stop()
+                            else:#10010
+                                if shi_value > 0:
+                                    if self.count == 1:#
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                    elif self.count == 2:#万
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                    elif self.count == 3:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+
+                                    elif self.count == 4:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(shi_value))  #9
+                                        
+                                    elif self.count == 5:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_3.mp3')  #十
+                                    elif self.count == 6 or self.count == 7:
+                                        if ge_value == 0 or self.count == 7:
+                                            self.count = 0
+                                            self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                            self.timer.stop()
+                                        else:
+                                            self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #个
+
+                                else:   #10008
+                                    if self.count == 1:#
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(wang))  #1  
+                                    elif self.count == 2:#万
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_0.mp3')  #万
+                                    elif self.count == 3:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_0.mp3')  #0
+
+                                    elif self.count == 4:
+                                        self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(ge_value))  #9
+                                    elif self.count == 5:
+                                        self.count = 0
+                                        self.aud.play(1, 1, 'U:/static/R_READ_STEP_4.mp3')  #步
+                                        self.timer.stop()
+                                pass   
+       
+
+class phonecallManager(Abstract):#是否正在电话呼叫中
+    def __init__(self):
+        self.call_state = 0
+        self.timer = osTimer()
+        self.aud = audio.Audio(0)
+        self.aud.set_pa(Pin.GPIO29)
+        self.aud.setVolume(11)
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("set_call_state", self.set_call_state)#
+        EventMesh.subscribe("get_call_state", self.get_call_state)#
+        EventMesh.subscribe("interup_call_event", self.interup_call_event)#
+        EventMesh.subscribe("answer_call_event", self.answer_call_event)#接听电话
+        EventMesh.subscribe("dialin_call_event", self.dialin_call_event)#电话拨进响铃
+        EventMesh.subscribe("call_test_event", self.call_test_event)#电话拨进响铃
+
+    def answer_call_event(self, event, msg): #
+        if self.call_state == 2:
+            self.timer.stop()
+            self.aud.stop()
+            voiceCall.callAnswer()
+
+    def set_call_state(self, event, msg): #
+        self.call_state = msg
+
+    def dialin_call_event(self, event, msg):
+        self.timer.start(6000, 1, self.call_timer_cb)
+        self.aud.play(1, 1, 'U:/static/R_CALL_mp3.mp3')  #播放来电铃声
+    
+    def call_timer_cb(self,*agrs):
+        if self.call_state != 2:
+            self.timer.stop()
+            self.aud.stop()
+            return
+        self.aud.play(1, 1, 'U:/static/R_CALL_mp3.mp3')  #播放来电铃声
+    def call_test_event(self, event, msg):
+        voiceCall.callStart(str("10086"))
+
+    def get_call_state(self, event, msg):
+        return self.call_state
+    
+    def interup_call_event(self, event, msg):
+        flag = EventMesh.publish("get_call_state")
+        if flag != 2:
+            voiceCall.callEnd()
+
+class closeAudioManager(Abstract):#关闭音频文件
+    def __init__(self):
+        self.aud = audio.Audio(0)
+        pass
+        
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("close_audio_play", self.close_audio_play)#
+
+
+    def close_audio_play(self, event, msg): #msg 1 开始测量 2 测量成功 3 测量失败未出值
+        play_state = EventMesh.publish("get_audio_state")#音频播放状态
+        if play_state != None:
+            if play_state != 0:#在上一个界面在播放音频时切换界面则关闭 以免一直播放
+                self.aud.stop()
+
+
+class resetFactoryUnbindManager(Abstract):#按键按下恢复出厂设置解绑app
+    def __init__(self):
+        pass
+        
+    
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("reset_factor_setiing", self.reset_factor_setiing)#恢复出厂设置
+    
+    def reset_factor_setiing(self, event, msg):
+        ret = 0
+        ret = ql_fs.path_exists("/usr/static/storage_file")#电话本
+        if ret == True:
+            ql_fs.rmdirs("/usr/static/storage_file")
+            ql_fs.mkdirs("/usr/static/storage_file")
+        EventMesh.publish("alipay_unbind")
+        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:
+            Power.powerRestart()
+        else:
+            EventMesh.publish(constants.PROTOCOL.DLT_SEND)
+
+class hrandBloodOxgenManager(Abstract):#查找设备
+    def __init__(self):
+        self.timer = osTimer()
+        self.get_hr_state  = 0
+        self.get_spo2_state = 0
+        pass
+        
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("close_hr_sop2", self.close_hr_sop2)#
+
+
+    def close_hr_sop2(self, event, msg): #msg 1 开始测量 2 测量成功 3 测量失败未出值
+        get_hr_state = EventMesh.publish("get_hr_state")
+        get_spo2_state = EventMesh.publish("get_spo2_state")
+        if get_hr_state != None and get_spo2_state != None:
+            if get_hr_state != 0:
+                EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                print("sstop hr")
+                EventMesh.publish(constants.EVENT.STOP_HEART) 
+            elif get_spo2_state != 0:
+                print("stop spo2")
+                EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+
+#imei = EventMesh.publish(constants.EVENT.GET_IMEI)
+class playImeiManager(Abstract):
+    def __init__(self):
+        self.timer = osTimer()
+        self.aud = audio.Audio(0)
+        self.aud.set_pa(Pin.GPIO29)
+        self.aud.setVolume(11)
+        self.play_count = 0
+        pass
+        
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("play_imei_event", self.play_imei_event)#播報imei号
+
+    
+
+    def play_imei_event(self, event, msg): #msg 1 开始测量 2 测量成功 3 测量失败未出值
+        self.play_count = 0
+        self.timer.start(1000,1,self.play_timer_cb)
+           
+    def play_timer_cb(self,*agrs):
+        if self.play_count > 14:
+            self.play_count = 0
+            self.timer.stop()
+            return
+        imei = EventMesh.publish(constants.EVENT.GET_IMEI)
+        play_state = EventMesh.publish("get_audio_state")#音频播放状态
+        if play_state != None:
+            if play_state == 0:
+                num = int(imei[self.play_count])
+                self.play_count+=1
+                self.aud.play(1, 1, 'U:/static/R_READ_TIME_{}.mp3'.format(num))  #播放imei号
+
+           
+
+class wechatInforManager(Abstract):#微聊相关信息 
+    def __init__(self):
+        self.MXA_MSG = 10
+        self.wechat_recode_list = {}
+        self.wechat_num = 0
+        self.read_data = {}
+        self.volum_size = 8 
+        self.msg_tmp = ""
+        check_txt = ql_fs.path_exists("/usr/static/storage_file/wechat_record.json")
+        if check_txt == True :
+            with open("/usr/static/storage_file/wechat_record.json","r") as fd:#音频文件编号
+                self.wechat_recode_list = ujson.load(fd)
+                if not self.wechat_recode_list:
+                    self.wechat_recode_list = {}
+                    self.wechat_num = 0 
+                else:
+                    sort_tmp = {}
+                    sort_tmp = self.wechat_recode_list.values()
+                    sort_new = {}
+                    sort_new = sorted(sort_tmp, key = lambda i: i['timesec'],reverse = True)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                    i = 0
+                    for sort_new_tmp in sort_new: #字典 key value
+                        i+=1 # 1 
+                        if i >= 1:#大于50条把最后一条删除掉只保留前面50调最新的数据
+                            self.wechat_num = sort_new_tmp["num"]
+                            break
+        else :
+            self.wechat_recode_list = {}
+
+            
+
+        self.record_test = audio.Record()
+        self.aud = audio.Audio(0)
+        self.aud.set_pa(Pin.GPIO29)  
+        self.timeSecond = 0
+        self.wechat_show = 0
+        self.sort_new = {}
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("start_wechat_record", self.start_wechat_record)#手表开始录音
+        EventMesh.subscribe("send_wechat_record", self.send_wechat_record)#发送微聊语音文件to app
+        EventMesh.subscribe("play_wechat_last_amr", self.play_wechat_last_amr)#播放微聊语音最后一条语音文件
+        EventMesh.subscribe("get_wechat_data", self.get_wechat_data)
+        EventMesh.subscribe("set_wechat_data", self.set_wechat_data)
+
+    def get_wechat_data(self,event, msg): 
+
+        return [self.MXA_MSG ,self.wechat_num]
+    
+    def set_wechat_data(self, event, msg): 
+        print("set_wechat_data1 ",msg,self.wechat_num)
+        # self.MXA_MSG = msg[0]
+        # self.wechat_recode_list = msg[1]
+        # self.wechat_num = self.wechat_recode_list["num"]
+        self.wechat_num = msg[1]
+        tmp = {}
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        
+
+        tmp["timesec"] = time_tmp #时间戳 到时候按时间戳排序
+        tmp["num"] = self.wechat_num
+        tmp["read"] = 1#1 代表未读 0 代表已读
+        self.wechat_recode_list[self.wechat_num] = tmp
+
+        print("self.wechat_recode_list :{}".format(self.wechat_recode_list))
+
+        with open("/usr/static/storage_file/wechat_record.json","w",encoding="utf-8") as fd:
+            ujson.dump(self.wechat_recode_list,fd)
+            #写编号
+        print("set_wechat_data2:{} ".format(self.wechat_num))
+       
+    def start_wechat_record(self, event, msg): #开始录音相关配置
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        self.timeSecond = time_tmp#保存按下的时间长s
+        self.aud.setVolume(11)#设置音量最大
+        print("talking1.0")
+        
+        self.record_test.start("/usr/static/storage_file/swechat.amr",16) 
+        pass
+
+    def send_wechat_record(self, event, msg): #发送录音文件
+        date_tmp = utime.localtime()
+        time_tmp = utime.mktime(date_tmp)
+        countdown = time_tmp - self.timeSecond
+        if countdown <= 0:#使用时间错相减得到录音时间校准确
+            countdown = 1
+        EventMesh.publish("stop_led_timer")#设置参数
+
+        print("countdown!!!!!!!!!",countdown)
+        self.record_test.stop() #停止录音
+        print("send wechat data!!!!!!!!!!!!!!!!!!!!!")
+        path = "/usr/static/storage_file/swechat.amr"
+        with open(path,"rb") as fd:
+            buf = bytearray(ql_fs.path_getsize(path))
+            fd.readinto(buf)
+            senddata = [countdown,buf]#发送录音二进制文件
+            EventMesh.publish(constants.PROTOCOL.TK_SEND,senddata)
+        pass
+
+    def play_wechat_last_amr(self, event, msg):#播放微聊最后一条语音文件
+        if self.wechat_recode_list != {}:
+            print("self.wechat_num",self.wechat_num)
+            if self.wechat_num > 0:
+                self.aud.setVolume(11)#设置音量最大
+                self.aud.stop()
+                self.aud.play(1, 1, '/usr/static/storage_file/{}.amr'.format(self.wechat_num))  #文件名前面要加上路径
+
+class FindWatchManager(Abstract):#查找设备
+    def __init__(self):
+        self.volum_size = 8
+        check_volum = ql_fs.path_exists("/usr/static/storage_file/config.json")
+        if check_volum == True :
+            with open("/usr/static/storage_file/config.json","r") as fd:#音频文件编号
+                self.read_data = ujson.load(fd)
+                if self.read_data != {}:
+                    b = str("volum") in self.read_data.keys()
+                    if b == True:
+                        self.volum_size = self.read_data["volum"]  
+                    else:
+                        self.volum_size = 8
+                else:
+                    self.volum_size = 8
+        else:
+            self.volum_size = 8
+        self.aud = audio.Audio(0)
+        self.aud.set_pa(Pin.GPIO29)
+        self.aud.setVolume(self.volum_size)
+        self.timer = osTimer()
+        self.find_state  = 0
+        
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("OPEN_FIND_WATCH", self.send_find_watch)#
+        EventMesh.subscribe("STOP_FIND_WATCH", self.stop_find_watch)#是否需要关闭查找设备
+
+    def stop_find_watch(self, event, msg): 
+        if self.find_state == 1:
+            self.find_state = 0
+            self.FIND_timer_count = 0
+            EventMesh.publish("stop_led_timer")#设置参数
+            self.aud.stop()  #播放声音 
+            self.timer.stop()
+
+    def send_find_watch(self, event, msg): 
+        flag = EventMesh.publish("get_call_state")
+        if flag != 2:
+            self.find_state = 1
+            self.FIND_timer_count = 0
+            self.timer.start(3000,1,self.FIND_timer_cb)
+            self.aud.play(1, 1, 'U:/static/audio_audio_haixiu.mp3')  #播放声音
+        
+
+    def FIND_timer_cb(self, *args):
+        if self.find_state == 1:
+            print("self.FIND_timer_count:{}".format(self.FIND_timer_count))
+            if EventMesh.publish("get_led_state") == 0:
+                EventMesh.publish("set_led_time_arg",[(38000-self.FIND_timer_count*3),1000,1,led_mode.LONG_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE])#查找设备绿灯长亮37s
+            self.aud.play(1, 1, 'U:/static/audio_audio_haixiu.mp3') 
+            self.FIND_timer_count += 1
+            if self.FIND_timer_count > 10: #120秒30s
+                EventMesh.publish("STOP_FIND_WATCH")
+    
+    def stop_FIND(self) :
+        self.timer.stop()
+        
+        
+        
+
 class BtnDevice(Abstract):
 
     def __init__(self, tp=None):
         self.pk = PowerKey()
         self.__pwk_timer = osTimer()
 
-        self.keypad = machine.KeyPad(4, 1)
+        # self.keypad = machine.KeyPad(1, 2)
         self.__PowerDownTimeOut = 3000
         self.__tp = tp
         self.pwk_press = 0
@@ -20,47 +827,222 @@ class BtnDevice(Abstract):
         self.GPIO26_status = 0
         self.powerKey_status = 0
         self.pin_timer = osTimer()
+        self.sosKey = 0
+        self.wechatKey = 0
+        self.sosKey_status = 0
+        self.WeChatKey_status = 0
+
+        self.wechatKey_timer = osTimer()
+        self.wechatKey_count = 0
+        self.wechatKey_press = 0 
+
+        self.sosKey_timer = osTimer()
+        self.sosKey_count = 0
+        self.sosKey_press = 0 
+
+        self.power_key = osTimer()
+
+        self.wechatKey_timeout = osTimer()
+        self.wechatKey_press_count = 0
+
+        self.timeSeconOld = 0
+        self.wechat_state = 1 #按下录音时的状态
+
+        self.sosKey_timeout = osTimer()
+        self.sosKey_press_count = 0
 
     def post_processor_after_instantiation(self):
-        self.keypad.init()
-        self.keypad.set_callback(self.key_callback)
+        # self.keypad.init()
+        # self.keypad.set_callback(self.key_callback)
+        EventMesh.subscribe("sos_short_press", self.sos_short_press)#sos短按事件
         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()
 
+        self.sosKey = ExtInt(ExtInt.GPIO22, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.sosKey_extint_cb)
+        self.sosKey.enable()
+
+        self.wechatKey = ExtInt(ExtInt.GPIO20, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.wechatKey_extint_cb)
+        self.wechatKey.enable()
 
+        key19 = Pin(Pin.GPIO19, Pin.OUT, Pin.PULL_PU, 0)
+
+    def sos_short_press(self,args,msg):
+        EventMesh.publish("close_audio_play")#强制关闭音频文件播放
+        EventMesh.publish("interup_call_event")#如果在电话中强制挂断电话
+        EventMesh.publish("stop_led_timer")#设置参数关闭led定时器 同时也关闭所有的灯再开相对应的灯
+        EventMesh.publish("STOP_FIND_WATCH")#停止查找设备
 
     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")
+        print('### key20_extint_cb  {} self.GPIO26_status :{}'.format(args,self.GPIO26_status)) # args[0]:gpio号 args[1]:上升沿或下降沿
+
+    def sosKey_extint_cb(self,args):
+        self.sosKey_status = self.sosKey.read_level()
+        print('### key22_extint_cb  {} self.GPIO22_status:{}'.format(args,self.sosKey_status)) # args[0]:gpio号 args[1]:上升沿或下降沿
+        if self.sosKey_status == 0:#按下
+            if self.sosKey_press == 0 :
+                self.sosKey_press = 1
+                self.sosKey_count = 0
+                self.sosKey_timer.start(100, 1, self.sosKey_press_cb)
+                print("key22_extint_cb:self.key22_timer.start!!!!\n")
+
+    def sosKey_press_cb(self, *args):
+        '''KEY2:联动屏幕右下角或返回键长按关机'''
+        if self.sosKey_press == 1 :
+            
+            self.sosKey_count += 1
+            print("self.sosKey_count {}",self.sosKey_count)
+            if self.sosKey_status == 1:#松开
+                if self.sosKey_count >= 1: #防抖100ms
+                    self.sosKey_timer.stop()
+                    self.sosKey_count = 0
+                    self.sosKey_press = 0
+                    self.sosKey_press_count+=1
+                    self.sosKey_timeout.start(800, 0, self.sosKey_timeout_cb)#松手超时1s判断
+                    
+                    print("self.sosKey_status!!!!!!!!!!!!!!")
+
+            # if self.sosKey_count > (self.__PowerDownTimeOut//100): #长按
+            #     self.sosKey_timer.stop()
+            #     self.sosKey_count = 0
+            #     self.key22_press = 0
+            #     print("sosKey_long_press!!!!!!!!!!!!!")
+
+    def sosKey_timeout_cb(self, *args):#微聊键
+        print("sosKey_press_count!!!!!!!!!!!!!! ",self.sosKey_press_count)
+        if self.sosKey_press_count >= 10:#短按十次解绑app
+            self.sosKey_press_count = 0
+            EventMesh.publish("reset_factor_setiing")#恢复出厂设置
+            pass
+        elif self.sosKey_press_count >= 6:#短按六次播报imei号
+            self.sosKey_press_count = 0
+            EventMesh.publish("play_imei_event")#播報imei号
+            pass
+        elif self.sosKey_press_count >= 4:#拨打通讯录号码三
+            self.sosKey_press_count = 0
+            # EventMesh.publish("call_phonebook_three_call")
+            pass
+        elif self.sosKey_press_count >= 3:#拨打通讯录号码二
+            self.sosKey_press_count = 0
+            # EventMesh.publish("call_phonebook_two_call")
+            pass
+        elif self.sosKey_press_count >= 2:#播报当前步数
+            self.sosKey_press_count = 0
+            EventMesh.publish("play_cur_step_event")#
+            pass
+        elif self.sosKey_press_count >= 1:#挂断来电 短语音播报
+            self.sosKey_press_count = 0
+            #EventMesh.publish(constants.EVENT.START_LOCATION) #开始定位
+            EventMesh.publish("sos_short_press")#sos短按事件
+            pass
+        self.sosKey_press_count = 0
+
+
+    def wechatKey_extint_cb(self,args):
+        self.WeChatKey_status = self.wechatKey.read_level()
+        print('### wechatKey_extint_cb  {} self.WeChatKey_status:{}'.format(args,self.WeChatKey_status)) # args[0]:gpio号 args[1]:上升沿或下降沿
+
+        if self.WeChatKey_status == 0:#按下
+            if self.wechatKey_press == 0 :
+                self.wechatKey_press = 1
+                self.wechatKey_count = 0
+                self.wechat_state = 1
+                self.wechatKey_timer.start(100, 1, self.wechatKey_press_cb)
+                self.wechatKey_timeout.stop()
+                print("wechatKey_extint_cb:selfwechatKey_timer.start!!!!\n")
+
+    def wechatKey_press_cb(self, *args):
+        '''KEY2:联动屏幕右下角或返回键长按关机'''
+        if self.wechatKey_press == 1 :#是否按下
+            
+            self.wechatKey_count += 1
+            print("self.wechatKey_count {}",self.wechatKey_count)
+            
+            if self.wechatKey_count >= 10: #长按1s进入微聊录音
+                if self.wechat_state == 1:#按下超过s开始录音
+                    EventMesh.publish("start_wechat_record")#开始录音
+                    self.wechat_state = 0
+                if EventMesh.publish("read_green_led_level") == 0:#读取绿灯的电平状态 不需要重复给高低平
+                    EventMesh.publish("set_led_time_arg",[1000,1000,1,led_mode.LONG_LIGHT_GREEN,led_mode.OPEN_LONG_LIGHT_MODE])#測量成功  
+                        
+
+            if self.WeChatKey_status == 1:#松开
+                if self.wechatKey_count >= 1: #防抖100ms
+                    # print("WeChat time!!!!!!!!!!!!!!")
+                    if self.wechat_state == 0:#如果按下时长超过1s且小于长按的时间也认为是录微聊
+                        # print("WeChat stop!!!!!!!!!!!!!!")
+                        EventMesh.publish("send_wechat_record")#发送录音文件内容
+                        self.wechatKey_timer.stop()
+                        self.wechatKey_timeout.stop()
+                        self.wechatKey_count = 0
+                        self.wechatKey_press = 0
+                        self.wechatKey_press_count=0
+                        return
+
+                    self.wechatKey_timer.stop()
+                    self.wechatKey_count = 0
+                    self.wechatKey_press = 0
+                    self.wechatKey_press_count+=1
+                    self.wechatKey_timeout.start(800, 0, self.wechatKey_timeout_cb)#松手超时1s判断
+                    # print("self.WeChatKey_status!!!!!!!!!!!!")
+
+            
+
+    def wechatKey_timeout_cb(self, *args):#微聊键
+        print("wechatKey_timeout_cb!!!!!!!!!!!!!! ",self.wechatKey_press_count)
+        if self.wechatKey_press_count >= 10:#短按十次解绑app
+            self.wechatKey_press_count = 0
+            EventMesh.publish("reset_factor_setiing")#恢复出厂设置
+            pass
+        elif self.wechatKey_press_count >= 6:#短按六次播报imei号
+            self.wechatKey_press_count = 0
+            EventMesh.publish("play_imei_event")#播報imei号
+            pass
+        elif self.wechatKey_press_count >= 4:#拨打通讯录号码三
+            self.wechatKey_press_count = 0
+            EventMesh.publish("call_phonebook_three_call")
+            pass
+        elif self.wechatKey_press_count >= 3:#拨打通讯录号码二
+            self.wechatKey_press_count = 0
+            EventMesh.publish("call_phonebook_two_call")
+            pass
+        elif self.wechatKey_press_count >= 2:#拨打通讯录号码一
+            self.wechatKey_press_count = 0
+            EventMesh.publish("call_phonebook_one_call")
+           # EventMesh.publish("interup_call_event")#
+            pass
+        elif self.wechatKey_press_count >= 1:#播放最后收到的语音
+            self.wechatKey_press_count = 0
+            #EventMesh.publish("call_test_event")#电话拨进响铃
+            call_state = EventMesh.publish("get_call_state") 
+            if call_state == 2:#电话拨进需要接听
+                EventMesh.publish("answer_call_event")#接听电话
+            else:
+                EventMesh.publish("play_wechat_last_amr")
+            pass
+        self.wechatKey_press_count = 0
+
+
     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
-            #
+            print("self.pwk_count {}",self.pwk_count)
             if self.GPIO26_status == 1:#松开
-                if(self.pwk_count >= 1): #防抖100ms
+                if self.pwk_count >= 1: #防抖100ms
                     self.__pwk_timer.stop()
                     self.pwk_count = 0
                     self.pwk_press = 0
-                    EventMesh.publish("btn8_press")
+                    print("self.GPIO22_status")
+
             if self.pwk_count > (self.__PowerDownTimeOut//100): #长按
                 self.__pwk_timer.stop()
                 self.pwk_count = 0
                 self.pwk_press = 0
-                EventMesh.publish("btn8_long_press")
+                print("btn8_long_press")
 
     def __ui_callback(self, para):
        # print("para = {}".format(para))
@@ -113,8 +1095,11 @@ class BtnDevice(Abstract):
         if status == 1:#拔出
             # if(self.GPIO26_status == 1):
             #     EventMesh.publish("btn8_press")
-            #self.__pwk_timer.start(self.__PowerDownTimeOut, 0, self.pwk_press_cb)
+            self.power_key.start(self.__PowerDownTimeOut, 0, self.power_key_press_cb)
             EventMesh.publish(constants.EVENT.SYSTEM_UP)
+
+            EventMesh.publish("stop_led_timer")#设置参数#关闭led定时器
+            # EventMesh.publish("set_led_time_arg",[1000,200,10,led_mode.LONG_LIGHT_RED,led_mode.CLOSE_LONG_LIGHT_MODE])#设置参数
             pass
         elif status == 0:#插入usb
             EventMesh.publish(constants.EVENT.SYSTEM_UP)
@@ -126,8 +1111,19 @@ class BtnDevice(Abstract):
             # if(self.GPIO26_status == 1):
             #     EventMesh.publish("btn8_press")
             #pass
+            self.power_key.stop()
+            EventMesh.publish("stop_led_timer")#设置参数关闭led定时器 同时也关闭所有的灯再开相对应的灯
+            EventMesh.publish("set_led_time_arg",[1000,1000,30,led_mode.LONG_LIGHT_RED,led_mode.OPEN_LONG_LIGHT_MODE])#开启长亮绿灯
+            EventMesh.publish("close_hr_sop2")##强制关闭心率血氧测试
+            EventMesh.publish("close_audio_play")#强制关闭音频文件播放
+            EventMesh.publish("interup_call_event")#如果在电话中强制挂断电话
+           
+            
+
+    def power_key_press_cb(self, *args):
+        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:#未插卡的情况下强制关机
+            EventMesh.publish("long_press_power_off")#
 
-    
 
     def start(self):
         self.post_processor_after_instantiation()
index 7a349a1..c6bfef1 100644 (file)
@@ -1,4 +1,239 @@
-#import main_init 
-from usr.main_init import main_init
-print("main !!!!!!!")
-main_init()
\ No newline at end of file
+import sms
+
+class App(object):
+    def __init__(self):
+        self.managers = []
+
+    def append_manager(self, manager):
+        if isinstance(manager, Abstract):
+            manager.post_processor_after_instantiation()
+            self.managers.append(manager)
+        return self
+
+    def start(self):
+        for manager in self.managers:
+            manager.post_processor_before_initialization()
+            manager.initialization()
+            manager.post_processor_after_initialization()
+
+
+class watchApp(App):
+    def __init__(self):
+        super(watchApp, self).__init__()
+        self.__ui = None
+
+    def set_ui(self, ui):
+        self.__ui = ui
+
+    def start(self):
+        if self.__ui is not None:
+            self.__ui.start()
+        super().start()
+
+
+
+if __name__ == '__main__':
+    import uos
+    import ql_fs
+    import utime
+    if ql_fs.path_exists("/ext") == False:
+        ldev = uos.VfsLfs1(32, 32, 32, "ext_fs",0,3)
+        uos.mount(ldev,'/ext')
+    res = uos.statvfs("/ext")
+    res = list(res)
+    print('总ext空间:{} MB,剩余空间:{} MB'.format((((res[0] * res[2]) / 1024 / 1024)),((res[0] * res[3]) / 1024 / 1024)))
+    print("init1:{}".format(utime.localtime()))
+    import EventMesh
+    from common import Abstract
+    print("init2:{}".format(utime.localtime()))
+    from lcd import tp_cst816
+    print("init3:{}".format(utime.localtime()))
+
+    from usr.ui_main_menu import MainMenuScreen
+    # from ui_WatchFaceScreen import WatchFaceScreen
+    
+    from appFactoryMode import  FactoryModeLocationScreen,FactoryModeScreen ,FactoryModeAlipayInitScreen
+    import ui as _ui
+    # import ui as _ui
+    print("init4:{}".format(utime.localtime()))
+    ui = _ui.UI()
+    ui.post_processor_after_instantiation()
+    ui.add_screen(MainMenuScreen()) 
+    EventMesh.publish("load_screen", {"screen": "main_menu"})
+    print("init5:{}".format(utime.localtime()))
+    
+    ui.add_screen(_ui.PopupScreen()) 
+    ui.add_screen(_ui.PhoneScreen()) 
+    ui.add_screen(_ui.HeartrateScreen()) 
+    import ui_setting as _ui_setting
+    ui.add_screen(_ui_setting.SettingScreen()) 
+    ui.add_screen(_ui.ToolboxScreen()) 
+    ui.add_screen(_ui.StepScreen()) 
+    ui.add_screen(_ui.CountdownScreen()) 
+    ui.add_screen(_ui.StopwatchScreen()) 
+    ui.add_screen(_ui.WeatherScreen()) 
+    ui.add_screen(_ui.Spo2Screen()) 
+    ui.add_screen(_ui.TemperatureScreen()) 
+    ui.add_screen(_ui.ContactsScreen()) 
+    from appWechat import WechatScreen,TK_ProtoCol,MESSAGE_ProtoCol,NewWechatPopupScreen
+    ui.add_screen(WechatScreen()) 
+    from alarm import ClkListScreen,ClockManager,NewEditClk,CLKTimeScreen,ClkPeriod,PopupAlarmScreen
+    from ui_health import HealthScreen
+    ui.add_screen(ClkListScreen()) 
+    ui.add_screen(_ui.CountdownEndScreen()) 
+    ui.add_screen(NewEditClk()) 
+    ui.add_screen(CLKTimeScreen()) 
+    ui.add_screen(ClkPeriod()) 
+  
+    # ui.add_screen(_ui_setting.LanguageScreen()) 
+    ui.add_screen(_ui_setting.DialswitchScreen()) 
+    # ui.add_screen(_ui.ThemeswitchScreen()) 
+    ui.add_screen(_ui_setting.ImeiScreen()) 
+    ui.add_screen(_ui_setting.AppScreen()) 
+    ui.add_screen(_ui_setting.BrightnessScreen()) 
+    ui.add_screen(_ui_setting.VolumeScreen()) 
+    ui.add_screen(_ui_setting.RestoreScreen()) 
+    ui.add_screen(_ui_setting.PoweroffScreen()) 
+    ui.add_screen(_ui_setting.VersionScreen()) 
+    ui.add_screen(_ui_setting.UpdateScreen()) 
+    ui.add_screen(_ui_setting.AlarmvolumeScreen()) 
+    ui.add_screen(_ui_setting.MsgvolumeScreen()) 
+    ui.add_screen(_ui_setting.PhoneringScreen()) 
+    ui.add_screen(_ui_setting.totalvolumeScreen()) 
+    ui.add_screen(_ui_setting.PoweroffConfirmScreen()) 
+    ui.add_screen(_ui.DialingScreen()) 
+    ui.add_screen(_ui.CallLogScreen()) 
+    from appAlipay import Alipay ,AlipayOpenScreen,Alipay_1_1,Alipay_invite,Alipay_inviting,\
+    Alipay_success,Alipay_paycode,Alipay_pay_success,Alipay_collect,Alipay_parent
+    ui.add_screen(AlipayOpenScreen()) 
+    ui.add_screen(Alipay_1_1())
+    ui.add_screen(Alipay_invite())  
+    ui.add_screen(Alipay_inviting()) 
+    ui.add_screen(Alipay_success()) 
+    ui.add_screen(Alipay_paycode()) 
+    ui.add_screen(Alipay_pay_success()) 
+    ui.add_screen(Alipay_collect()) 
+    ui.add_screen(Alipay_parent()) 
+    ui.add_screen(_ui.UIFINDScreen())
+    ui.add_screen(_ui.MsgDetailScreen())
+    ui.add_screen(_ui.IncomingCallScreen())
+    ui.add_screen(_ui.OnCallScreen())
+    ui.add_screen(_ui.MessageFullScreen())
+    # ui.add_screen(_ui.PowerOnScreen())
+    ui.add_screen(FactoryModeLocationScreen())
+    ui.add_screen(FactoryModeScreen())
+    ui.add_screen(FactoryModeAlipayInitScreen())
+    ui.add_screen(PopupAlarmScreen())
+    ui.add_screen(_ui.LowPowerScreen())
+    ui.add_screen(_ui.NewMessageScreen())
+    ui.add_screen(NewWechatPopupScreen())
+    ui.add_screen(HealthScreen())
+    # ui.add_screen(_ui.Setting3Screen())  
+    print("init6:{}".format(utime.localtime()))
+    
+
+    from protocol import LK_ProtoCol,PING_ProtoCol,HEART_ProtoCol,OXYGEN_ProtoCol,OXYGEN_One_ProtoCol,HRSTART_ProtoCol,CENTER_ProtoCol,UPLOAD_ProtoCol,\
+        TEMP_ProtoCol,DLT_ProtoCol,WT_ProtoCol,UD_ProtoCol,REMIND_ProtoCol, CR_ProtoCol,KA_ProtoCol,FIND_ProtoCol,POWEROFF_ProtoCol,\
+            ProtoColResolver,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager
+    import mgr as mgr
+    print("init7:{}".format(utime.localtime()))
+    
+    from mgr import ConfigStoreManager,getBootOffManager,getSosFlagManager,CountdownManager, LocationManager, getVolumSizeManager,gethistoryDataManager,getUpLoadDataManager, getplayAudiodStateManager,\
+    AddrBookManager,MsgdetailManager,PhoneCallingManager,getOldTimeManager,getStorageDataManager,getBrightnessManager,getHrTimeManager,getTempTimeManager,getLowBatManager
+    print("init8:{}".format(utime.localtime()))
+    
+    
+    #from ui_WatchFaceScreen import WatchFaceScreen 
+    
+    
+    # from usr.test_sms import HRSTART_ProtoCol,getHrTimeManager,HEART_ProtoCol,OXYGEN_ProtoCol,OXYGEN_One_ProtoCol,getBrightnessManager,\
+    # getStorageDataManager
+    print("init9:{}".format(utime.localtime()))
+   #from usr.ui_wechat import WechatScreen,TK_ProtoCol
+
+    print("init10:{}".format(utime.localtime()))
+    
+
+    app = watchApp()
+    app.set_ui(ui)
+    app.append_manager(mgr.AlarmVolumeLevelManager()) \
+        .append_manager(mgr.MsgVolumeLevelManager()) \
+        .append_manager(mgr.PhoneVolumeLevelManager()) \
+        .append_manager(mgr.DeviceInfoManager()) \
+        .append_manager(mgr.BatteryManager()) \
+           
+        # .append_manager(mgr.StopwatchManager()) \
+        # .append_manager(mgr.CountdownManager()) \
+
+    app.append_manager(Alipay()) 
+    app.append_manager(ConfigStoreManager())
+    app.append_manager(NetManager())
+    app.append_manager(LocationManager())
+    app.append_manager(AddrBookManager())
+    app.append_manager(mgr.MsgManager())
+    app.append_manager(MsgdetailManager())
+    app.append_manager(mgr.CallLogManager())
+    app.append_manager(mgr.getWeatherDataManager())
+    app.append_manager(PhoneCallingManager())
+    app.append_manager(ClockManager())
+    app.append_manager(gethistoryDataManager())
+    app.append_manager(getHrTimeManager())
+    app.append_manager(getBrightnessManager())
+    app.append_manager(getStorageDataManager())
+    app.append_manager(getUpLoadDataManager())
+    app.append_manager(getVolumSizeManager())
+    app.append_manager(getTempTimeManager())
+    app.append_manager(getplayAudiodStateManager())
+    app.append_manager(getLowBatManager())
+    app.append_manager(getBootOffManager())
+    app.append_manager(getOldTimeManager())
+    app.append_manager(getSosFlagManager())
+    app.append_manager(CountdownManager())
+
+    print("init21:{}".format(utime.localtime()))    
+    
+    print("init11:{}".format(utime.localtime()))    
+    pcr = ProtoColResolver()
+    pcr.add_support(LK_ProtoCol())
+    pcr.add_support(PING_ProtoCol())
+    pcr.add_support(KA_ProtoCol())
+    pcr.add_support(UD_ProtoCol())
+    pcr.add_support(CR_ProtoCol())
+    pcr.add_support(FIND_ProtoCol())
+    pcr.add_support(POWEROFF_ProtoCol())
+    pcr.add_support(PHL_ProtoCol())
+    pcr.add_support(TK_ProtoCol())
+    pcr.add_support(MESSAGE_ProtoCol())
+    pcr.add_support(WT_ProtoCol())
+    pcr.add_support(REMIND_ProtoCol())
+    pcr.add_support(HRSTART_ProtoCol())
+    pcr.add_support(HEART_ProtoCol())
+    pcr.add_support(OXYGEN_ProtoCol())
+    pcr.add_support(OXYGEN_One_ProtoCol())
+    pcr.add_support(TEMP_ProtoCol())
+    pcr.add_support(DLT_ProtoCol())
+    pcr.add_support(UPLOAD_ProtoCol())
+    pcr.add_support(MONITOR_ProtoCol())
+    # pcr.add_support(CENTER_ProtoCol())
+    pcr.add_support(CENTER_ProtoCol())
+    pcr.add_support(bootoff_ProtoCol())
+    pcr.add_support(WDSTART_ProtoCol())
+    pcr.add_support(LOWBAT_ProtoCol())
+    pcr.add_support(sosHome_dial_ProtoCol())
+
+    sm = SockManager()
+    sm.add_support_resolver(pcr)
+    app.append_manager(sm)
+    print("init11.0:{}".format(utime.localtime()))   
+    app.start()
+    sms_data = sms.getSaveLoc()
+    sms_lacv = sms_data[0][0]
+    if sms_lacv != 'SM':#每次开机设置一下短信的存储位置
+        sms.setSaveLoc('SM', 'SM', 'SM')
+    print("init12:{}".format(utime.localtime()))
+    import atcmd
+    resp=bytearray(50)
+    atcmd.sendSync('AT+log=52,1\r\n',resp,'',20)
+    print("AT+log=52,1:{}".format(resp))
+
+
index d5786c0..ef0cdd6 100644 (file)
@@ -2,6 +2,7 @@ import sms
 import atcmd
 import net
 import machine
+from usr.led import ledEventManager,led_mode
 resp=bytearray(50)
 # atcmd.sendSync('AT+log=52,1\r\n',resp,'',200)
 # print("AT+log=52,1:{}".format(resp))
@@ -38,93 +39,58 @@ class watchApp(App):
 
 
 
-def main_init():
+#def main_init():
+if __name__ == '__main__':
     import uos
     import ql_fs
     import utime
-
+    # if ql_fs.path_exists("/ext") == False:
+    #     ldev = uos.VfsLfs1(32, 32, 32, "ext_fs",0,3)
+    #     uos.mount(ldev,'/ext')
     res = uos.statvfs("/usr")
     res = list(res)
     print('总usr空间:{} MB,剩余空间:{} MB'.format((((res[0] * res[2]) / 1024 / 1024)),((res[0] * res[3]) / 1024 / 1024)))
     print("init1:{}".format(utime.localtime()))
     import EventMesh
-    from btn_device_ec800m import BtnDevice
-    btn_device = BtnDevice()
-    btn_device.start()
+    
     print("init2:{}".format(utime.localtime()))
     print("init3:{}".format(utime.localtime()))
+    from usr.btn_device_ec800m import BtnDevice,playImeiManager,FindWatchManager,powerOFFManager,closeAudioManager,\
+        phonecallManager,wechatInforManager,resetFactoryUnbindManager,playCurStepManager
+
+    btn_device = BtnDevice()
+    btn_device.start()
     
     import ui as _ui
     # import ui as _ui
     print("init4:{}".format(utime.localtime()))
     ui = _ui.UI()
     ui.post_processor_after_instantiation()
-    # ui.add_screen(_ui.SystemInitScreen()) 
-    # print("init5:{}".format(utime.localtime()))
-    # ui.add_screen(_ui.PopupScreen()) 
-    # ui.add_screen(_ui.PhoneScreen()) 
-    # ui.add_screen(_ui.HeartrateScreen()) 
-    # ui.add_screen(_ui.ToolboxScreen()) 
-    # ui.add_screen(_ui.StepScreen()) 
-    # ui.add_screen(_ui.CountdownScreen()) 
-    # ui.add_screen(_ui.StopwatchScreen()) 
-    # ui.add_screen(_ui.WeatherScreen()) 
-    # ui.add_screen(_ui.Spo2Screen()) 
-    # ui.add_screen(_ui.TemperatureScreen()) 
-    # ui.add_screen(_ui.ContactsScreen()) 
-    # print("init5.1:{}".format(utime.localtime()))
-    # from appWechat import WechatScreen,TK_ProtoCol,MESSAGE_ProtoCol,NewWechatPopupScreen
-    # ui.add_screen(WechatScreen()) 
-    # #from alarm import ClkListScreen,ClockManager,NewEditClk,CLKTimeScreen,ClkPeriod,PopupAlarmScreen
-    # # ui.add_screen(ClkListScreen()) 
-
-    # # ui.add_screen(NewEditClk()) 
-    # # ui.add_screen(CLKTimeScreen()) 
-    # # ui.add_screen(ClkPeriod()) 
-    # # ui.add_screen(PopupAlarmScreen())
-
-    # ui.add_screen(_ui.CountdownEndScreen()) 
-    # ui.add_screen(_ui.DialingScreen()) 
-    # ui.add_screen(_ui.CallLogScreen()) 
-    # print("init5.10:{}".format(utime.localtime()))
-    # ui.add_screen(_ui.UIFINDScreen())
-    # ui.add_screen(_ui.MsgDetailScreen())
-    # print("init5.11:{}".format(utime.localtime()))
-    # ui.add_screen(_ui.IncomingCallScreen())
-    # ui.add_screen(_ui.OnCallScreen())
-    # ui.add_screen(_ui.MessageFullScreen())
-    # # ui.add_screen(_ui.PowerOnScreen())
-    # print("init5.2:{}".format(utime.localtime()))
-    # ui.add_screen(_ui.LowPowerScreen())
-    # ui.add_screen(_ui.NewMessageScreen())
-    # ui.add_screen(_ui.sosScreen())
-    # ui.add_screen(_ui.noSosDataScreen())
-    # ui.add_screen(_ui.NoSimScreen())
-    # ui.add_screen(_ui.NoSimPowerScreen())
-    # ui.add_screen(_ui.DialingNoPlayPopupScreen())
-    # ui.add_screen(_ui.NovaliedNumScreen())
-    # ui.add_screen(_ui.DialNoconnectPopupScreen())
-    # ui.add_screen(NewWechatPopupScreen())
-    # # ui.add_screen(_ui.Setting3Screen())  
+
+    print("init5:{}".format(utime.localtime()))
+    
+    ui.add_screen(_ui.UIFINDScreen())  
     print("init6:{}".format(utime.localtime()))
     
-    from alarm import ClockManager
+
     from protocol import LK_ProtoCol,PING_ProtoCol,HEART_ProtoCol,OXYGEN_ProtoCol,OXYGEN_One_ProtoCol,HRSTART_ProtoCol,CENTER_ProtoCol,UPLOAD_ProtoCol,\
         TEMP_ProtoCol,DLT_ProtoCol,WT_ProtoCol,UD_ProtoCol,REMIND_ProtoCol, CR_ProtoCol,KA_ProtoCol,FIND_ProtoCol,POWEROFF_ProtoCol,Time_ProtoCol,\
-            ProtoColResolver,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager
+            ProtoColResolver,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager,MESSAGE_ProtoCol,\
+            TK_ProtoCol
     import mgr as mgr
     print("init7:{}".format(utime.localtime()))
     
     from mgr import ConfigStoreManager,sosInfoCallManager,getBootOffManager,getSosFlagManager,CountdownManager, LocationManager, getVolumSizeManager,gethistoryDataManager,getUpLoadDataManager, getplayAudiodStateManager,\
     AddrBookManager,MsgdetailManager,PhoneCallingManager,getOldTimeManager,getStorageDataManager,getBrightnessManager,getHrTimeManager,getTempTimeManager,getLowBatManager
     print("init8:{}".format(utime.localtime()))
-
+    
+    
+    #from ui_WatchFaceScreen import WatchFaceScreen 
     
     
     # from usr.test_sms import HRSTART_ProtoCol,getHrTimeManager,HEART_ProtoCol,OXYGEN_ProtoCol,OXYGEN_One_ProtoCol,getBrightnessManager,\
     # getStorageDataManager
     print("init9:{}".format(utime.localtime()))
-   #from usr.ui_wechat import WechatScreen,TK_ProtoCol
 
     print("init10:{}".format(utime.localtime()))
     
@@ -136,10 +102,19 @@ def main_init():
         .append_manager(mgr.PhoneVolumeLevelManager()) \
         .append_manager(mgr.DeviceInfoManager()) \
         .append_manager(mgr.BatteryManager()) \
-           
+        .append_manager(FindWatchManager())\
+        .append_manager(ledEventManager())\
+        .append_manager(powerOFFManager())\
+        .append_manager(closeAudioManager())\
+        .append_manager(phonecallManager())\
+        .append_manager(wechatInforManager())\
+        .append_manager(resetFactoryUnbindManager())\
+        .append_manager(playImeiManager())\
+        .append_manager(playCurStepManager())
         # .append_manager(mgr.StopwatchManager()) \
         # .append_manager(mgr.CountdownManager()) \
 
+   
     app.append_manager(ConfigStoreManager())
     app.append_manager(NetManager())
     app.append_manager(LocationManager())
@@ -149,7 +124,7 @@ def main_init():
     app.append_manager(mgr.CallLogManager())
     app.append_manager(mgr.getWeatherDataManager())
     app.append_manager(PhoneCallingManager())
-    app.append_manager(ClockManager())
+   
     app.append_manager(gethistoryDataManager())
     app.append_manager(getHrTimeManager())
     app.append_manager(getBrightnessManager())
@@ -216,7 +191,7 @@ def main_init():
             next_alarm_time = utime.localtime(timeSecond)
             machine.RTC().datetime((next_alarm_time[0],next_alarm_time[1],next_alarm_time[2],next_alarm_time[6],next_alarm_time[3],next_alarm_time[4],next_alarm_time[5],0))
 
-   
-    EventMesh.publish("load_screen", {"screen": "main_menu"})
+    EventMesh.publish("set_led_time_arg",[1000,200,10,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE])#设置参数
+    # EventMesh.publish("load_screen", {"screen": "main_menu"})
 
 
index 2d949a5..d837f07 100644 (file)
@@ -28,6 +28,7 @@ import wifiScan
 import math
 import voiceCall
 from misc import PWM
+from usr.led import led_mode,open_led_green,close_led_green,open_led_red,close_led_red,close_led_white
 from queue import Queue
 class PhoneVolumeLevelManager(Abstract):
     def __init__(self):
@@ -544,7 +545,9 @@ def voice_callback(args):
 
         if b == True and size_len > 11:
             tmp = tmp[size_len-11:]
-        EventMesh.publish("load_screen", {"screen": "incoming_call","meta":str(tmp)})
+        EventMesh.publish("set_call_state",2) 
+        EventMesh.publish("dialin_call_event")#电话拨进响铃
+        # EventMesh.publish("load_screen", {"screen": "incoming_call","meta":str(tmp)})
 
    elif args[0] == 11:
         EventMesh.publish("set_UI_high_priority",0)
@@ -561,7 +564,8 @@ def voice_callback(args):
         b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了
         if b == True and size_len > 11:
             tmp = tmp[size_len-11:]
-        EventMesh.publish("load_screen", {"screen": "on_call","meta":str(tmp)})
+        EventMesh.publish("set_call_state",1) 
+        # EventMesh.publish("load_screen", {"screen": "on_call","meta":str(tmp)})
 
    elif args[0] == 12:
         set_interrup_call = EventMesh.publish("get_interrup_incall")#打断这次不需要来电的ui事件 以免通话中退出当前界面进不去了
@@ -573,12 +577,13 @@ def voice_callback(args):
         EventMesh.publish("set_UI_high_priority",0)
         
 
-        screen_NAME = EventMesh.publish("get_screen_NAME")
-        if screen_NAME != None:
-            if screen_NAME != "dialing_noplay_popup":
-                EventMesh.publish("load_screen", {"screen": "main_menu"})  
+        # screen_NAME = EventMesh.publish("get_screen_NAME")
+        # if screen_NAME != None:
+        #     if screen_NAME != "dialing_noplay_popup":
+        #         EventMesh.publish("load_screen", {"screen": "main_menu"})  
         
         EventMesh.publish("set_sos_info_call")  
+        EventMesh.publish("set_call_state",0) 
         print('voicecall disconnect end')
         
 
@@ -588,7 +593,8 @@ def voice_callback(args):
 
         print('voicecall dialing, PhoneNO.: ', args[6])
         EventMesh.publish("set_UI_high_priority",0)
-        EventMesh.publish("load_screen", {"screen": "dialing"})
+        EventMesh.publish("set_call_state",1) 
+        # EventMesh.publish("load_screen", {"screen": "dialing"})
         
    elif args[0] == 15:
         print('voicecall alerting, PhoneNO.: ', args[6])
@@ -644,11 +650,17 @@ class DeviceInfoManager(Abstract):
         self.UD_time = 0
         self.upload_time = 0
         self.UD_timeout = 7*60
-
+        self.curr_battery_level = 4200
         self.temp_time = 0
         self.temp_state = 0
         self.temp_one_state = 0
 
+        self.bat_full = 0
+        self.usb_full = 0
+
+        self.bat_count =0
+        self.vbat_buf = []
+
         self.usb = USB()
         self.usb.setCallback(self.usb_event_cb)
         self.log = LogAdapter(self.__class__.__name__)
@@ -772,8 +784,8 @@ class DeviceInfoManager(Abstract):
         self.timer_push = 0
         date_tmp = utime.localtime()
         time_tmp = utime.mktime(date_tmp)
-        # print("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
-        EventMesh.publish("countdown_end_cb")
+        print("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
+        
         gnss_state = quecgnss.get_state()
         get_location_flag = EventMesh.publish("get_location_flag")
         if get_location_flag != None:
@@ -848,6 +860,23 @@ class DeviceInfoManager(Abstract):
             if self.clear_step == 1:
                 self.clear_step = 0
         
+        temp = Power.getVbatt()
+        self.bat_count+=1
+        self.vbat_buf.append(temp)
+
+        curr_count = len(self.vbat_buf)
+        bat_total_value = 0
+        for i in range(curr_count):
+            bat_total_value += self.vbat_buf[i]
+
+        bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
+
+        EventMesh.publish("set_curr_battery_level",bat_total_value)
+        # print("self.vbat_buf:{} curr_count :{} bat_total_value:{}".format(self.vbat_buf,curr_count,bat_total_value))
+        if self.bat_count >= 10:
+            self.bat_count = 0
+            self.vbat_buf = []
+
         #电量小于20% 5分钟提醒一次
         get_low_btn = EventMesh.publish("get_low_bat_btn")#
         battery = EventMesh.publish("screen_get_battery")
@@ -878,7 +907,7 @@ class DeviceInfoManager(Abstract):
         get_temp_time  = EventMesh.publish("get_temp_time")
         get_temp_state  = EventMesh.publish("get_temp_state")
         hr_time = EventMesh.publish("get_time_hr_spo2")#获取时间是否大于0
-        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and battery[1] != 1:
+        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and battery[0] == "0":
             # print("get_temp_time:{} self.temp_one_state:{}".format(get_temp_time,self.temp_one_state))
             if get_temp_time != None:#定时测量体温
                 if get_temp_time > 0:
@@ -968,7 +997,6 @@ class DeviceInfoManager(Abstract):
                             print("AUTO once temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp)) 
                             EventMesh.publish("set_temp_state",0)
                             EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
-
             if hr_time != None:
                 # print("hr......01....{}\r\n".format(hr_time))
                 if hr_time > 0:
@@ -983,17 +1011,20 @@ class DeviceInfoManager(Abstract):
                             self.SENSOR_time = time_tmp#防止改变时间的时候正在开启测量突然10s就停止测量
                             if self.get_hr_state == 2 and self.HR_state == 1:#自动检测的心率还在测量立马关了测试
                                 heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                EventMesh.publish("set_old_hr_data",heart_value)
                                 if heart_value > 50 and heart_value != None:
-                                    EventMesh.publish("set_old_hr_data",heart_value)
                                     EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)
                                 print("stop debug1")
+
                                 EventMesh.publish(constants.EVENT.STOP_HEART)
                                 self.HR_state = 0
                             elif self.get_spo2_state == 2 and self.HR_state == 2:
                                 self.HR_state = 0
                                 spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
-                                if spo2_value > 85 and spo2_value != None:
-                                    EventMesh.publish("set_old_spo2_data",spo2_value)
+                                
+                                EventMesh.publish("set_old_spo2_data",spo2_value)
+                                
+                                if spo2_value >= 85 and spo2_value != None:
                                     EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
                                 EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
                         self.old_time = hr_time
@@ -1005,15 +1036,16 @@ class DeviceInfoManager(Abstract):
                                         print("stop debug2")
                                         EventMesh.publish(constants.EVENT.STOP_HEART)
                                         heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                        EventMesh.publish("set_old_hr_data",heart_value)
                                         if heart_value > 50 and heart_value != None:
-                                            EventMesh.publish("set_old_hr_data",heart_value)
                                             EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)
                                         
                                     elif self.get_spo2_state == 3:
                                         EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
                                         spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                        
+                                        EventMesh.publish("set_old_spo2_data",spo2_value)
                                         if spo2_value > 85 and spo2_value != None:
-                                            EventMesh.publish("set_old_spo2_data",spo2_value)
                                             EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
 
                                     self.HR_state = 0
@@ -1025,7 +1057,9 @@ class DeviceInfoManager(Abstract):
                         if (time_tmp - self.SENSOR_time) == 0 and self.HR_state == 0:
                             print("START_HEART:1")
                             EventMesh.publish("set_hr_state",2)#2代表后台进入测试
+                            EventMesh.publish("set_hr_blood_led",1)#
                             EventMesh.publish(constants.EVENT.START_HEART)
+                            
                             self.HR_state = 1
                             self.HR_Onestate = 0
                             self.HR_OneTime = 0
@@ -1035,12 +1069,14 @@ class DeviceInfoManager(Abstract):
                             EventMesh.publish(constants.EVENT.STOP_HEART)
                             heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
                             print("heart_value:{}".format(heart_value))
+                            EventMesh.publish("set_old_hr_data",heart_value)
                             if heart_value > 50 and heart_value != None:
-                                EventMesh.publish("set_old_hr_data",heart_value)
                                 EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+
                             #获取心率数据上传数据app
                             print("STOP_HEART:")
                             EventMesh.publish("set_spo2_state",2)#2代表后台进入血氧测试
+                            EventMesh.publish("set_hr_blood_led",1)#
                             EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
                             print("START_BLOOD_OXYGEN:")
                             self.HR_state = 2
@@ -1050,9 +1086,10 @@ class DeviceInfoManager(Abstract):
                             EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
                             spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
                             print("spo2_value:{}".format(spo2_value))
+                            EventMesh.publish("set_old_spo2_data",spo2_value)
                             if spo2_value > 85 and spo2_value != None:
-                                EventMesh.publish("set_old_spo2_data",spo2_value)
                                 EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                               
                             self.HR_state = 3
                     else:
                         self.HR_state = 0
@@ -1067,6 +1104,7 @@ class DeviceInfoManager(Abstract):
                                 if self.get_hr_state == 3:
                                     self.Hr_Need_Open = 1
                                     EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                    EventMesh.publish("set_hr_blood_led",1)#
                                     EventMesh.publish(constants.EVENT.START_HEART)
                                 else:
                                     self.Hr_Need_Open = 0
@@ -1074,6 +1112,7 @@ class DeviceInfoManager(Abstract):
                                 if self.get_spo2_state == 3 and self.Hr_Need_Open == 0:
                                     self.Spo2_Need_Open = 1
                                     EventMesh.publish("set_spo2_state",3)#2代表后台进入测试
+                                    EventMesh.publish("set_hr_blood_led",1)#
                                     EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
                                 else:
                                     self.Spo2_Need_Open = 0
@@ -1085,12 +1124,14 @@ class DeviceInfoManager(Abstract):
                                     print("stop debug4")
                                     EventMesh.publish(constants.EVENT.STOP_HEART)
                                     heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                    EventMesh.publish("set_old_hr_data",heart_value)
                                     if heart_value > 50 and heart_value != None:
                                         EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
-                                        EventMesh.publish("set_old_hr_data",heart_value)
+                                        
                             
                                     if self.Spo2_Need_Open == 0 and self.get_spo2_state == 3:
                                         EventMesh.publish("set_spo2_state",3)#2代表后台进入血氧测试
+                                        EventMesh.publish("set_hr_blood_led",1)#
                                         EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
                                         
                                         self.HR_Onestate = 2
@@ -1111,8 +1152,12 @@ class DeviceInfoManager(Abstract):
                                         if spo2_value > 85 and spo2_value != None:
                                             EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
                                             EventMesh.publish("set_old_spo2_data",spo2_value)
+                                            EventMesh.publish("set_hr_blood_led",2)#
+                                        else:
+                                            EventMesh.publish("set_hr_blood_led",3)#
                                         if self.Hr_Need_Open == 0 and self.get_hr_state == 3:
                                             EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                            EventMesh.publish("set_hr_blood_led",1)#
                                             EventMesh.publish(constants.EVENT.START_HEART)
                                             self.HR_Onestate = 2
                                             self.set_hsenor_crt = 1#心率
@@ -1128,17 +1173,19 @@ class DeviceInfoManager(Abstract):
                                     EventMesh.publish("set_spo2_state",0)#2代表后台进入血氧测试
                                     EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
                                     spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                    EventMesh.publish("set_old_spo2_data",spo2_value)
                                     if spo2_value > 85 and spo2_value != None:
                                         EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
-                                        EventMesh.publish("set_old_spo2_data",spo2_value)
+                                        
                                 elif self.set_hsenor_crt == 1:
                                     EventMesh.publish("set_hr_state",0)#0代表g关闭测试
                                     print("stop debug5")
                                     EventMesh.publish(constants.EVENT.STOP_HEART)
                                     heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                    EventMesh.publish("set_old_hr_data",heart_value)
                                     if heart_value > 50 and heart_value != None:
-                                        EventMesh.publish("set_old_hr_data",heart_value)
                                         EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                       
                                 self.HR_Onestate = 0
                         else:
                             self.HR_Onestate = 0
@@ -1155,6 +1202,7 @@ class DeviceInfoManager(Abstract):
                                 if self.get_hr_state == 3:
                                     self.Hr_Need_Open = 1
                                     EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                    EventMesh.publish("set_hr_blood_led",1)#
                                     EventMesh.publish(constants.EVENT.START_HEART)
                                 else:
                                     self.Hr_Need_Open = 0
@@ -1162,6 +1210,7 @@ class DeviceInfoManager(Abstract):
                                 if self.get_spo2_state == 3 and self.Hr_Need_Open == 0:
                                     self.Spo2_Need_Open = 1
                                     EventMesh.publish("set_spo2_state",3)#2代表后台进入测试
+                                    EventMesh.publish("set_hr_blood_led",1)#
                                     EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
                                 else:
                                     self.Spo2_Need_Open = 0
@@ -1174,11 +1223,13 @@ class DeviceInfoManager(Abstract):
                                     EventMesh.publish(constants.EVENT.STOP_HEART)
                                     heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
                                     print("stop_heart heart_value:{}".format(heart_value))
+                                    EventMesh.publish("set_old_hr_data",heart_value)
                                     if heart_value > 50 and heart_value != None:
-                                        EventMesh.publish("set_old_hr_data",heart_value)
                                         EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+
                                     if self.Spo2_Need_Open == 0 and self.get_spo2_state == 3:
                                         EventMesh.publish("set_spo2_state",3)#2代表后台进入血氧测试
+                                        EventMesh.publish("set_hr_blood_led",1)#
                                         EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
                                         self.HR_Onestate = 2
                                         self.set_hsenor_crt = 2#血氧关闭
@@ -1194,11 +1245,13 @@ class DeviceInfoManager(Abstract):
                                         EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#K开血氧
                                         spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
                                         print("spo2_value:{}.......01..".format(spo2_value))
+                                        EventMesh.publish("set_old_spo2_data",spo2_value)
                                         if spo2_value > 85 and spo2_value != None:
-                                            EventMesh.publish("set_old_spo2_data",spo2_value)
                                             EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                            
                                         if self.Hr_Need_Open == 0 and self.get_hr_state == 3:
                                             EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                            EventMesh.publish("set_hr_blood_led",1)#
                                             EventMesh.publish(constants.EVENT.START_HEART)
                                             self.HR_Onestate = 2
                                             self.set_hsenor_crt = 1#心率
@@ -1213,45 +1266,52 @@ class DeviceInfoManager(Abstract):
                                     EventMesh.publish("set_spo2_state",0)#2代表后台进入血氧测试
                                     EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
                                     spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                    EventMesh.publish("set_old_spo2_data",spo2_value)
                                     if spo2_value > 85 and spo2_value != None:
-                                        EventMesh.publish("set_old_spo2_data",spo2_value)
                                         EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                       
                                 elif self.set_hsenor_crt == 1:
                                     EventMesh.publish("set_hr_state",0)#0代表g关闭测试
                                     print("stop debug7")
                                     EventMesh.publish(constants.EVENT.STOP_HEART)
                                     heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                    EventMesh.publish("set_old_hr_data",heart_value)
                                     if heart_value > 50 and heart_value != None:
-                                        EventMesh.publish("set_old_hr_data",heart_value)
                                         EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+
                                 self.HR_Onestate = 0
                         else:
                             self.HR_Onestate = 0
                             self.HR_OneTime = 0
         else:
-            if self.get_hr_state != None and self.get_spo2_state != None:
-                if self.get_hr_state ==3 or self.get_spo2_state ==3:#3单次测量
-                    if self.get_hr_state != 0:
-                        EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
-                        print("stop debug8")
-                        EventMesh.publish(constants.EVENT.STOP_HEART) 
-                    elif self.get_spo2_state != 0:
-                        EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
-                        EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+            print("stop hrself.get_hr_state:{} {}".format(self.get_hr_state,self.get_spo2_state))
+            if battery[0] == "1":#接上充电座 如果是灯亮着就关闭心里灯
+                get_hr_state = EventMesh.publish("get_hr_state")
+                get_spo2_state = EventMesh.publish("get_spo2_state")
+                if get_hr_state != None and get_spo2_state != None:
+                        if get_hr_state == 2 or get_hr_state == 3:
+                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                            print("sstop hr")
+                            EventMesh.publish(constants.EVENT.STOP_HEART) 
+                        elif get_spo2_state == 2 or get_spo2_state == 3:
+                            print("stop spo2")
+                            EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
             
-            if get_temp_time != None:
-                if get_temp_state != 0:
-                    self.temp_one_state = 0
-                    self.temp_state = 0
-                    temp = EventMesh.publish(constants.EVENT.GET_TEMP)              
-                    tmp_f = str(temp).split('.')[0] 
-                    tmp_f_tmp = int(tmp_f)
-
-                    tmp_d = str(temp).split('.')[1][:1]
-                    tmp_d_tmp = int(tmp_d)
-                    EventMesh.publish("set_temp_state",0)
-                    EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
-                    EventMesh.publish(constants.EVENT.STOP_TEMP)
+                if get_temp_time != None:
+                    get_temp_state  = EventMesh.publish("get_temp_state")
+                    if get_temp_state != 0:
+                        self.temp_one_state = 0
+                        self.temp_state = 0
+                        temp = EventMesh.publish(constants.EVENT.GET_TEMP)              
+                        tmp_f = str(temp).split('.')[0] 
+                        tmp_f_tmp = int(tmp_f)
+
+                        tmp_d = str(temp).split('.')[1][:1]
+                        tmp_d_tmp = int(tmp_d)
+                        EventMesh.publish("set_temp_state",0)
+                        EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                        EventMesh.publish(constants.EVENT.STOP_TEMP)
             self.SENSOR_time = time_tmp
             self.HR_Onestate = 0
             self.HR_OneTime = 0
@@ -1259,6 +1319,42 @@ class DeviceInfoManager(Abstract):
             self.old_time = 0    
             self.set_hsenor_crt = 0
 
+        print("battery[0] :{} battery[1]:{}".format(battery[0],battery[1]))
+        if battery[0] == "1":
+            if battery[1] >= 100:
+                EventMesh.publish("set_led_time_arg",[1000,1000,30,led_mode.LONG_LIGHT_GREEN,led_mode.OPEN_LONG_LIGHT_MODE])#开启长亮绿灯
+                self.bat_full = 1
+                self.usb_full = 0 
+            else:
+                self.bat_full = 0
+                timer_flag = EventMesh.publish("get_led_state")#设置参数
+                if timer_flag != 1:
+                    self.usb_full = 1
+                    EventMesh.publish("set_led_time_arg",[1000,1000,30,led_mode.LONG_LIGHT_RED,led_mode.OPEN_LONG_LIGHT_MODE])#開始測量
+                else:
+                    self.usb_full = 0
+                    EventMesh.publish("stop_led_timer")#设置参数
+        else:
+            if self.bat_full == 1:
+                self.bat_full = 0
+                EventMesh.publish("stop_led_timer")#设置参数
+            if self.usb_full == 1:
+                self.usb_full = 0
+                EventMesh.publish("stop_led_timer")#设置参数
+            
+            pass
+        low_power = battery[1]
+        if low_power <= 5:#小于5%红色灯慢闪
+            EventMesh.publish("set_led_time_arg",[1000,1000,30,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE])#開始測量
+        
+
+
+        get_hr_state = EventMesh.publish("get_hr_state")
+        get_spo2_state = EventMesh.publish("get_spo2_state")
+        # print("stop get_hr_state :{} get_spo2_state:{}".format(get_hr_state,get_spo2_state))
+        if get_hr_state != 0 or  get_spo2_state != 0:
+           EventMesh.publish("set_hr_blood_led",1)#设置参数 
+
         voiceCall.setCallback(voice_callback)
             
         #quecgnss.gnssEnable(0)  
@@ -1387,24 +1483,34 @@ class DeviceInfoManager(Abstract):
             charge_state = '0'
 
         vbat = 0
-        temp = Power.getVbatt()
-        if temp <= 3505:
-            vbat = 0 
-        elif temp <= 3699:
-            vbat = 20 #"U:/vbat_20.jpg"
-        elif temp <= 3772:
-            vbat = 40 #"U:/vbat_40.jpg"
-        elif temp <= 3882:
-            vbat = 60 #"U:/vbat_60.jpg"
-        elif temp <= 4070:
-            vbat = 80 #"U:/vbat_80.jpg"
+        #temp = Power.getVbatt()
+        temp = EventMesh.publish("get_curr_battery_level")
+        if temp != None :
+            if temp <= 3505:
+                vbat = 0 
+            elif temp <= 3699:
+                vbat = 20 #"U:/vbat_20.jpg"
+            elif temp <= 3772:
+                vbat = 40 #"U:/vbat_40.jpg"
+            elif temp <= 3882:
+                vbat = 60 #"U:/vbat_60.jpg"
+            elif temp <= 4070:
+                vbat = 80 #"U:/vbat_80.jpg"
+            else:
+                vbat = 100 #"U:/vbat_100.jpg"
         else:
-            vbat = 100 #"U:/vbat_100.jpg"
+            vbat = 100
 
         result = [charge_state, vbat]
 
         return result
 
+    def set_curr_battery_level(self, event=None, msg=None):
+        self.curr_battery_level = msg
+    
+    def get_curr_battery_level(self, event=None, msg=None):
+        return self.curr_battery_level
+    
     def get_device_fw_version(self, *args):
         '''
         获取设备固件版本号
@@ -1786,11 +1892,45 @@ class AddrBookManager(Abstract):
     def post_processor_after_instantiation(self):
         EventMesh.subscribe("get_phonebook_list", self.get)
         EventMesh.subscribe("set_phonebook_list", self.set)
+        EventMesh.subscribe("call_phonebook_one_call", self.call_phonebook_one_call)
+        EventMesh.subscribe("call_phonebook_two_call", self.call_phonebook_two_call)
+        EventMesh.subscribe("call_phonebook_three_call", self.call_phonebook_three_call)
 
     def get(self, event, msg):
         self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
         return [self.check_json,self.read_phonebook]
     
+    def call_phonebook_one_call(self, event, msg):
+        if self.read_phonebook != {}:
+            if len(self.read_phonebook) >= 1:
+                phonebook_keys = sorted(self.read_phonebook.keys())
+                name = self.read_phonebook[phonebook_keys[0]]
+                key_tmp = phonebook_keys[0]
+                if len(name) != 0:
+                    voiceCall.callStart(str(name))
+                print("call_phonebook_one_call name:{} key_tmp:{}".format(name,key_tmp))
+
+    def call_phonebook_two_call(self, event, msg):
+        if self.read_phonebook != {}:
+            if len(self.read_phonebook) >= 2:
+                phonebook_keys = sorted(self.read_phonebook.keys())
+                name = self.read_phonebook[phonebook_keys[1]]
+                key_tmp = phonebook_keys[1]
+                if len(name) != 0:
+                    voiceCall.callStart(str(name))
+                print("call_phonebook_two_call name:{} key_tmp:{}".format(name,key_tmp))
+    
+    def call_phonebook_three_call(self, event, msg):
+        if self.read_phonebook != {}:
+            if len(self.read_phonebook) >= 3:
+                phonebook_keys = sorted(self.read_phonebook.keys())
+                name = self.read_phonebook[phonebook_keys[2]]
+                key_tmp = phonebook_keys[2]
+                if len(name) != 0:
+                    voiceCall.callStart(str(name))
+                print("call_phonebook_three_call name:{} key_tmp:{}".format(name,key_tmp))
+    
+
     def set(self, event, msg):
         self.check_json = msg[0]
         self.read_phonebook = msg[1]
@@ -1972,42 +2112,43 @@ class gethistoryDataManager(Abstract):
         return self.read_histroy_spo2_data
 
     def set_history_spo2_value(self, event, msg): 
-        if msg > 0:
-            self.read_histroy_spo2_data = EventMesh.publish("get_history_spo2_value")
-            count = len(self.read_histroy_spo2_data)
-            if count >= 7:
-                for i in range(6):
-                    self.read_histroy_spo2_data["0{}".format(i+1)] = self.read_histroy_spo2_data["0{}".format(i+2)]
-                self.read_histroy_spo2_data["07"] = msg
-            else:
-                self.read_histroy_spo2_data["0{}".format(count+1)] = msg
-            with open("/usr/static/storage_file/history_spo2.json","w",encoding="utf-8") as fd:
-                ujson.dump(self.read_histroy_spo2_data,fd)
+        pass
+
 
 
     def get_history_temp_value(self, event, msg): #近7次体温历史数据统计显示
         return self.read_histroy_temp_data
 
     def set_history_temp_value(self, event, msg): 
-        if msg > 0:
-            self.read_histroy_temp_data = EventMesh.publish("get_history_temp_value")
-            count = len(self.read_histroy_temp_data)
-            if count >= 7:
-                for i in range(6):
-                    self.read_histroy_temp_data["0{}".format(i+1)] = self.read_histroy_temp_data["0{}".format(i+2)]
-                self.read_histroy_temp_data["07"] = msg
-            else:
-                self.read_histroy_temp_data["0{}".format(count+1)] = msg
-            with open("/usr/static/storage_file/history_temp.json","w",encoding="utf-8") as fd:
-                ujson.dump(self.read_histroy_temp_data,fd)
+        count = len(self.read_histroy_temp_data)
+        print(count)
+        if count >= 7:
+            for i in range(6):
+                self.read_histroy_temp_data["0{}".format(i+1)] = self.read_histroy_temp_data["0{}".format(i+2)]
+            self.read_histroy_temp_data["07"] = msg
+        else:
+            self.read_histroy_temp_data["0{}".format(count+1)] =msg
+        # with open("/usr/static/storage_file/history_temp.json","w",encoding="utf-8") as fd:
+        #     ujson.dump(self.read_histroy_temp_data,fd)
+           
 
 
     def get_history_hr_value(self, event, msg): #近7次心率历史数据统计显示
         return self.read_histroy_hr_data
 
     def set_history_hr_value(self, event, msg): 
+        pass
+            
+           
+
+    def save_hr_value(self, event, msg): 
         if msg >= 50:
-            self.read_histroy_hr_data = EventMesh.publish("get_history_hr_value")
+            EventMesh.publish("set_hr_blood_led",2)#
+            self.read_data = EventMesh.publish("get_storage_data")
+            self.read_data["old_hr"] = msg
+            
+            EventMesh.publish("set_storage_data", self.read_data)
+           
             count = len(self.read_histroy_hr_data)
             if count >= 7:
                 for i in range(6):
@@ -2015,30 +2156,44 @@ class gethistoryDataManager(Abstract):
                 self.read_histroy_hr_data["07"] = msg
             else:
                 self.read_histroy_hr_data["0{}".format(count+1)] = msg
-            with open("/usr/static/storage_file/history_hr.json","w",encoding="utf-8") as fd:
-                ujson.dump(self.read_histroy_hr_data,fd)
 
-    def save_hr_value(self, event, msg): 
-        if msg >= 50:
-            self.read_data = EventMesh.publish("get_storage_data")
-            self.read_data["old_hr"] = msg
-
-            EventMesh.publish("set_storage_data", self.read_data)
             with open("/usr/static/storage_file/config.json","w",encoding="utf-8") as fd:
                 ujson.dump(self.read_data,fd)
-            self.oldHr = msg
 
+            # with open("/usr/static/storage_file/history_hr.json","w",encoding="utf-8") as fd:
+            #     ujson.dump(self.read_histroy_hr_data,fd)
+            # print(self.read_histroy_temp_data)
+        else:
+            EventMesh.publish("set_hr_blood_led",3)#
+        if msg != None:
+            self.oldHr = msg
     def get_hr_value(self, event, msg): 
         return self.oldHr
 
     def save_spo2_value(self, event, msg): 
         if msg >= 85:
+            EventMesh.publish("set_hr_blood_led",2)#
             self.read_data = EventMesh.publish("get_storage_data")
             self.read_data["old_spo2"] = msg
-
+            
             EventMesh.publish("set_storage_data", self.read_data)
+           
+            count = len(self.read_histroy_spo2_data)
+            if count >= 7:
+                for i in range(6):
+                    self.read_histroy_spo2_data["0{}".format(i+1)] = self.read_histroy_spo2_data["0{}".format(i+2)]
+                self.read_histroy_spo2_data["07"] = msg
+            else:
+                self.read_histroy_spo2_data["0{}".format(count+1)] = msg
+
             with open("/usr/static/storage_file/config.json","w",encoding="utf-8") as fd:
                 ujson.dump(self.read_data,fd)
+
+            # with open("/usr/static/storage_file/history_spo2.json","w",encoding="utf-8") as fd:
+            #     ujson.dump(self.read_histroy_spo2_data,fd)
+        else:
+            EventMesh.publish("set_hr_blood_led",3)#测量失败长亮3s红灯
+        if msg != None:
             self.oldspo2 = msg
 
     def get_spo2_value(self, event, msg): 
@@ -2052,6 +2207,8 @@ class gethistoryDataManager(Abstract):
         step = EventMesh.publish(constants.EVENT.GET_STEP)
         self.old_step = self.oldstep + step[0]
         return self.old_step
+
+
 #获取旧的时间戳
 class getOldTimeManager(Abstract):
     # 获取天气数据
@@ -2480,6 +2637,8 @@ class getCountDownManager(Abstract):#倒计时
     def get_low_bat_btn(self, event, msg): 
         return self.low_btn
 
+
+
     
 class getBootOffManager(Abstract):#开关机时间
     def __init__(self):
index 5a2122c..42eb6e1 100644 (file)
@@ -644,8 +644,8 @@ class FIND_ProtoCol(ProtoCol):
         # a.set_pa(Pin.GPIO29)
         # a.setVolume(10)
         # a.play(1, 1, 'U:/audio_audio_haixiu.mp3')  #文件名前面要加上路径
-        
-        EventMesh.publish("load_screen", {"screen": "FIND"})
+        EventMesh.publish("set_find_watch_led")#
+        # EventMesh.publish("load_screen", {"screen": "FIND"})
         #print("FIND_ProtoCol:recv:%s"%(msg)) 
 
 class POWEROFF_ProtoCol(ProtoCol):
@@ -724,7 +724,7 @@ class PHL_ProtoCol(ProtoCol):
         
         EventMesh.publish(constants.PROTOCOL.PHL_SEND)
         EventMesh.publish("set_phonebook_list",[1,phonebook])
-        EventMesh.publish("contact_updata_list_show")
+        # EventMesh.publish("contact_updata_list_show")
 
          
 class WT_ProtoCol(ProtoCol):
@@ -773,7 +773,7 @@ class WT_ProtoCol(ProtoCol):
         print("WT_ProtoCol RECV msg:%s"%(msg))
 
         EventMesh.publish("set_weather_data",[msg_date,msg_time,msg_weather_content,msg_type,msg_temp,msg_min_temp,msg_max_temp,msg_city,1])
-        EventMesh.publish("updata_weather_show")
+        # EventMesh.publish("updata_weather_show")
         EventMesh.publish(constants.PROTOCOL.WT_SEND)
 
 class REMIND_ProtoCol(ProtoCol):
@@ -1173,6 +1173,7 @@ class MONITOR_ProtoCol(ProtoCol):
                     print("MONITOR RECV msg:{} {}".format(contact,type(contact)))
                     EventMesh.publish("save_phonename", contact)  
                     EventMesh.publish("save_phonenum", contact)  
+                    EventMesh.publish("set_call_state", 1)#
                     voiceCall.callStart(contact)
         EventMesh.publish(constants.PROTOCOL.MONITOR_SEND)  
 
@@ -1329,7 +1330,176 @@ class Time_ProtoCol(ProtoCol):
         #EventMesh.publish(constants.PROTOCOL.TIME_SEND)  
 
 
+class TK_ProtoCol(ProtoCol):
+    """微聊"""
+    TYPE = "TK"
+    
+
+    def send(self, event, msg):
+        # [SZKW*YYYYYYYYYYYYYYY*LEN*TK,AMR 格式音频数据]
+        #[XT*YYYYYYYYYYYYYYY*LEN*TKS,秒数(十进制),AMR 格式音频数据]
+        arm_data = msg[1]
+        arm_sec = msg[0]
+        print("TK_ProtoCol:msgtype:{} arm_sec:{}".format(type(msg),arm_sec))
+
+        arm = bytearray()
+        for i in range(len(arm_data)):
+            if arm_data[i] == 0x7d:
+                arm.extend(b'\x7d\x01')
+            elif arm_data[i] == 0x5b :
+                arm.extend(b'\x7d\x02')
+            elif arm_data[i] == 0x5d :
+                arm.extend(b'\x7d\x03')
+            elif arm_data[i] == 0x2c :
+                arm.extend(b'\x7d\x04')
+            elif arm_data[i] == 0x2a :
+                arm.extend(b'\x7d\x05')
+            else :
+                arm.append(arm_data[i])
+               
+        datalen = len(arm) + 4+len(str(arm_sec))+1
+        #Wechat_log("len(str(arm_sec)):{}".format(len(str(arm_sec))+1))
+        send_data = bytearray("SZKW*%s*%04X*TKS,%d,"%(self.imei,datalen,arm_sec))
+        send_data.extend(arm)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = bytearray('[')
+        data.extend(MD5_SIGN)
+        data.extend(send_data)
+        data.extend(']')
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+
+    def recv(self, event, msg):
+        """
+
+        
+        @param event: 微聊
+        @param msg: 接收到的下行数据
+        [SZKW*860132060004322*20BD*TK,#!AMR...]
+        """
+        #Wechat_log("K_ProtoCol:recv:data:{}".format(msg))
+        msg_tmp = msg.decode('ascii')
+        str = msg_tmp.split('TK,')
+        # Wechat_log("TK_ProtoCol:recv:len:{} {} {}".format(len(msg),len(str),msg_tmp.find("#!AMR")))
+        if  msg_tmp.find("#!AMR") != -1: #是否是服务器下发音频数据
+            # Wechat_log("TK_ProtoCol:recv:datalen{}".format(len(msg)))
+            arm_data = bytearray(str[1])#获取amr输出
+            get_wechat_data = EventMesh.publish("get_wechat_data")
+            
+            MXA_MSG = get_wechat_data[0]
+            wechat_recode_list = get_wechat_data[1]
+            wechat_num = get_wechat_data[1]
+            # Wechat_log("TK_ProtoCol:datalen:{} {} {}".format(wechat_num,MXA_MSG,wechat_recode_list))
+            
+            if wechat_num >= MXA_MSG:
+                wechat_num = 0 
+            if wechat_num == 0:
+                wechat_num += 1 
+            elif wechat_num > 0:
+                wechat_num += 1 
+          
+            EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_num])
+            #写语音文件数据
+            screen_NAME = EventMesh.publish("get_screen_NAME")
+            get_lcd_state = EventMesh.publish("get_lcd_state")
+            if screen_NAME != "wechat" or get_lcd_state == 0:
+                pass
+                # EventMesh.publish("load_screen", {"screen": "wechat_popup"})
+            else:
+                pass
+                # EventMesh.publish("wechat_updata_list_show")
+            # path = "/usr/static/storage_file/audio_amr/amr/{}.amr".format(wechat_num)
+            path = "/usr/static/storage_file/{}.amr".format(wechat_num)
+            with open(path,"w") as fd:
+                arm = bytearray()
+                j = 0
+                for i in range(len(arm_data)):
+                    if arm_data[j] == 0x7d and arm_data[j+1] == 0x01:
+                        arm.extend(b'\x7d')
+                        j+=1
+                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x02:
+                        arm.extend(b'\x5b')
+                        j+=1
+                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x03:
+                        arm.extend(b'\x5d')
+                        j+=1
+                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x04:
+                        arm.extend(b'\x2c')
+                        j+=1
+                    elif arm_data[j] == 0x7d and arm_data[j+1] == 0x05:
+                        arm.extend(b'\x2a')
+                        j+=1
+                    else :
+                        arm.append(arm_data[j])
+                    j+=1
+                    if j >= len(arm_data):
+                        break
+                fd.write(arm)
+            
+            
+            
 
+class MESSAGE_ProtoCol(ProtoCol):
+    """微聊"""
+    TYPE = "MESSAGE"
+    
+
+    def send(self, event, msg):
+       
+        #[XT*334588000000156*0007*MESSAGE]
+        send_data = "SZKW*%s*0007*MESSAGE"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data))
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+
+    def recv(self, event, msg):
+        """
+
+        @param event: 微聊文字
+        @param msg: 接收到的下行数据
+        """
+
+        EventMesh.publish(constants.PROTOCOL.MESSAGE_SEND)
+        # msg = msg[1:-1]
+
+        # msg_s = msg.decode('ascii')
+        # msg_s = msg_s.split(',')
+        # msg_s = msg_s[1]
+        # # Wechat_log("msg_tmp:len:{}\r\n data:{}".format(len(msg_s),msg_s))
+        
+
+        # get_wechat_data = EventMesh.publish("get_wechat_data")
+        
+        # MXA_MSG = get_wechat_data[0]
+        # wechat_recode_list = get_wechat_data[1]
+        # wechat_num = wechat_recode_list["num"]
+        # # Wechat_log("TK_ProtoCol:datalen:{} {} {}".format(wechat_num,MXA_MSG,wechat_recode_list))
+        
+        # if wechat_num >= MXA_MSG:
+        #     wechat_num = 0 
+        # if wechat_num == 0:
+        #     wechat_num += 1 
+        # elif wechat_num > 0:
+        #     wechat_num += 1 
+        # msg_txt = {}
+        # # 0 1 2 3
+        # print("wechat_num:init {}".format(wechat_num))
+        # msg_txt = UnicodeHexStr_To_Utf8Str(msg_s)
+        # # Wechat_log("msg_txt:{}".format(msg_txt))
+        # wechat_recode_list["%02d"%(wechat_num)] = "T:{}".format(msg_txt)
+        # wechat_recode_list['num'] = wechat_num
+        # # EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_recode_list])
+        # # Wechat_log("wechat_recode_list:len data:{}".format(wechat_recode_list))
+        
+        # screen_NAME = EventMesh.publish("get_screen_NAME")
+        # get_lcd_state = EventMesh.publish("get_lcd_state")
+        # if screen_NAME != "wechat" or get_lcd_state == 0:
+        #     pass
+        #     # EventMesh.publish("load_screen", {"screen": "wechat_popup"})
+        # else:
+        #     pass
+        #     # EventMesh.publish("wechat_updata_list_show")
 
 
 class ProtoColResolver(object):
index 454a7c5..073ed26 100644 (file)
@@ -5,8 +5,7 @@ if ql_fs.path_exists("/ext") == False:
     uos.mount(ldev,'/ext')
 res = uos.statvfs("/ext")
 res = list(res)
-print('总ext空间:{} MB,剩余空间:{} MB'.format((((res[0] * res[2]) / 1024 / 1024)),((res[0] * res[3]) / 1024 / 1024)))
-from lcd import tp_cst816
+
 from btn_device_ec800m import BtnDevice
 
 import lvgl as lv
@@ -15,13 +14,12 @@ import osTimer
 import pm
 import ql_fs
 from machine import Pin
-from lcd import lcd,lcd_ctrl,tp_cst816,lcd_ctrl
 from misc import PWM
 import uos
 from machine import I2C
 from Hsensor import GH3018
 from Gsensor import SC7A20
-btn_device = BtnDevice(tp_cst816)
+btn_device = BtnDevice()
 btn_device.start()
 i2c0 = I2C(I2C.I2C0, I2C.FAST_MODE)
 WHO_AM_I = bytearray([0x01, 0])
@@ -46,8 +44,6 @@ utime.sleep(5)
 PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, 0, 1)
 PWM_backlight.open()
 hsensor.close()
-tp_cst816.suspend()
-lcd.lcd_display_off()
 #lcd_ctrl.write(0)
 lv.autoSleep(1)
 pm.autosleep(1)
index 7bb1e42..742f097 100644 (file)
@@ -14,11 +14,13 @@ import ql_fs
 import audio
 import sms
 from machine import Pin
+from misc import PWM
 import uos
 import gc
 import _thread
 from queue import Queue
 from machine import RTC
+from usr.led import open_led_green,close_led_green
 
 def audio_cb(event):
     if event == 0:
@@ -217,13 +219,6 @@ class Screen(Abstract):
 
     def done_error(self):
         pass
-
-    def lcd_off(self):
-        pass
-
-    def lcd_on(self):
-        pass
-
     def handle_message_event(self,data):
         pass
     def publish_message_event(self,data):
@@ -1368,6 +1363,7 @@ class DialingNoPlayPopupScreen(Screen):#正在拨号中...未打出
 
     def timeout_call(self,e):
         phone_num = EventMesh.publish("get_phonenum")  
+        EventMesh.publish("set_call_state", 1)#
         voiceCall.callStart(phone_num)
         
     def timeout_hangup(self,e):
@@ -2180,8 +2176,9 @@ class HeartrateScreen(Screen):
         if self.point > 120: #测20s
             heartrate_done_img.set_src("U:/static/hr_gif_03.png")
             self.heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+            EventMesh.publish("set_old_hr_data",self.heart_value)
             if self.heart_value > 50:
-                EventMesh.publish("set_old_hr_data",self.heart_value)
+                
                 EventMesh.publish("set_history_hr_value",self.heart_value)
                 EventMesh.publish(constants.PROTOCOL.HEART_SEND,self.heart_value)
             heartrate_reset_btn_img.clear_flag(lv.obj.FLAG.HIDDEN)
@@ -5563,36 +5560,17 @@ class UIFINDScreen(Screen):
         self.FIND_timer_count = 0
 
         self.meta = None
-
+    
     def initialization(self):
-        global FIND_screen ,watchface_mpsignal_img 
-        
-        if FIND_screen ==None:
-            FIND_screen = lv.obj()
-            print("FIND_screen")
-            FIND_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
-            # add style for watchface
-            FIND_screen.add_style(style_screen, lv.PART.MAIN|lv.STATE.DEFAULT)
-            #进入图片
-            watchface_mpsignal_img = lv.img(FIND_screen)
-            watchface_mpsignal_img.set_pos(int(40),int(45))
-            watchface_mpsignal_img.set_size(160,230)
-            watchface_mpsignal_img.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
-            watchface_mpsignal_img.add_flag(lv.obj.FLAG.CLICKABLE)
-            watchface_mpsignal_img.set_src("U:/static/find_phone.png")
-            watchface_mpsignal_img.add_style(style_screen, lv.PART.MAIN|lv.STATE.DEFAULT)
-            self.meta = FIND_screen
-        
+        self.meta = FIND_screen
 
     def post_processor_after_initialization(self):
-        utime.sleep_ms(200)#不加延时会切屏
         self.FIND_timer_count = 0
         print("self.FIND_timer_count:{}".format(self.FIND_timer_count))
         self.FIND_timer.start(3000, 1, self.FIND_timer_cb)
         self.aud.play(1, 1, 'U:/static/audio_audio_haixiu.mp3')  #播放声音
 
     def FIND_timer_cb(self, *args):
-        EventMesh.publish("system_sleep_rest")
         self.aud.play(1, 1, 'U:/static/audio_audio_haixiu.mp3') 
         self.FIND_timer_count += 1
         if self.FIND_timer_count > 20: #120秒
@@ -5601,7 +5579,7 @@ class UIFINDScreen(Screen):
     def stop_FIND(self) :
         self.FIND_timer.stop()
         self.aud.stop()  #播放声音
-        EventMesh.publish("load_screen", {"screen": "main_menu"})
+        
 
     def Close(self):
         print("self.FIND_timer_Close")
@@ -5984,6 +5962,8 @@ class UI(object):
         
         if self.level == None:
             self.level = 6
+        self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, self.level, 10)
+        self.PWM_backlight.open()
         self.sleep_lock = 0
 
     def post_processor_after_instantiation(self):
@@ -6135,8 +6115,9 @@ class UI(object):
             else:
                 EventMesh.publish("load_screen", {"screen": "no_sim_power_screen"})
 
-        if event == "btn1_press":           
-            self.screen.btn1_release()
+        if event == "btn1_press":        
+            pass   
+            
         
 
     def btn_release(self, event, msg):
@@ -6164,12 +6145,15 @@ class UI(object):
             
             #lcd_ctrl.write(1)
             #utime.sleep(10)
-            self.screen.lcd_on()
+            
             self.system_sleep_timer.start(1000, 1, self.system_sleep_timer_cb)
             EventMesh.publish("set_lcd_state",self.sleep_flag)
+           
             utime.sleep_ms(2)
+            lv.autoSleep(0)
             pm.autosleep(0)
             pm.sclkEx_set(0, 1, 5)
+            utime.sleep_ms(60)
             self.level = EventMesh.publish("get_brightness_level")
             if self.level == None:
                 self.level = 6 
@@ -6177,6 +6161,7 @@ class UI(object):
                 self.level = 10
             elif self.level <= 0:
                 self.level = 1
+           
             self.sleep_lock = 0
             
 
@@ -6189,16 +6174,21 @@ class UI(object):
             print("__lcd_off")
             if self.sleep_lock == 1:
                 print("__lcd_on:sleep_lock:error!")
+                utime.sleep_ms(200)
             self.sleep_lock = 1
             self.sleep_flag = 0
-
+           
+            #lcd_ctrl.write(0)
+            #
             lv.autoSleep(1)
             pm.autosleep(1)
             pm.sclkEx_set(1, 1, 5)
+            utime.sleep_ms(2)
+           
             #utime.sleep_ms(80)
             EventMesh.publish("set_lcd_state",self.sleep_flag)
             self.sleep_lock = 0
-            self.screen.lcd_off()
+           
             self.system_sleep_timer.stop()
             EventMesh.publish("Hsensor_set_sleep") #让系统更快休眠
 
@@ -6231,7 +6221,7 @@ class UI(object):
         return self
     
     def get_screen_NAME(self, event, msg):
-        return self.screen.NAME
+        return 0
     
     def load_screen_cb(self, topic, msg):
         EventMesh.publish("publish_message_event_ui",{"func":self.load_screen,"data":msg})  
@@ -6262,6 +6252,8 @@ class UI(object):
 
                 if self.screen_old != None :
                     self.screen_old.Close() #先关闭上一次界面
+                    self.lv.img.cache_invalidate_src(None) #清img cache
+                    self.lv.img.cache_set_size(16) #开img cache
                     if self.screen_old.meta_type != "popup": #不是弹窗,保存上一个界面,用来返回
                         self.screen_prev = self.screen_old #
                 self.screen_old = self.screen
@@ -6270,10 +6262,11 @@ class UI(object):
                 print("load_screen:post_processor_before_initialization")
                 self.screen.post_processor_before_initialization()
                 print("load_screen:initialization")
-                self.screen.initialization()
+                # self.screen.initialization()
                 
                 print("load_screen.load()")
                 self.screen.load()
+                self.lv.scr_load(self.screen.get_meta())
                 
                 self.screen.post_processor_after_initialization()
                 self.__lcd_on()
index 8b7bc40..68ba3ff 100644 (file)
@@ -1,2 +1,2 @@
 import main_init 
-main_init()
\ No newline at end of file
+main_init.main_init()
\ No newline at end of file