新版lcd、心率血氧整合
authorp15692025051 <846603105@qq.com>
Thu, 6 Apr 2023 08:23:09 +0000 (16:23 +0800)
committerp15692025051 <846603105@qq.com>
Thu, 6 Apr 2023 08:23:09 +0000 (16:23 +0800)
2.sdk/HeliosSDK_For_EC800MCNGA/services/microPython/ports/quectel/core/source/modHsensor_GH3018.c
3.code/1.watch/2.code/appAlipay.py
3.code/1.watch/2.code/constants.py
3.code/1.watch/2.code/lcd.py
3.code/1.watch/2.code/main_1.py
3.code/1.watch/2.code/mgr.py
3.code/1.watch/2.code/ui.py

index 547b387..0883f76 100644 (file)
@@ -43,7 +43,6 @@ typedef struct _GH3018_obj_t
     uint8_t i2c_no;
        uint8_t i2c_mode;
     uint8_t irq;
-       uint8_t reset;
        uint8_t power;
 
 } GH3018_obj_t;
@@ -110,15 +109,13 @@ STATIC mp_obj_t GH3018_make_new(const mp_obj_type_t *type,
         ARG_i2c_no,
         ARG_i2c_mode,
         ARG_irq,
-        ARG_reset,
                ARG_power,
     };
 
     static const mp_arg_t allowed_args[] = {
         { MP_QSTR_i2c_no, MP_ARG_INT, {.u_int = 0}},
         { MP_QSTR_i2c_mode, MP_ARG_INT, {.u_int = 1}},
-        { MP_QSTR_irq, MP_ARG_INT, {.u_int = 2}},
-        { MP_QSTR_reset, MP_ARG_INT, {.u_int = 3}},
+        { MP_QSTR_irq, MP_ARG_INT, {.u_int = 27}},
                { MP_QSTR_power, MP_ARG_INT, {.u_int = 30}},
     };
 
@@ -130,7 +127,7 @@ STATIC mp_obj_t GH3018_make_new(const mp_obj_type_t *type,
     self->i2c_no = args[ARG_i2c_no].u_int;
        self->i2c_mode = args[ARG_i2c_mode].u_int;
     self->irq = args[ARG_irq].u_int;
-       self->reset = args[ARG_reset].u_int;
+
        self->power = args[ARG_power].u_int;
     return MP_OBJ_FROM_PTR(self);
 }
@@ -172,7 +169,7 @@ void sensor_thread_entry(void * argv)
                        Helios_msleep(10);
                }else 
                {
-                       Helios_msleep(1500);
+                       Helios_msleep(1000);
                        SL_SC7A20_PEDO_KCAL_WRIST_SLEEP_SWAY_L_ALGO();
                }
                
@@ -208,7 +205,7 @@ mp_obj_t mp_GH3018_init(mp_obj_t self_in)
 
        gpio_struct.dir = HELIOS_GPIO_OUTPUT;
        Helios_GPIO_Init(self->power, &gpio_struct);//ldo
-       Helios_GPIO_Init(self->reset, &gpio_struct);//复位IO
+
        gpio_struct.dir = HELIOS_GPIO_INPUT;
        gpio_struct.pull = HELIOS_PULL_NONE;
        gpio_struct.value = HELIOS_LVL_LOW;
@@ -235,10 +232,6 @@ mp_obj_t mp_GH3018_init(mp_obj_t self_in)
        Helios_msleep(10);
        Helios_GPIO_SetLevel(self->power, HELIOS_LVL_HIGH);
        Helios_msleep(20);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_LOW);
-       Helios_msleep(10);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_HIGH);
-       Helios_msleep(20);
        
                
        //gh30x_module_start_without_adt(GH30X_RUN_MODE_HB);
@@ -280,8 +273,6 @@ STATIC mp_obj_t mp_GH3018_deinit(mp_obj_t self_in)
     GH3018_obj_t *self = MP_OBJ_TO_PTR(self_in);
        gh30x_module_stop();
        Helios_GPIO_Deinit((Helios_GPIONum)self->irq);
-       Helios_GPIO_Deinit((Helios_GPIONum)self->reset);
-       // Helios_GPIO_Deinit((Helios_GPIONum)self->power);
        Helios_ExtInt_Deinit(self->irq);
        // Helios_I2C_Deinit((Helios_I2CEnum) self->i2c_no);
        Helios_GPIO_SetLevel(self->power, HELIOS_LVL_LOW);
@@ -305,10 +296,7 @@ STATIC mp_obj_t mp_GH3018_open_heart(mp_obj_t self_in)
        Helios_msleep(10);
        Helios_GPIO_SetLevel(self->power, HELIOS_LVL_HIGH);
        Helios_msleep(20);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_LOW);
-       Helios_msleep(10);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_HIGH);
-       Helios_msleep(20);
+
        ret = gh30x_module_init();
        if(ret == 1)
        {
@@ -341,10 +329,7 @@ STATIC mp_obj_t mp_GH3018_open_blood_oxygen(mp_obj_t self_in)
        Helios_msleep(10);
        Helios_GPIO_SetLevel(self->power, HELIOS_LVL_HIGH);
        Helios_msleep(20);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_LOW);
-       Helios_msleep(10);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_HIGH);
-       Helios_msleep(20);
+
        ret = gh30x_module_init();
        if(ret == 1)
        {
@@ -378,10 +363,7 @@ STATIC mp_obj_t mp_GH3018_open_hrv(mp_obj_t self_in)
        Helios_msleep(10);
        Helios_GPIO_SetLevel(self->power, HELIOS_LVL_HIGH);
        Helios_msleep(20);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_LOW);
-       Helios_msleep(10);
-       Helios_GPIO_SetLevel(self->reset, HELIOS_LVL_HIGH);
-       Helios_msleep(20);
+
        ret = gh30x_module_init();
        if(ret == 1)
        {
@@ -402,13 +384,19 @@ STATIC mp_obj_t mp_GH3018_open_hrv(mp_obj_t self_in)
 STATIC mp_obj_t mp_GH3018_close(mp_obj_t self_in)
 {
     GH3018_obj_t *self = MP_OBJ_TO_PTR(self_in);
-       gh30x_module_stop();
-       Helios_GPIO_SetLevel(self->power, HELIOS_LVL_LOW);
-       is_open_gh3018 = 0;
-       if(sensor_timer != 0)
+       if(is_open_gh3018 == 1)
        {
-               Helios_Timer_Stop(sensor_timer);
+               gh30x_module_stop();
+               if(sensor_timer != 0)
+               {
+                       Helios_Timer_Stop(sensor_timer);
+               }
        }
+               
+       is_open_gh3018 = 0;
+       Helios_GPIO_SetLevel(self->power, HELIOS_LVL_LOW);
+       
+       
     return mp_obj_new_int(1);
 }
 //获取心律
index e086970..9d0c18d 100644 (file)
@@ -88,9 +88,9 @@ class Alipay(Abstract):
         if self.is_simcard_identify == 0  and self.is_init != 0:
             id2_st = bytearray([0])
             id2_ret = self.alipay.id2_init()
-            print("id2_ret:%d"%id2_ret)
+            #print("id2_ret:%d"%id2_ret)
             self.alipay.id2_check_status(id2_st)
-            print("id2_st:",str(id2_st))
+            #print("id2_st:",str(id2_st))
             if id2_st[0] != 1:
                 return
             self.is_init = self.alipay.pay_init(90000, 90000,\
index b84670d..88424c8 100644 (file)
@@ -64,6 +64,8 @@ class EVENT:
     SYSTEM_SLEEP = "SYSTEM_SLEEP"
     SYSTEM_UP = "SYSTEM_UP"
     START_HEART = "START_HEART" 
-    PUSH_HEART = "PUSH_HEART"
+    GET_HEART = "GET_HEART"
+    STOP_HEART = "STOP_HEART"
     START_BLOOD_OXYGEN = "STARTT_BLOOD_OXYGEN" 
-    PUSHT_BLOOD_OXYGEN = "PUSHT_BLOOD_OXYGEN"
\ No newline at end of file
+    GET_BLOOD_OXYGEN = "GET_BLOOD_OXYGEN"
+    STOP_BLOOD_OXYGEN = "STOP_BLOOD_OXYGEN"
\ No newline at end of file
index 2f83db9..69a9619 100644 (file)
@@ -139,8 +139,8 @@ displayon = bytearray(init_data4)
 
 
 lcd_ctrl = Pin(Pin.GPIO18, Pin.OUT, Pin.PULL_DISABLE, 1)
-lcd.lcd_init(init_buf, 240, 320, 52000, 1, 4, 0, invalid, displayon, displayoff, None,TESel = True,TEPin = 7)
-gpio_backlight = Pin(Pin.GPIO17, Pin.OUT, Pin.PULL_PU, 0)
+lcd.lcd_init(init_buf, 240, 320, 52000, 1, 4, 0, invalid, displayon, displayoff, None,TESel = True,TEPin = 5)
+gpio_backlight = Pin(Pin.GPIO37, Pin.OUT, Pin.PULL_PU, 0)
 gpio_backlight.write(1)
 
 LCD_SIZE_W = 240
index e0e2efa..5243cd0 100644 (file)
@@ -35,8 +35,10 @@ class watchApp(App):
 
 if __name__ == '__main__':
     import uos
-    ldev = uos.VfsLfs1(32, 32, 32, "ext_fs",0,3)
-    uos.mount(ldev,'/ext')
+    import ql_fs
+    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)))
index 683b0ad..2fdc044 100644 (file)
@@ -514,12 +514,10 @@ class DeviceInfoManager(Abstract):
         print("DeviceInfoManager:1.1")
         self.gsensor.init()
         print("DeviceInfoManager:2")
-        # self.hsensor = GH3018()
-        # self.hsensor.activate()
-        # self.hsensor.init()
-        # self.hsensor.close()
-        # self.hsensor_time = osTimer()
-        # self.hsensor_time_count = 0
+        self.hsensor = GH3018()
+        self.hsensor.activate()
+        self.hsensor.init()
+        self.hsensor.close()
         # #print("hsensor.open_heart:%d\r\n"%(self.hsensor.open_heart()))
         print("DeviceInfoManager:3")
         ret = quecgnss.init()
@@ -560,6 +558,11 @@ class DeviceInfoManager(Abstract):
         
         EventMesh.subscribe(constants.EVENT.START_BLOOD_OXYGEN, self.start_blood_oxygen)
         EventMesh.subscribe(constants.EVENT.START_HEART, self.start_heart)
+        EventMesh.subscribe(constants.EVENT.STOP_BLOOD_OXYGEN, self.stop_blood_oxygen)
+        EventMesh.subscribe(constants.EVENT.STOP_HEART, self.stop_heart)
+        EventMesh.subscribe(constants.EVENT.GET_BLOOD_OXYGEN, self.get_blood_oxygen)
+        EventMesh.subscribe(constants.EVENT.GET_HEART, self.get_heart)
+
         print("post_processor_after_instantiation:2")
         self.timer_push_schedule.start(10000, 1, self.publish_event)
         # self.battery_push_schedule.start(3000, 1, self.__check_battery)
@@ -663,7 +666,7 @@ class DeviceInfoManager(Abstract):
         :return: HH:MM 格式
         """
         rtc_time = self.rtc.datetime()
-        print("rtc_time:{}".format(rtc_time))
+        #print("rtc_time:{}".format(rtc_time))
         date = ("%d月%d日" % (rtc_time[1], rtc_time[2]))
         year = ("%04d年" % (rtc_time[0]))
         week = ("星期%s"%(self.get_week(rtc_time[3])))
@@ -806,28 +809,28 @@ class DeviceInfoManager(Abstract):
     def start_blood_oxygen(self, topic, msg):
         print("start_blood_oxygen!!!")
         self.hsensor.open_blood_oxygen()
-        self.hsensor_time.start(1000, 1, self.hsensor_time_cb)
-        self.hsensor_time_count = 0
 
     def start_heart(self, topic, msg):
         print("start_heart!!!")
         self.hsensor.open_heart()
-        self.hsensor_time.start(1000, 1, self.hsensor_time_cb)
-        self.hsensor_time_count = 0
 
-    def hsensor_time_cb(self, *args, **kwargs):
-        #data 心律、血氧、高压、低压、HRV、佩戴状态
+    def stop_blood_oxygen(self, topic, msg):
+        print("stop_blood_oxygen!!!")
+        self.hsensor.close()
+
+    def stop_heart(self, topic, msg):
+        print("stop_heart!!!")
+        self.hsensor.close()
+
+    def get_blood_oxygen(self, topic, msg):
         data = self.hsensor.get_all_data()
-        self.hsensor_time_count += 1
-        print("hsensor_time_cb:",str(data))
-        if (data[0] != 0 and self.hsensor_time_count > 35) or self.hsensor_time_count > 45:
-            self.hsensor.close()
-            self.hsensor_time.stop()
-            EventMesh.publish(constants.EVENT.PUSH_HEART,[str(data[0]),str(data[2]),str(data[3])])
-        if (data[1] != 0 and self.hsensor_time_count > 35) or self.hsensor_time_count > 45:
-            self.hsensor.close()
-            self.hsensor_time.stop()
-            EventMesh.publish(constants.EVENT.PUSHT_BLOOD_OXYGEN,str(data[1]))
+        return data[1]
+
+    def get_heart(self, topic, msg):
+        data = self.hsensor.get_all_data()
+        return data[0]
+
+ 
             
 
     def sim_slot_get(self, topic=None, msg=None):
index 9e94bcd..19653b4 100644 (file)
@@ -2452,62 +2452,52 @@ class Spo2Screen(Screen):
         self.meta = spo2_screen
         self.timer = osTimer()
         self.point = 0
-        self.old_spo2_value = 0
         self.spo2_value = 0
 
+
+
     def post_processor_after_initialization(self):
         self.point = 0
         self.spo2_value = 0
         self.timer.start(1*1000, 1, self.start_measure)
+        EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)
 
     def start_measure(self,*args):
         self.point = self.point + 1
-        if self.point == 1:
-            self.spo2_value = 96
-            spo2_label.set_text("96 %")
-            spo2_label_1.set_text("测量中")
-
-        if self.point == 2:
-            self.spo2_value = 97
-            spo2_label.set_text("97 %")
-            spo2_label_1.set_text("测量中")
-
-        if self.point == 3:
-            self.spo2_value = 98
-            spo2_label.set_text("98 %")
-            spo2_label_1.set_text("测量中")
-
-        if self.point == 4:
-            self.spo2_value = 99
-            spo2_label.set_text("99 %")
+        EventMesh.publish("system_sleep_rest")#防止黑屏
+        #if self.point == 1:
+        self.spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+        spo2_label.set_text("{} %".format(self.spo2_value))
+        if self.point%4 == 0 :
+            spo2_label_1.set_text("测量中.")
+        if self.point%4 == 1 :
+            spo2_label_1.set_text("测量中..")
+        if self.point%4 == 2 :
+            spo2_label_1.set_text("测量中...")
+        if self.point%4 == 3 :
+            spo2_label_1.set_text("测量中....")
+
+        if self.point > 60: #测20s
+            self.spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+            spo2_label.set_text("{} %".format(self.spo2_value))
             spo2_label_1.set_text("测量完成")
             self.timer.stop()
             self.point = 0
-            self.old_spo2_value = self.spo2_value
-            time = EventMesh.publish("screen_get_time")#获取系统时间
+            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+            # spo2_last_time.set_text()
 
-            # result = [time, time_quantum, date , week,year]
-            
-            time_tmp = "{}:{}".format("%02d"%(time[0][0]),"%02d"%(time[0][1]))#时间
-            date_year = time[4]#年份
-            date_month = time[2]#日期 04月05日
-            print("date_year:{} date_month:{} time_tmp:{}".format(date_year,date_month,time_tmp))
-            spo2_last_time.set_text(str(date_year)+str(date_month)+" {}".format(str(time_tmp)))
-            spo2_last_value.set_text(str(self.old_spo2_value)+'%')
-            
-    def done_return(self):
+    def Close(self):
         self.timer.stop()
+        EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+
+    def done_return(self):
         EventMesh.publish("load_screen", {"screen": "main_menu"})
 
     def btn1_release(self):
         EventMesh.publish("load_screen", {"screen": "watchface"})
-        self.timer.stop()
         
     def btn8_press(self):
         EventMesh.publish("load_screen", {"screen": "watchface"})
-        self.timer.stop()
-
-
 
 class CountdownScreen(Screen):
     NAME = "countdown"
@@ -2909,11 +2899,15 @@ class UI(object):
 
         EventMesh.subscribe(constants.EVENT.SYSTEM_SLEEP, self.system_sleep)
         EventMesh.subscribe(constants.EVENT.SYSTEM_UP, self.system_up)
+        EventMesh.subscribe("system_sleep_rest", self.system_sleep_rest)
         self.system_sleep_timer.start(1000, 1, self.system_sleep_timer_cb)
 
         for screen in self.screen_list:
             screen.post_processor_after_instantiation()
 
+    def system_sleep_rest(self, event, key):
+        self.system_sleep_timeout_rest()
+
     def ui_press(self, event, key):
         self.system_sleep_timeout_rest()
         print("ui press {}".format(event))
@@ -2977,7 +2971,7 @@ class UI(object):
         EventMesh.publish("load_screen", {"screen": "dialing", "meta": msg})
 
     def __lcd_off(self):
-        print("__lcd_off")
+        #print("__lcd_off")
         if self.sleep_flag == 1 :
             self.sleep_flag = 0
             gpio_backlight.write(0)