const int32_t hrv_ir_wear_thres = 6000;
//SPO2_INFRARED_THRES
const uint8_t spo2_check_unwear_oft = 4;
-const int32_t spo2_ir_wear_thres = 12000;
+const int32_t spo2_ir_wear_thres = 20000;
//CHECK_WEAR_MODE_THRES
const int32_t check_mode_unwear_thre = 5000;
const int32_t check_mode_wear_thre = 6000;
//const int32_t check_mode_sar_thre = 6000;
-
+int32_t sar_wear_thres = NORMALWEARDIFF/3; // 可设定为正常的1/3, 必须小于32767
+int32_t sar_unwear_thres = NORMALWEARDIFF/30*8; // 可设定为 sar_wear_thres *0.8
uint8_t alg_ram[11 * 1024] __attribute__((aligned(4)));
ppg_sensor_data_t ppg_s_dat;
hx3918_agc_Int_handle();
#endif
+#ifdef SAR_ALG_LIB
+ hx3918_report_prox_status();
+#endif
switch(work_mode_flag)
{
case HRS_MODE:
//#define HRV_ALG_LIB
#define CHECK_TOUCH_LIB
//#define CHECK_LIVING_LIB
+#define SAR_ALG_LIB
#define BP_CUSTDOWN_ALG_LIB
extern uint8_t alg_ram[11*1024];
extern uint8_t hx3918_chip_id;
+extern int32_t sar_wear_thres;
+extern int32_t sar_unwear_thres;
extern WORK_MODE_T work_mode_flag;
factory_result_t factory_reslts = {0,0,0};
factory_result_t hx3918_factroy_test(uint32_t test_mode)
{
-
+ factory_result_t factory_reslts = {0,0,0};
int32_t green_buffer[4] = {0,0,0,0};
int32_t red_buffer[4] = {0,0,0,0};
int32_t ir_buffer[4] = {0,0,0,0};
#include "hx3918.h"
#include "hx3918_hrs_agc.h"
#include "tyhx_hrs_alg.h"
+#ifdef SAR_ALG_LIB
#include "hx3918_prox.h"
+#endif
#ifdef HRS_ALG_LIB
extern const int32_t hrs_ir_unwear_thres;
extern const int32_t hrs_ir_wear_thres;
-extern const int32_t sar_unwear_thres;
-extern const int32_t sar_wear_thres;
static uint8_t s_ppg_state = 0;
static uint8_t s_cal_state = 0;
hx3918_hrs_wear_msg_code_t hx3918_hrs_wear_mode_check(int32_t infrared_data)
{
int32_t check_thre = 0;
+ int16_t sar_data = 32767;
+#ifdef SAR_ALG_LIB
+ sar_data = hx90xx_get_prox_data();
+#endif
if(hrs_wear_status == MSG_HRS_NO_WEAR)
{
check_thre = hrs_ir_wear_thres;
check_thre = hrs_ir_unwear_thres;
}
- if(infrared_data < check_thre)
+ if(infrared_data < check_thre || sar_data < sar_unwear_thres)
{
if(no_touch_cnt < NO_TOUCH_CHECK_NUM)
{
hrs_wear_status = MSG_HRS_NO_WEAR;
}
}
- else if(infrared_data >= check_thre)
+ else if(infrared_data >= check_thre && sar_data > sar_wear_thres)
{
if(no_touch_cnt>0)
{
//AGC_LOG("hrs wearstates: hrs_wear_status_pre=%d,hrs_wear_status=%d\r\n",\
//hrs_wear_status_pre,hrs_wear_status);
- hrs_wear_status = hx3918_get_wear_result(hrs_wear_status);
- HX3918_LOG("[hx3918_hrs_wear_mode_check end] final result = %d\r\n",hrs_wear_status);
+ //hrs_wear_status = hx3918_get_wear_result(hrs_wear_status);
+ //HX3918_LOG("[hx3918_hrs_wear_mode_check end] final result = %d\r\n",hrs_wear_status);
if(hrs_wear_status_pre != hrs_wear_status)
{
hrs_wear_status_pre = hrs_wear_status;
hx3918_hrs_set_mode(CAL_INIT);
}
}
- return hrs_wear_status;
+ return hrs_wear_status;
}
/*
hx3918_delay(5);
hx3918_write_reg(0X4d, 0X00); //release
hx3918_delay(5); //Delay for reset time
- hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+ hx3918_prox_reg_init();
+#endif
read_fifo_first_flg = 1;
}
hx3918_delay(5);
hx3918_write_reg(0x4d, 0x00); //release
hx3918_delay(5);
-
calReg.led_cur = 0;
- hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+ hx3918_prox_reg_init();
+#endif
read_fifo_first_flg = 1;
AGC_LOG(" chip go to low power mode \r\n" );
//DEBUG_PRINTF("%d/%d %d %d\r\n",1+i,data_count,PPG_buf[i],ir_buf[i]);
}
TYHX_LOG("\r\n");
-
+
+ #ifdef SAR_ALG_LIB
+ if (hrs_wear_status == MSG_HRS_NO_WEAR)
+ {
+ hx3918_cali_with_ir(Ir_src_data, hrs_ir_unwear_thres);
+ }
+ #endif
+
if (ps_green_data<100000 || ps_green_data>400000)
{
recal = true;
#include "hx3918_hrs_agc.h"
#include "hx3918_hrv_agc.h"
#include "tyhx_hrv_alg.h"
+#ifdef SAR_ALG_LIB
#include "hx3918_prox.h"
+#endif
//#ifdef TYHX_DEMO
//#include "twi_master.h"
//#include "SEGGER_RTT.h"
hx3918_delay(5);
hx3918_write_reg(0X4d, 0X00); //release
hx3918_delay(5);
- hx3918_prox_init();
+ //hx3918_prox_init();
read_fifo_first_flg = 1;
}
hx3918_hrv_wear_msg_code_t hx3918_hrv_wear_mode_check(int32_t infrared_data)
{
- if(infrared_data > hrv_ir_wear_thres)
+ int16_t sar_data = 32767;
+#ifdef SAR_ALG_LIB
+ sar_data = hx90xx_get_prox_data();
+#endif
+ if(infrared_data > hrv_ir_wear_thres && sar_data > sar_wear_thres)
{
if(no_touch_cnt < NO_TOUCH_CHECK_NUM)
{
hrv_wear_status = MSG_HRV_WEAR;
}
}
- else if(infrared_data < hrv_ir_unwear_thres)
+ else if(infrared_data < hrv_ir_unwear_thres || sar_data < sar_unwear_thres)
{
if(no_touch_cnt>0)
{
{
hrv_wear_status_pre = hrv_wear_status;
//TYHX_LOG("[hx3918_hrv_wear_mode_check start] ir wear result = %d\r\n",hrv_wear_status);
- hrv_wear_status = hx3918_get_wear_result(hrv_wear_status);
- TYHX_LOG("[hx3918_hrv_wear_mode_check end] final result = %d\r\n",hrv_wear_status);
+ //hrv_wear_status = hx3918_get_wear_result(hrv_wear_status);
+ //TYHX_LOG("[hx3918_hrv_wear_mode_check end] final result = %d\r\n",hrv_wear_status);
if(hrv_wear_status_pre == MSG_HRV_NO_WEAR)
{
hx3918_hrv_low_power();
hx3918_delay(5);
hx3918_write_reg(0X4d, 0X00); //release
hx3918_delay(5); //Delay for reset time
- hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+ hx3918_prox_reg_init();
+#endif
read_fifo_first_flg = 1;
}
hx3918_write_reg(0X4d, 0X00); //release
hx3918_delay(5);
calReg.led_cur = 0;
- hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+ hx3918_prox_reg_init();
+#endif
// hx3918_ppg_timer_cfg(false);
// hx3918_agc_timer_cfg(false);
// hx3918_gpioint_cfg(true);
PPG部分没有同时被初始化, 所以读到的hx3918_chip_id = 0, 那这里就是会加上芯片的上下电控制
6. 注意CSx和CHx, CSx是指外部PAD接到芯片的对应CS管脚. CH是指内部采集数据的3个通道, CSx可配置在不同的CH上;
-------------------------------- -------------------------------- -----------------------------------*/
-#define ANALOG_DIFF //模拟差分, 一般用这种模式
-//#define DIGITAL_DIFF //数字差分
-#ifdef ANALOG_DIFF
+#ifdef SAR_ALG_LIB
+//#define TEMP_COMPENSATION
+
//#define INDEPENDDENT_CH // 独立通道宏定义, 就是一个PAD对应一个CH
#define DIFFERENCE_CH //差分通道定义, 两个PAD作为一个CH的差分正端和负端, 挨着胳膊的佩戴为正端
-#endif
+
//#define HRS_VDD_ALWAYS_ON //HRS 模块长供电
int16_t nv_wear_offset[2] = {0}; // 芯片产测校准的两个通道的OFFSET值, 值记录在fash里面
int16_t nv_base_data[2] = {0}; // 芯片产测校准的两个通道的对空LP值, 值记录在flash里面
//extern uint16_t sendcnt; // 蓝牙数据采集计数, 这个是采数用的, 可以不用
-int16_t gdiff[2] = {0}; // gdiff[0], gdiff[1] 分别保存CH0, CH1的结果
-int16_t lp[2] = {0};
-int16_t bl[2] = {0};
+int16_t gdiff[2] = {0}; // gdiff[0], gdiff[1] 分别保存WEAR_CH, REF_CH的结果
+int16_t glp[2] = {0};
+int16_t gbl[2] = {0};
//flash 读写变量, 依次记录nv_wear_offset[0],nv_wear_offset[1],nv_base_data[0],nv_base_data[1]
-int16_t fds_read[4] = {0}; //读出flash 存储数据的变量;
-int16_t fds_write[4] = {0}; //写flash的变量, flash里面分别记录
-
+uint32_t fds_read[4] = {0}; //读出flash 存储数据的变量;
+uint32_t fds_write[4] = {0}; //写flash的变量, flash里面分别记录
+uint8_t data_updata_ready = 0;
uint8_t is_factory_mode = 0; // 产测模式, 用来读取整机对空时OFFSET和对空的nv_base值;
-uint8_t wear_detect_mode = NORMAL_WEAR_MODE;
-
-
-
-
-/**
- * set touch detect mode
- * @param current_mode 设置的工作模式
- */
-void hx_set_wear_detect_mode(uint8_t current_mode)
-{
- if(current_mode>SLEEP_WEAR_MODE)
- {
- TYHX_LOG("wear mode set fail , exceed the limit\r\n");
- return;
- }
- wear_detect_mode = current_mode;
+uint8_t is_offset_manual = 0; // = 0自动校准模式, 用来读取整机对空时OFFSET和对空的nv_base值;
+static bool cap_wear = false;
+static bool cap_enable = false;
-}
/**
uint8_t val_h = 0;
uint8_t val_m= 0;
int32_t data = 0;
+ hx3918_write_reg(0x35,0x08); // man lock
val_l = hx3918_read_reg(addl-1);
val_m = hx3918_read_reg(addl);
val_h = hx3918_read_reg(addh);
+ hx3918_write_reg(0x35,0x00); // unlock
data =((val_l>>4) | (val_m<<4)|((val_h & 0x0f) << 12)) ;
if (data > 32767)
return (int16_t)(data - 65536);
*/
void hx3918_config_thres(uint8_t chx,int16_t high_thres, int16_t low_thres, int16_t base_data)
{
-
- if ((low_thres + base_data) <= 0)
+
+ //TYHX_LOG("[config_thres]CHX = %d, high thres =%d, low_thres=%d, base_data=%d\r\n",chx,high_thres,low_thres,base_data);
+ //if ((low_thres + base_data) <= 0)
{
- return;
+ // return;
}
+ //TYHX_LOG("[config_thres]CHX = %d, high thres =%d, low_thres=%d\r\n",chx,high_thres,low_thres);
int16_t thres = 0;
- thres = (high_thres + base_data)/32;
+
+
+ thres = (high_thres + base_data)/32;
+ if(thres<0)
+ {
+ thres = 0;
+ }
+
+ TYHX_LOG("[config_thres]CHX = %d, high thres =%d\r\n",chx,thres);
hx3918_write_reg(0x9D+1*chx, (thres&0x00FF));
hx3918_write_reg(0xA0+1*chx, (thres&0xFF00)>>8);
+
thres = (low_thres + base_data)/32;
+ if(thres<0)
+ {
+ thres = 0;
+ }
+
+ TYHX_LOG("[config_thres]CHX = %d,low_thres=%d\r\n",chx,thres);
hx3918_write_reg(0xA5+1*chx, (thres&0x00FF));
hx3918_write_reg(0xA8+1*chx, (thres&0xFF00)>>8);
}
bool hx3918_prox_reg_init(void)
{
bool write_ok = true;
-
-#ifdef ANALOG_DIFF
- if (hx3918_chip_id != PROX_CHIPID)
- {
- TYHX_LOG("100hz\r\n");
- write_ok &= hx3918_write_reg(0x18,0x40); //prf =100HZ
- write_ok &= hx3918_write_reg(0x19,0x01); //
- }
+ data_updata_ready = 0;
+//prf 默认25HZ
+// if (hx3918_chip_id != PROX_CHIPID)
+// {
+// TYHX_LOG("100hz\r\n");
+// write_ok &= hx3918_write_reg(0x18,0x00); //prf =100HZ
+// write_ok &= hx3918_write_reg(0x19,0x05); //
+// }
write_ok &= hx3918_write_reg(0x6a,0x00); //CH0~N disable
- write_ok &= hx3918_write_reg(0x51,0x00); //default??
- write_ok &= hx3918_write_reg(0x52,0x02); //default??
- write_ok &= hx3918_write_reg(0x53,0x00); //default??
+// write_ok &= hx3918_write_reg(0x51,0x00); //default
+// write_ok &= hx3918_write_reg(0x52,0x02); //default
+// write_ok &= hx3918_write_reg(0x53,0x00); //default
#ifdef INDEPENDDENT_CH //
-// write_ok &= hx3918_write_reg(0x55,0x0C); //CS1->CH0
- write_ok &= hx3918_write_reg(0x55,0x03); //CS0->CH0
+ write_ok &= hx3918_write_reg(0x55,0x0C); //CS1->CH0
+ write_ok &= hx3918_write_reg(0x55,0x03); //CS0->CH0
// write_ok &= hx3918_write_reg(0x57,0x30); //CS2->CH1
#elif defined(DIFFERENCE_CH) //?????????????¨, ???????·??
// write_ok &= hx3918_write_reg(0x55,0x2c); //CS1->CH0[P],CS2->CH0[N]
// write_ok &= hx3918_write_reg(0x55,0x0e); //CS1->CH0[P],CS0->CH0[N]
- write_ok &= hx3918_write_reg(0x55,0x0B); //CS0->CH0[P],CS1->CH0[N]
+ write_ok &= hx3918_write_reg(0x55,0x0c); //CS0->CH0[P],CS1->CH0[N]
// write_ok &= hx3918_write_reg(0x57,0x30); //CS2->CH1
// write_ok &= hx3918_write_reg(0x57,0x03); //CS0->CH1
- write_ok &= hx3918_write_reg(0x57,0x0c); //CS1->CH1
+ write_ok &= hx3918_write_reg(0x57,0x0b); //CS1->CH1
#endif
- write_ok &= hx3918_write_reg(0x56,0x00); //default
- write_ok &= hx3918_write_reg(0x58,0x00); //default
- write_ok &= hx3918_write_reg(0x59,0x00); //CH2
- write_ok &= hx3918_write_reg(0x5A,0x00); //CH2
+ write_ok &= hx3918_write_reg(0x59,0x0c); //CH2 CS1
+
#ifdef FULL25PF
write_ok &= hx3918_write_reg(0x5B,0x11); //full range = 2.5pf 0x11=2.5pf 0x22 = 3.75pf, 0x33 = 5pf
+#elif defined(FULL125PF)
+ write_ok &= hx3918_write_reg(0x5B,0x00); //full range 0x00 = 1.25pf
#elif defined(FULL375PF)
write_ok &= hx3918_write_reg(0x5B,0x22); //full range = 2.5pf 0x11=2.5pf 0x22 = 3.75pf, 0x33 = 5pf
#elif defined(FULL50PF)
write_ok &= hx3918_write_reg(0x5B,0x33); //full range = 2.5pf 0x11=2.5pf 0x22 = 3.75pf, 0x33 = 5pf
#endif
write_ok &= hx3918_write_reg(0x5D,0x25); //OSR AVG
- write_ok &= hx3918_write_reg(0x5E,0x11); //OSR AVG
- write_ok &= hx3918_write_reg(0x5F,0x01); //OSR AVG
+ write_ok &= hx3918_write_reg(0x5E,0x22); //OSR nosr1_num_i2c nosr2_num_i2c
+ write_ok &= hx3918_write_reg(0x5F,0x11); //AVG ch1_avg_num_i2c ch2_avg_num_i2c
write_ok &= hx3918_write_reg(0x66,0x08); //采样时间
write_ok &= hx3918_write_reg(0x67,0x00); //
write_ok &= hx3918_write_reg(0x6E,0x11); //LP alpha
write_ok &= hx3918_write_reg(0x77,0x70); //output 选择LP和BL
- write_ok &= hx3918_write_reg(0x7A,0x07); //补偿电容校准触发设置=16384
-
-
- if(is_factory_mode)
+ //write_ok &= hx3918_write_reg(0x99,0x40); // ch0 coe 增益配置
+ //write_ok &= hx3918_write_reg(0x9A,0x40); // ch1 coe 增益配置
+ //write_ok &= hx3918_write_reg(0x94,0x02); // diff_en_ch01
+
+
+ if(is_offset_manual == 0)
{
- TYHX_LOG("is_factory_mode\r\n");
+ TYHX_LOG("is_offset_manual = 0\r\n");
- write_ok &= hx3918_write_reg(0x70,0x66);
- write_ok &= hx3918_write_reg(0x72,0x20);
- write_ok &= hx3918_write_reg(0x73,0x04);
- write_ok &= hx3918_write_reg(0x90,0x77);
- write_ok &= hx3918_write_reg(0x8F,0x00);
+ write_ok &= hx3918_write_reg(0x90,(0x1<<WEAR_CH)); //ch1=P+ ch0=N-
+ write_ok &= hx3918_write_reg(0x8F,0x00);//00
write_ok &= hx3918_write_reg(0x95,0x00);
- hx3918_config_thres(CH0,CH0_HIGH_DIFF, CH0_LOW_DIFF,0); // wear0
- hx3918_config_thres(CH1,CH1_HIGH_DIFF, CH1_LOW_DIFF,0); // wear0
-
+ hx3918_config_thres(WEAR_CH,sar_wear_thres, sar_unwear_thres,0); //
+ hx3918_config_thres(REF_CH,REF_HIGH_DIFF, REF_LOW_DIFF,0); //
+
}
else
{
- write_ok &= hx3918_write_reg(0x70,0x66);
- write_ok &= hx3918_write_reg(0x72,0x20);
- write_ok &= hx3918_write_reg(0x73,0x02);
- write_ok &= hx3918_write_reg(0x90,0x77);//0x07
- write_ok &= hx3918_write_reg(0x8F,0x07);
- write_ok &= hx3918_write_reg(0x95,0x00);//0x0a
- hx3918_write_offset(nv_wear_offset[0], CH0_OFFSET);
- hx3918_write_offset(nv_wear_offset[1], CH1_OFFSET);
- hx3918_config_thres(CH0,CH0_HIGH_DIFF, CH0_LOW_DIFF,nv_base_data[0]); // wear0
- hx3918_config_thres(CH1,CH1_HIGH_DIFF, CH1_LOW_DIFF,nv_base_data[1]); // wear0
- hx3918_write_reg(0x7A,0x17);
- HX3918_LOG("hx3918_prox_reg_init:nv_base_data:%d %d!!!!!!!!!!!!!!!!!!!!!!!!\n",nv_base_data[0],nv_base_data[1]);
+
+ write_ok &= hx3918_write_reg(0x90,(0x1<<WEAR_CH));////ch1=P+ ch0=N-
+ write_ok &= hx3918_write_reg(0x8F,(0x1<<WEAR_CH)); // ch1 offset_dac_en
+ write_ok &= hx3918_write_reg(0x95,0x00);//0xaa
+ hx3918_write_offset(nv_wear_offset[0], WEAR_CH);
+ //hx3918_write_offset(nv_wear_offset[1], REF_CH);
+ hx3918_config_thres(WEAR_CH,sar_wear_thres, sar_unwear_thres,0); // wear0
+ hx3918_config_thres(REF_CH,REF_HIGH_DIFF, REF_LOW_DIFF,0);
+
+ //write_ok &= hx3918_write_reg(0x7A,0x07|(0x10<<WEAR_CH)); // 打开转换中断
+ write_ok &= hx3918_write_reg(0x9c,0x00); // lp_out_delta_bypass
+ write_ok &= hx3918_write_reg(0x85,0x0f); // prox_int_high_num_i2c
+ write_ok &= hx3918_write_reg(0xa3,0xff); //lp_out_delta_thres_ch1[7:0]
+ write_ok &= hx3918_write_reg(0xa4,0x0f); // lp_out_delta_thres_ch1[11:8]
+ write_ok &= hx3918_write_reg(0x70,0x11); // RA_UP_ALP_1_0_CFG
+ //write_ok &= hx3918_write_reg(0x71,0x11); //
+ //write_ok &= hx3918_write_reg(0x72,0x11); //
+ //write_ok &= hx3918_write_reg(0x73,0x11); //
+
}
-
- write_ok &= hx3918_write_reg(0x6a,0x03); //CH0, CH1 enable
-#endif
- hx3918_delay(50);
+ write_ok &= hx3918_write_reg(0x6a,0x03); //CH0, CH1 enable
+ // hx3918_delay(50);
return write_ok;
}
//蓝牙发送数据给APP
//extern uint32_t sendDataToClient(int16_t sendnum1,int16_t sendnum2,int16_t sendnum3,int16_t sendnum4);
+void hx3918_timerout_cb(void)
+{
+}
/**
* hx3918 获取靠近感应的结果,结果=0, prox感应的结果为非佩戴, =1 佩戴
* @param NULL
*/
extern char is_open_sar ; //是否打开sar检测
+static int hx3918_timer = 0;
uint8_t hx3918_report_prox_status(void)
{
- static int16_t lp_old[2] = {0};
- static int16_t bl_old[2] = {0};
static uint8_t cap_wear_flag = 0;
- uint8_t ret = 0;
+ static int hx3918_report_prox_timer = 0;
if(is_open_sar == 0)
- return 1;
- lp[0] = hx3918_read_diff_lp(LP0);
- bl[0] = hx3918_read_raw_bl(BL0);
-
- lp[1] = hx3918_read_diff_lp(LP1);
- bl[1] = hx3918_read_raw_bl(BL1);
-
-
- gdiff[0] = lp[0]- bl[0];
- gdiff[1] = lp[1]- bl[1];
-
-
- HX3918_LOG("result = %d %d %d %d %d %d\r\n",lp[0],bl[0],lp[1],bl[1],gdiff[0],gdiff[1]);
- // if(gdiff[0]>100)
- // ret = 1;
- // else
- // {
- // if((lp_old[0] - lp[0]) > 40)
- // ret = 0;
- // else
- // {
- // if(lp[0]>3300)
- // ret = 1;
- // else
- // ret = 0;
- // }
-
- // }
- // lp_old[0] = lp[0];
- // lp_old[1] = lp[1];
- // bl_old[0] = bl[0];
- // bl_old[1] = bl[1];
- // return ret;
-#ifdef TEMP_COMPENSATION //温度补偿
- //这个是应对高温环境要求, 不用打开, 要看看具体情况,
- if(gdiff[1]>20000)
- {
- gdiff[0] = gdiff[0]*0.9; // 如果随着高温,感应值上升,为0.9, 感应值下降改为1.1
- }
-#endif
- if(gdiff[0]<WEARTHRES)// WEARTHRES=3500/2
+ return 1;
+ if(hx3918_timer== 0)
{
- if((gdiff[0]>=SLEEPWEARTHRES)&&(wear_detect_mode == SLEEP_WEAR_MODE ))//SLEEPWEARTHRES=9000*0.3
- {
- ret = prox_detect;
- }
- ret = prox_no_detect;
- }
- else
- {
- ret = prox_detect;
+ hx3918_timer = Helios_Timer_init( (void* )hx3918_timerout_cb, NULL);
+ Helios_Timer_Start(hx3918_timer, 1500, 1);
}
- if(ret == 1) //检测到已佩戴,置标志
- cap_wear_flag = 1;
- if(cap_wear_flag != 1)//没有检测过已佩戴,统一置为已佩戴
- ret = 1;
- return ret;
+ uint8_t ret = 0;
+
+ glp[0] = hx3918_read_diff_lp(WEAR_CH);
+ gbl[0] = hx3918_read_raw_bl(WEAR_CH);
+
+ glp[1] = hx3918_read_diff_lp(REF_CH);
+ gbl[1] = hx3918_read_raw_bl(REF_CH);
+
+ if ((glp[0] == 0) && (gbl[0] == 0)) // agc 调节时出现
+ {
+ data_updata_ready = 0;
+ }
+
+ if (data_updata_ready == 1&& (glp[0] != gbl[0]))
+ {
+ if (is_offset_manual == 0)
+ {
+ gdiff[0] = glp[0]- gbl[0];
+ }
+ else
+ {
+ gdiff[0] = glp[0]- nv_base_data[0];
+ }
+ gdiff[1] = glp[1]- gbl[1];
+
+ hx3918_update_min_nv_data(gbl[0]);
+ }
+
+ if ((glp[0] == gbl[0]) && (glp[0] != 0) && is_offset_manual ==1)
+ {
+ if (data_updata_ready == 0)
+ {
+ // 恢复寄存器
+ hx3918_write_reg(0x9c,0x07); // lp_out_delta_bypass
+ //hx3918_write_reg(0x85,0x0f); // prox_int_high_num_i2c
+ //hx3918_write_reg(0xa3,0xff); //lp_out_delta_thres_ch1[7:0]
+ //hx3918_write_reg(0xa4,0x0f); // lp_out_delta_thres_ch1[11:8]
+ hx3918_write_reg(0x70,0x99); // RA_UP_ALP_1_0_CFG
+ data_updata_ready = 1;
+ TYHX_LOG("data_updata_ready == 1\r\n");
+ }
+ }
+ if(gdiff[0]>sar_wear_thres)
+ ret = 1;
+ else
+ ret = 0;
+ if(ret == 1)//
+ cap_wear_flag = 1;
+ if(cap_wear_flag == 0)
+ ret = 0;
+ TYHX_LOG("SARresult ready: %d, lp,%d,%d, bl,%d,%d, giff, %d,%d, offset, %d, nv_data,%d\r\n",data_updata_ready, glp[0],glp[1], gbl[0],gbl[1],gdiff[0],gdiff[1], nv_wear_offset[0],nv_base_data[0]);
+ return ret;
+}
+
+
+int32_t hx90xx_get_prox_data(void)
+{
+ if (data_updata_ready == 1)
+ {
+ // 异常处理
+ if (nv_base_data[0] <-16384|| nv_base_data[0] > 25000 || hx3918_chip_id != PROX_CHIPID ||is_open_sar == 0)
+ {
+ gdiff[0] = 32767;
+ }
+ }
+
+ if (is_offset_manual == 0)
+ {
+ gdiff[0] = 32767;
+ }
+ //DEBUG_PRINTF("gdiff[0]: %d \r\n", gdiff[0]);
+
+ return gdiff[0];
+}
+
+ //红外值很小时校准
+void hx3918_cali_with_ir(int32_t infrared_data, int32_t ir_thres)
+{
+ //设定 对空红外值 校准
+ int32_t unwear_infrared_data = ir_thres/4;
+ if (data_updata_ready == 1)
+ {
+ if (infrared_data < unwear_infrared_data)
+ {
+ if ((gdiff[0] > sar_unwear_thres/4)&& (gdiff[0] < sar_unwear_thres))
+ {
+ nv_base_data[0] = gbl[0];
+ }
+ }
+ }
+ DEBUG_PRINTF("infrared_data: %d , unwear_infrared_data %d, sar_unwear_thres: %d,gdiff[0],%d\r\n", infrared_data, unwear_infrared_data,sar_unwear_thres,gdiff[0]);
+}
+
+
+//更新最小值
+void hx3918_update_min_nv_data(int16_t min_data)
+{
+ uint8_t nv_change_flag = 0;
+ if (is_offset_manual == 1&&data_updata_ready == 1)
+ {
+ // 取得最小信号量值
+ if(min_data < nv_base_data[0]-50)
+ {
+ nv_base_data[0] = min_data;
+ nv_change_flag = 1;
+
+ }
+
+ if (nv_change_flag == 1)
+ {
+// hx90xx_config_thres(CH0,ch0_high_diff, ch0_low_diff,nv_base_data[0]); // wear0
+// hx90xx_config_thres(CH1,ch1_high_diff, ch1_low_diff,nv_base_data[1]); // wear1
+ DEBUG_PRINTF("90XX update_min_nv_data nv_base_data0: %d,\r\n", nv_base_data[0]);
+ }
+ }
+}
+
+
+// 在充电状态下调用, 每次充电只调用一次
+void hx3918_update_nv_data()
+{
+ int16_t min_data0 = {0};
+ uint8_t nv_change_flag = 0;
+
+ glp[0] = hx3918_read_diff_lp(WEAR_CH);
+ min_data0 = hx3918_read_raw_bl(WEAR_CH);
+
+ if (is_offset_manual == 1)
+ {
+ //nv_wear_offset[0] = hx3918_read_offset(CH0_OFFSET);
+ // 取得对空信号值
+ if((min_data0 - nv_base_data[0]) > 100 )
+ {
+ nv_base_data[0] = nv_base_data[0] + (min_data0 - nv_base_data[0])/2;
+ nv_change_flag = 1;
+ }
+
+ // 异常处理
+ if (nv_base_data[0] <-16384|| nv_base_data[0] > 20000 || glp[0] > 32000)
+ {
+ hx3918_prox_factory_hanging_cali();
+ return;
+ }
+ if (nv_change_flag == 1)
+ {
+ hx3918_factory_cali_save_nv();
+ }
+ hx3918_prox_init();
+ DEBUG_PRINTF("90XX update_nv_data nv_base_data0: %d, nv_base_data1: %d\r\n", nv_base_data[0], nv_base_data[1]);
+ }
+ else if (is_offset_manual == 0)
+ {
+ hx3918_prox_factory_hanging_cali();
+ DEBUG_PRINTF("is_offset_manual == 0 %d, %d \r\n", nv_base_data[0], nv_wear_offset[0]);
+ }
}
/**
nv_base_data[1] = fds_read[3];
//如果flash记录的值大于上限, 则让靠近感应进入相对值模式
- if(nv_wear_offset[0] > 1020)
+ if ( (nv_wear_offset[0] == 0&& nv_base_data[0] == 0) || nv_wear_offset[0] == 0xFFFF)
{
- nv_wear_offset[0] = 0;
- nv_base_data[0] = 0;
- nv_wear_offset[1] = 0;
- nv_base_data[1] = 0;
+ nv_wear_offset[0] = 0;
+ nv_base_data[0] = 0;
+ nv_wear_offset[1] = 0;
+ nv_base_data[1] = 0;
+ cap_enable = false;
+ is_offset_manual = 0;
}
- TYHX_LOG("[hx3918_read_nv]\r\n");
- TYHX_LOG("OFF[0]: %d, OFF[1]:%d\r\n",nv_wear_offset[0],nv_wear_offset[1]);
- TYHX_LOG("BASE[0]: %d, BASE[1]:%d\r\n",nv_base_data[0],nv_base_data[1]);
+ else
+ {
+ is_offset_manual = 1;
+ }
+
+ TYHX_LOG("hx3918_read_nv ,OFF[0]: %d, OFF[1]:%d\r\n",nv_wear_offset[0],nv_wear_offset[1]);
+ TYHX_LOG("BASE[0]: %d, BASE[1]:%d,mode: %d \r\n",nv_base_data[0],nv_base_data[1],is_offset_manual);
#endif
int32_t i = 0;
bool ret = false;
- //sendcnt = 0;
+ cap_wear = false;
TYHX_LOG("[hx3918_prox_init]prox device_id is : 0x%.2x !\r\n", hx3918_chip_id);
if (hx3918_chip_id != PROX_CHIPID)
{
hx3918_power_restart();
//i2c_hrs_init();
- //twi_master_init();
+ // twi_master_init();
hx3918_read_nv();
- hx3918_ppg_on();
- hx3918_prox_reg_init();
+ hx3918_ppg_on();
+
for (i = 0; i<5; i++)
{
hx3918_chip_id = hx3918_check_device_id();
TYHX_LOG(" power restart ,prox device_id is : 0x%.2x !\r\n", hx3918_chip_id);
if (hx3918_chip_id == PROX_CHIPID)
{
+ hx3918_prox_reg_init();
break;
}
}
- if(hx3918_chip_id == 0)
+ if(hx3918_chip_id != PROX_CHIPID)
{
TYHX_LOG("no proximity device\r\n");
//i2c_hrs_uninit();
hx3918_read_nv();
hx3918_prox_reg_init();
}
- hx3918_delay(50);
+ //hx3918_ppg_off();
return ret;
}
hx3918_power_restart();
//i2c_hrs_init();
-
hx3918_ppg_on();
- hx3918_prox_reg_init();
for (i = 0; i<5; i++)
{
hx3918_chip_id = hx3918_check_device_id();
TYHX_LOG(" power restart ,prox device_id is : 0x%.2x !\r\n", hx3918_chip_id);
if (hx3918_chip_id == PROX_CHIPID)
{
+ hx3918_write_reg(0x18,0x40); //prf =100HZ
+ hx3918_write_reg(0x19,0x01); //
+ hx3918_prox_reg_init();
break;
}
}
- if(hx3918_chip_id == 0)
+
+ if(hx3918_chip_id != PROX_CHIPID)
{
TYHX_LOG("no proximity device\r\n");
- //i2c_hrs_uninit();
hx3918_power_down();
}
- hx3918_delay(50);
return ret;
}
+//佩戴数据
+void hx3918_factory_cali_read_data(void)
+{
+ int16_t lp[2] = {0};
+ int16_t bl[3] = {0};
+ int32_t diff[3] = {0};
+
+ lp[0] = hx3918_read_diff_lp(WEAR_CH);
+ bl[0] = hx3918_read_raw_bl(WEAR_CH);
+
+ //lp[1] = hx3918_read_diff_lp(REF_CH);
+ //bl[1] = hx3918_read_raw_bl(REF_CH);
+
+ if (is_offset_manual ==1)
+ {
+ diff[0] = lp[0]- nv_base_data[0];
+ }
+ else
+ {
+ diff[0] = lp[0] - bl[0];
+ }
+
+
+ DEBUG_PRINTF("id: 0x%x,offset0,%%d, lp[0], %d, bl[0], %d, diff[0],%d\r\n", hx3918_chip_id,nv_wear_offset[0],lp[0],bl[0],diff[0]);
+}
+
/**
* hx3918 靠近感应部分 工厂产测程序, 需将手表悬空或者远离其他可能影响电容值的物体.
* @param NULL
// uint16_t offset1 = 0;
// int16_t lp[2] = {0};
//uint8_t device_id = 0x00;
-
- is_factory_mode = 1;
+ is_offset_manual = 0;
hx3918_prox_factory_init();
hx3918_delay(50);//delay 100ms
- prox_factory_offset0 = hx3918_read_offset(CH0_OFFSET);
- prox_factory_offset1 = hx3918_read_offset(CH1_OFFSET);
+ prox_factory_offset0 = hx3918_read_offset(WEAR_CH);
+ prox_factory_offset1 = hx3918_read_offset(REF_CH);
- prox_factory_lp[0] = hx3918_read_diff_lp(LP0);
- prox_factory_lp[1] = hx3918_read_diff_lp(LP1);
+ prox_factory_lp[0] = hx3918_read_diff_lp(WEAR_CH);
+ prox_factory_lp[1] = hx3918_read_diff_lp(REF_CH);
HX3918_LOG("offset0,offset1= %d %d\r\n", prox_factory_offset0,prox_factory_offset1);
#endif
nv_wear_offset[0] = prox_factory_offset0;
nv_wear_offset[1] = prox_factory_offset1;
- nv_base_data[0] = lp[0];
- nv_base_data[1] = lp[1];
- HX3918_LOG("base0,base1= %d %d\r\n", lp[0],lp[1]);
+ nv_base_data[0] = prox_factory_lp[0];
+ nv_base_data[1] = prox_factory_lp[1];
+ HX3918_LOG("base0,base1= %d %d\r\n", glp[0],glp[1]);
#ifdef DIFFERENCE_CH
//将差分数据读到的OFFSET, NV_BASE记录到FLASH里面, 校准存储把自学习的记录也需要清掉重新计算
- if((prox_factory_offset0 == 510) &&(prox_factory_offset1 == 510))
+ if((prox_factory_offset0 == 510) &&(prox_factory_offset1 == 510)&&(prox_factory_lp[0]==0)&&(prox_factory_lp[1]==0))
{
TYHX_LOG("ERR, read offset err, please redo it !!!\r\n");
}
hx3918_factory_cali_save_nv();
}
#endif
- hx3918_ppg_off();
- is_factory_mode = 0;
+
+ hx3918_prox_init();
+ hx3918_delay(1000);//delay 1000ms
}
}
}
}
-
+#endif // SAR_ALG_LIB
#define DIFF1 1
#define DIFF2 2
+// user to config
+#define WEAR_CH CH1
+#define REF_CH CH0
#define hx_min(x,y) ( (x)>(y)?(y):(x) )
#define hx_abs(x) ((x)>0?(x):(-(x)))
-#define RELATIVE_MODE 0 //相对值模式, 检测结果=LP-BL, 无法佩戴着开机时的靠近感应,其他正常
-#define ABSOLUTE_MODE 1 //绝对值模式, 检测结果=LP-NV_BASE 可以佩戴开机
#define PROX_CHIPID 0x27
-#define HX3918_IR_AIR 6000 //小于这个值代表脱腕
-#define NORMALWEARDIFF 7000 //正常佩戴测试到的平均值, 宽松佩戴
-#define WEARTHRES NORMALWEARDIFF/2 //普通佩戴阈值
-#define SLEEPWEARTHRES NORMALWEARDIFF*0.3 //睡眠佩戴阈值
+#define NORMALWEARDIFF 18000 //正常佩戴测试到的平均值, 宽松佩戴
-#define CH0_HIGH_DIFF NORMALWEARDIFF/8
-#define CH0_LOW_DIFF NORMALWEARDIFF/10
-#define CH1_HIGH_DIFF NORMALWEARDIFF/8
-#define CH1_LOW_DIFF NORMALWEARDIFF/10
+#define WEAR_HIGH_DIFF NORMALWEARDIFF/6
+#define WEAR_LOW_DIFF NORMALWEARDIFF/8
+#define REF_HIGH_DIFF NORMALWEARDIFF/6
+#define REF_LOW_DIFF NORMALWEARDIFF/8
//HX3918 cap 测试电容的满量程设置, 最小
//#define FULL0625PF //HX3918 full range cap = 0.625pf //一般不用这个, 这个满量程设置, 说明感应pad很小,
//#define FULL125PF //HX3918 full range cap = 1.25pf
-#define FULL25PF //HX3918 full range cap = 2.5pf, 一般PAD大小默认这个.
-//#define FULL375PF //HX3918 full range cap = 3.75 pf
+//#define FULL25PF //HX3918 full range cap = 2.5pf, 一般PAD大小默认这个.
+#define FULL375PF //HX3918 full range cap = 3.75 pf
//#define FULL50PF //HX3918 full range cap = 5.0 pf
//READ_DEVATION ,read offset 的偏差控制, 一个offset = 0.0586pf 按照不同量程, 对应的code, 留10%余量
#define READ_DEVATION 560
#elif defined(FULL375PF)
#define READ_DEVATION 420
+#elif defined(FULL50PF)
+#define READ_DEVATION 420
#endif
} wear_mode_t;
-
+extern int32_t sar_wear_thres;
+extern int32_t sar_unwear_thres;
extern int16_t gdiff[2];
-extern int16_t lp[2];
-extern int16_t bl[2];
+extern int16_t glp[2];
+extern int16_t gbl[2];
extern int16_t nv_base_data[2];
extern int16_t nv_wear_offset[2];
#define FDSLEN 4 //flash 存储的长度
-extern int16_t fds_read[FDSLEN]; //flash 读
-extern int16_t fds_write[FDSLEN];//flash 写
+extern uint32_t fds_read[FDSLEN]; //flash 读
+extern uint32_t fds_write[FDSLEN];//flash 写
extern uint8_t wear_detect_mode;
bool hx3918_get_wear_result(uint8_t ppg_wear);
bool hx3918_prox_factory_init(void);
void hx_set_wear_detect_mode(uint8_t current_mode);
+int32_t hx90xx_get_prox_data(void);
+void hx3918_cali_with_ir(int32_t infrared_data, int32_t ir_thres);
+void hx3918_update_min_nv_data(int16_t min_data);
#endif
#include "tyhx_spo2_alg.h"
#include "tyhx_hrs_alg.h"
//#include "tyhx_hrs_custom.h"
+#ifdef SAR_ALG_LIB
#include "hx3918_prox.h"
+#endif
+
#ifdef SPO2_ALG_LIB
extern const uint8_t hx3918_spo2_agc_green_idac; // 6,7,8...
extern const uint8_t spo2_check_unwear_oft;
extern const int32_t spo2_ir_wear_thres;
-extern const int32_t sar_unwear_thres;
-extern const int32_t sar_wear_thres;
+
extern uint8_t read_fifo_first_flg;
static uint8_t s_ppg_state = 0;
bool hx3918_spo2_check_unwear(void)
{
- if(calReg.ir_idac < spo2_check_unwear_oft)
+ int16_t sar_data = 32767;
+#ifdef SAR_ALG_LIB
+ sar_data = hx90xx_get_prox_data();
+#endif
+ if(calReg.ir_idac < spo2_check_unwear_oft || sar_data < sar_unwear_thres)
{
spo2_wear_status = MSG_SPO2_NO_WEAR;
if(spo2_wear_status_pre != MSG_SPO2_NO_WEAR)
bool hx3918_spo2_check_wear(int32_t infrared_data)
{
- if(infrared_data > spo2_ir_wear_thres )
+ int16_t sar_data = 32767;
+#ifdef SAR_ALG_LIB
+ sar_data = hx90xx_get_prox_data();
+#endif
+ if(infrared_data > spo2_ir_wear_thres && sar_data > sar_wear_thres)
{
spo2_wear_status = MSG_SPO2_WEAR;
hx3918_delay(5);
hx3918_write_reg(0X4d, 0X00); //release
hx3918_delay(5); //Delay for reset time
- hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+ hx3918_prox_reg_init();
+#endif
read_fifo_first_flg = 1;
}
hx3918_delay(5);
hx3918_write_reg(0X4d, 0X00); //release
hx3918_delay(5);
- hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+ hx3918_prox_reg_init();
+#endif
read_fifo_first_flg = 1;
AGC_LOG(" chip go to low power mode \r\n" );
}
extern int SC7A20_init(void);
extern signed char SL_SC7A20_PEDO_KCAL_WRIST_SLEEP_SWAY_L_ALGO(void);
extern unsigned char Gsensor_init_flag ;
-
+void HX3918_restart(void);
#endif
int ir_wear = 0;//红外佩戴状态
int cap_wear = 1;//电容佩戴状态
HX3918_close();
Helios_msleep(20);
HX3918_jobs_mode = NULL_MODE;
- }
+ }else
+ HX3918_restart();
HX3918_test(HX3918_run_mode);
HX3918_jobs_mode = HX3918_run_mode;
HX3918_run_mode = NULL_MODE;
}
void HX3918_result_set_wear_status(unsigned char wear_status)
{
- s_HX3918_wear_status = wear_status;
+ if(wear_status != 1)
+ s_HX3918_wear_status = 0;
+ else
+ s_HX3918_wear_status = 1;
//HX3918_LOG("s_HX3918_wear_status:%d !!!!!!!!!!!!!!!!!\n\n\n",s_HX3918_wear_status);
}
void HX3918_result_set_blood_oxygen(unsigned char blood_oxygen)
-
void sensor_timerout_cb(void)
{
- timer_Gsensor_count++;
+
+ if(timer_Gsensor_count < 65536)
+ timer_Gsensor_count++;
}
void HX3918_irq_cb(void)
{
}
}
is_open_HX3918 = 0;
- // Helios_GPIO_SetLevel(g_HX3918->power, HELIOS_LVL_LOW);
- // Helios_msleep(15);
- // Helios_GPIO_SetLevel(g_HX3918->power, HELIOS_LVL_HIGH);
- // Helios_msleep(20);
+ HX3918_restart();
hx3918_init(WEAR_MODE);//打开佩戴检测
}
void HX3918_restart(void)
{
Helios_GPIO_SetLevel(g_HX3918->power, HELIOS_LVL_LOW);
- Helios_msleep(150);
+ Helios_msleep(50);
Helios_GPIO_SetLevel(g_HX3918->power, HELIOS_LVL_HIGH);
Helios_msleep(50);
}
}
// ir_wear = hx3918_get_wear_ppg_Int_handle();
// cap_wear = hx3918_report_prox_status();
-//lp[0],bl[0],lp[1],bl[1],gdiff[0]
-extern int16_t lp[2] ;
-extern int16_t bl[2];
-extern int16_t gdiff[2];
+
//获取佩戴状态
STATIC mp_obj_t mp_HX3918_get_wear(mp_obj_t self_in)
{
// extern int16_t prox_factory_lp[2] ;
extern int16_t nv_wear_offset[2] ; // 芯片产测校准的两个通道的OFFSET值, 值记录在fash里面
extern int16_t nv_base_data[2]; // 芯片产测校准的两个通道的对空LP值, 值记录在flash里面
+//lp[0],bl[0],lp[1],bl[1],gdiff[0]
+extern int16_t glp[2] ;
+extern int16_t gbl[2];
+extern int16_t gdiff[2];
STATIC mp_obj_t mp_HX3918_get_test_data(mp_obj_t self_in)
{
mp_obj_t coordinate_list[15] = {mp_obj_new_int((int)factory_reslts.green_data_final),mp_obj_new_int((int)factory_reslts.red_data_final),mp_obj_new_int((int)factory_reslts.ir_data_final),
- mp_obj_new_int((int)ir_wear),mp_obj_new_int((int)cap_wear),mp_obj_new_int((int)lp[0]),mp_obj_new_int((int)bl[0]),mp_obj_new_int((int)lp[1]),mp_obj_new_int((int)bl[1]),
+ mp_obj_new_int((int)ir_wear),mp_obj_new_int((int)cap_wear),mp_obj_new_int((int)glp[0]),mp_obj_new_int((int)gbl[0]),mp_obj_new_int((int)glp[1]),mp_obj_new_int((int)gbl[1]),
mp_obj_new_int((int)(gdiff[0])),mp_obj_new_int((int)(gdiff[1])),mp_obj_new_int((int)nv_wear_offset[0]),mp_obj_new_int((int)nv_wear_offset[1]),mp_obj_new_int((int)nv_base_data[0]),
mp_obj_new_int((int)nv_base_data[1]),
};
def add_filter(flt):
event_store.add_filter(flt)
+Txt_Log = 1
+def txt_log(data):
+ if Txt_Log != 0 :
+ print(data)
+ try:
+ f_stat = uos.stat("ext/log.txt")
+ if f_stat[6] >50*1024:
+ uos.remove("ext/log.txt")
+ except Exception as e:
+ usys.print_exception(e)
+ with open("/ext/log.txt","a",encoding="utf-8") as fd:
+ d_time = utime.localtime()
+ data_tmp = "%02d-%02d %02d:%02d:%02d :"%(d_time[1],d_time[2],d_time[3],d_time[4],d_time[5])
+ fd.write(data_tmp+data+"\n")
def callback_wrapper(callback):#按键回调
def wrapped_callback(*args, **kwargs):
from ui import style_screen,style_font_youyuan_20,style_btn,style_img,Screen,style_contact_btn
import audio
import utime
+import usys
from misc import Power
factorymode_cont_y = 0
factorymode_screen = lv.obj()
if rmc_tmp[2] == 'A':
if self.GNSS_status == 0:
self.time_GNSS = time_tmp-self.time_count
+ EventMesh.txt_log("test location time:{}".format(self.time_GNSS))
self.GNSS_status = 1
else:
self.GNSS_status = 0
if len(gsv_tmp)-i < 4:
break
count = 0
- for key in GSV_dict :
- #print("GSV_dict[key]:len:{}".format(len(GSV_dict[key])))
- if len(GSV_dict[key]) >= 1 :
- GNSS_DATA+=" {:<3}:[{:<3}] \n".format(key,GSV_dict[key])#:<3 宽度为3左对齐
- count+=1
- if count > 14:
- break
- print("GxGSV:{}".format(GNSS_DATA))
+ try:
+ for j in range(200):
+ for key in GSV_dict :
+
+ if(int(key) != j):
+ continue
+ #print("GSV_dict[key]:len:{}".format(len(GSV_dict[key])))
+ if len(GSV_dict[key]) >= 1 :
+ GNSS_DATA+="{:<3}:[{:<3}]".format(key,GSV_dict[key])#:<3 宽度为3左对齐
+ count+=1
+ if count % 2 == 0:
+ GNSS_DATA+="\n"
+
+ if count > 30:
+ break
+ except Exception as e:
+ usys.print_exception(e)
+ #print("GxGSV:{}".format(GNSS_DATA))
_DATA += GNSS_DATA
#FactoryModeLocation_GNSS_label.set_text(GNSS_DATA)
if msg[1] != [] : #WIFI
WIFI_len = len(msg[1][1])
- _DATA += "WIFI:------\n"
+ _DATA += "\nWIFI:------\n"
if WIFI_len > 3:
WIFI_len = 3
for i in range(WIFI_len) :
0, 0, 0xfe,
0, 0, 0xEF,
+ 0, 0, 0x21,
+
0, 1, 0x36,
1, 1, 0xd8,
1, 1, 0x00,
0, 1, 0xA8,
- 1, 1, 0x0c,
+ 1, 1, 0x22,
0, 1, 0xB4,
1, 1, 0x00,
1, 1, 0x2F,
0, 1, 0xB3,
- 1, 1, 0x03,
+ 1, 1, 0x13,
0, 1, 0xB6,
1, 1, 0x19,
1, 1, 0xC8,
0, 1, 0xAB,
- 1, 1, 0x07,
+ 1, 1, 0x0f,
0, 1, 0xb8,
1, 1, 0x08,
0, 1, 0xE8,
- 1, 1, 0x20,
+ 1, 1, 0x27,
2, 0, 12,
0, 1, 0xE9,
- 1, 1, 0x44,
+ 1, 1, 0x47,
0, 1, 0xea,
1, 1, 0x44,
0, 1, 0xeb,
1, 1, 0xb0,
- 0, 1, 0xed,
- 1, 1, 0x03,
+ # 0, 1, 0xed,
+ # 1, 1, 0x03,
0, 1, 0x44,
1, 1, 0x00,
0, 1, 0xc7,
- 1, 1, 0x10,
+ 1, 1, 0x1D,
0, 14, 0xF0,
1, 1, 0x0F,
+ 1, 1, 0x24,
+ 1, 1, 0x2c,
+ 1, 1, 0x38,
+ 1, 1, 0x67,
+ 1, 1, 0x39,
1, 1, 0x20,
- 1, 1, 0x25,
- 1, 1, 0x35,
- 1, 1, 0x26,
- 1, 1, 0x3f,
- 1, 1, 0x30,
1, 1, 0x60,
- 1, 1, 0x26,
- 1, 1, 0x03,
- 1, 1, 0x00,
- 1, 1, 0x09,
- 1, 1, 0x13,
- 1, 1, 0x1a,
+ 1, 1, 0x04,
+ 1, 1, 0x14,
+ 1, 1, 0x10,
+ 1, 1, 0x10,
+ 1, 1, 0x0c,
+ 1, 1, 0x1f,
0, 14, 0xF1,
- 1, 1, 0x00,
- 1, 1, 0x28,
- 1, 1, 0x7f,
- 1, 1, 0x39,
- 1, 1, 0xa5,
- 1, 1, 0x0f,
- 1, 1, 0x30,
+ 1, 1, 0x1f,
+ 1, 1, 0x38,
+ 1, 1, 0x3f,
+ 1, 1, 0x4f,
+ 1, 1, 0xd7,
+ 1, 1, 0x24,
+ 1, 1, 0x3f,
1, 1, 0x60,
1, 1, 0x00,
- 1, 1, 0x05,
- 1, 1, 0x01,
- 1, 1, 0x0f,
- 1, 1, 0x0f,
+ 1, 1, 0x03,
+ 1, 1, 0x09,
+ 1, 1, 0x14,
+ 1, 1, 0x10,
1, 1, 0x1F,
-
+
+ 0, 3, 0xf4,
+ 1, 1, 0x00,
+ 1, 1, 0x00,
+ 1, 1, 0xff,
0, 0, 0x11,
2, 0, 120,
def add_filter(flt):
event_store.add_filter(flt)
import utime
+import uos
Txt_Log = 1
def txt_log(data):
if Txt_Log != 0 :
+ print(data)
+ try:
+ f_stat = uos.stat("ext/log.txt")
+ if f_stat[6] >50*1024:
+ uos.remove("ext/log.txt")
+ except Exception as e:
+ usys.print_exception(e)
with open("/ext/log.txt","a",encoding="utf-8") as fd:
d_time = utime.localtime()
data_tmp = "%02d-%02d %02d:%02d:%02d :"%(d_time[1],d_time[2],d_time[3],d_time[4],d_time[5])
$(BUILD)/uping.mpy \
$(BUILD)/ymodem.mpy \
$(BUILD)/alarm.mpy \
- $(BUILD)/appAlipay.mpy \
$(BUILD)/appFactoryMode.mpy \
$(BUILD)/appWechat.mpy \
$(BUILD)/btn_device_ec800m.mpy \
self.rtc = RTC()
self.days = 0
self.idx = 0
-
+ self.rtc.enable_alarm(1)
IFEXIST = ql_fs.path_exists("/ext/static/storage_file/alarm_msg.json")
self.check_alarm_list = []
if IFEXIST == True:
factorymode_log_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
factorymode_log.add_style(style_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
-factorymode_cont_y+=200
-factorymode_alipay_init = lv.btn(factorymode_cont)
-factorymode_alipay_init.set_pos(0, factorymode_cont_y)
-factorymode_alipay_init.set_size(240, 60)
-factorymode_alipay_init_label = lv.label(factorymode_alipay_init)
-factorymode_alipay_init_label.set_text("支付宝初始化")
-factorymode_alipay_init.set_style_pad_all(0, lv.STATE.DEFAULT)
-factorymode_alipay_init_label.align(lv.ALIGN.LEFT_MID, 70, 0)
-factorymode_alipay_init_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
-factorymode_alipay_init_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
-factorymode_alipay_init.add_style(style_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
+# factorymode_cont_y+=200
+# factorymode_alipay_init = lv.btn(factorymode_cont)
+# factorymode_alipay_init.set_pos(0, factorymode_cont_y)
+# factorymode_alipay_init.set_size(240, 60)
+# factorymode_alipay_init_label = lv.label(factorymode_alipay_init)
+# factorymode_alipay_init_label.set_text("支付宝初始化")
+# factorymode_alipay_init.set_style_pad_all(0, lv.STATE.DEFAULT)
+# factorymode_alipay_init_label.align(lv.ALIGN.LEFT_MID, 70, 0)
+# factorymode_alipay_init_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
+# factorymode_alipay_init_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+# factorymode_alipay_init.add_style(style_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
class FactoryModeScreen(Screen):
super().__init__()
self.meta = factorymode_screen
factorymode_location.add_event_cb(lambda e: EventMesh.callback_wrapper(self.load_screen(e, {"screen": "FactoryModeLocation"})), lv.EVENT.CLICKED, None)
- factorymode_alipay_init.add_event_cb(lambda e: EventMesh.callback_wrapper(self.load_screen(e, {"screen": "FactoryModeAlipayInit"})), lv.EVENT.CLICKED, None)
+ #factorymode_alipay_init.add_event_cb(lambda e: EventMesh.callback_wrapper(self.load_screen(e, {"screen": "FactoryModeAlipayInit"})), lv.EVENT.CLICKED, None)
factorymode_bat_test.add_event_cb(lambda e: EventMesh.callback_wrapper(self.load_screen(e, {"screen": "FactoryModeBatTest"})), lv.EVENT.CLICKED, None)
factorymode_hsensor_test.add_event_cb(lambda e: EventMesh.callback_wrapper(self.load_screen(e, {"screen": "FactoryModeHsensorTest"})), lv.EVENT.CLICKED, None)
factorymode_log.add_event_cb(lambda e: EventMesh.callback_wrapper(self.load_screen(e, {"screen": "FactoryModeLog"})), lv.EVENT.CLICKED, None)
self.hsensorTest_timer.start(1000,1,self.hsensorTest_timer_cb)
if self.Hsensor == None:
self.Hsensor = EventMesh.publish("get_Hsensor")
+ #EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)
def post_processor_after_initialization(self):
pass
def Close(self):
self.hsensorTest_timer.stop()
+ #EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
pass
def done_return(self):
EventMesh.publish("load_screen", {"screen": "main_menu"})
-FactoryModeAlipayInit_screen = lv.obj()
-FactoryModeAlipayInit_screen.center()
-FactoryModeAlipayInit_screen.set_size(240, 320)
-FactoryModeAlipayInit_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
-
-FactoryModeAlipayInit_label = lv.label(FactoryModeAlipayInit_screen)
-FactoryModeAlipayInit_label.set_text("支付宝初始化成功")
-FactoryModeAlipayInit_label.set_size(240, 100)
-FactoryModeAlipayInit_label.set_pos(50, 100)
-FactoryModeAlipayInit_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
-FactoryModeAlipayInit_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
-import atcmd
-
-class FactoryModeAlipayInitScreen(Screen):
- NAME = "FactoryModeAlipayInit"
- def __init__(self):
- super().__init__()
- self.meta = FactoryModeAlipayInit_screen
+# FactoryModeAlipayInit_screen = lv.obj()
+# FactoryModeAlipayInit_screen.center()
+# FactoryModeAlipayInit_screen.set_size(240, 320)
+# FactoryModeAlipayInit_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+# FactoryModeAlipayInit_label = lv.label(FactoryModeAlipayInit_screen)
+# FactoryModeAlipayInit_label.set_text("支付宝初始化成功")
+# FactoryModeAlipayInit_label.set_size(240, 100)
+# FactoryModeAlipayInit_label.set_pos(50, 100)
+# FactoryModeAlipayInit_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
+# FactoryModeAlipayInit_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+# import atcmd
+
+# class FactoryModeAlipayInitScreen(Screen):
+# NAME = "FactoryModeAlipayInit"
+# def __init__(self):
+# super().__init__()
+# self.meta = FactoryModeAlipayInit_screen
- def initialization(self):
- ret =EventMesh.publish("id2_clean_data")
- print("id2_clean_data:ret:{}".format(ret))
-
- def post_processor_after_initialization(self):
- resp=bytearray(50)
- atcmd.sendSync('AT+RSTSET\r\n',resp,'',200) #清nv
- print("AT+RSTSET:{}".format(resp))
- utime.sleep(5)
- Power.powerRestart()
- def Close(self):
- pass
-
- def done_return(self):
- EventMesh.publish("load_screen", {"screen": "factorymode"})
-
- def btn1_release(self):
- EventMesh.publish("load_screen", {"screen": "factorymode"})
+# def initialization(self):
+# ret =EventMesh.publish("id2_clean_data")
+# print("id2_clean_data:ret:{}".format(ret))
+
+# def post_processor_after_initialization(self):
+# resp=bytearray(50)
+# atcmd.sendSync('AT+RSTSET\r\n',resp,'',200) #清nv
+# print("AT+RSTSET:{}".format(resp))
+# utime.sleep(5)
+# Power.powerRestart()
+# def Close(self):
+# pass
+
+# def done_return(self):
+# EventMesh.publish("load_screen", {"screen": "factorymode"})
+
+# def btn1_release(self):
+# EventMesh.publish("load_screen", {"screen": "factorymode"})
- def btn8_press(self):
- EventMesh.publish("load_screen", {"screen": "main_menu"})
+# def btn8_press(self):
+# EventMesh.publish("load_screen", {"screen": "main_menu"})
FactoryModeLocation_screen = lv.obj()
print("FactoryModeLocation_screen")
self.time_count = 0
self.time_GNSS = 0
self.GNSS_status = 0
-
+ self.timer_c = 0
def initialization(self):
FactoryModeLocation_GNSS_label.set_text("GNSS:\n")
# FactoryModeLocation_WIFI_label.set_text("WIFI:")
EventMesh.publish(constants.EVENT.START_LOCATION_TEST) #测试模式
def timer_FactoryModeLocation_cb(self, *args, **kwargs):
- EventMesh.publish("system_sleep_rest")#防止黑屏
+ EventMesh.publish("system_sleep_rest")#防止黑屏
+ self.timer_c += 1
+ if self.timer_c >= 5:
+ get_location_flag = EventMesh.publish("get_location_flag")
+ self.timer_c = 0
+ if get_location_flag != None:
+ if(get_location_flag == 0):
+ EventMesh.publish(constants.EVENT.START_LOCATION_TEST) #测试模式
def GET_LOCATION_DATA(self, event, msg):
# print("GPS:{}".format(msg[0]))
if len(msg[0]) > 1 : #GPS
GNSS_DATA = "GNSS:------\n"
- _DATA += "定位时间:{};{}秒\n".format(self.time_GNSS,time_tmp-self.time_count)
+
rmc_data = msg[0][1].split("RMC")
gsv_data = msg[0][1].split("GSV")
if len(rmc_data) >= 2 :
if self.GNSS_status == 0:
self.time_GNSS = time_tmp-self.time_count
EventMesh.txt_log("test location time:{}".format(self.time_GNSS))
+
+ self.time_count = utime.mktime(utime.localtime())
self.GNSS_status = 1
else:
self.GNSS_status = 0
- self.time_GNSS = 0
-
+ #self.time_GNSS = 0
+ _DATA += "定位时间:{};{}秒\n".format(self.time_GNSS,time_tmp-self.time_count)
if len(gsv_data) >= 2 :
gsv_data = gsv_data[1:]
GSV_dict= {}
_DATA += "CALL:------\n{}".format(msg[2][0])
#FactoryModeLocation_CALL_label.set_text("CALL:{}".format(msg[2][0]))
print("GET_LOCATION_DATA:data:{}".format(_DATA))
- FactoryModeLocation_GNSS_label.set_text(_DATA)
+ FactoryModeLocation_GNSS_label.set_text(_DATA)
+ self.timer_c = 0
def Close(self):
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)
self.timer_FactoryModeLocation.stop()
from ui_main_menu import MainMenuScreen
# from ui_WatchFaceScreen import WatchFaceScreen
- from appFactoryMode import FactoryModeLocationScreen,FactoryModeScreen ,FactoryModeAlipayInitScreen,FactoryModeBatTestScreen,FactoryModeHsensorTestScreen,FactoryModeLogScreen
+ from appFactoryMode import FactoryModeLocationScreen,FactoryModeScreen ,FactoryModeBatTestScreen,FactoryModeHsensorTestScreen,FactoryModeLogScreen
from mgr import setSmsIndexManager,ConfigStoreManager,testSmsSetIPManager,playPowerAudioManager,sosInfoCallManager,getBootOffManager,getSosFlagManager,CountdownManager, LocationManager, getVolumSizeManager,gethistoryDataManager,getUpLoadDataManager, getplayAudiodStateManager,\
AddrBookManager,MsgdetailManager,PhoneCallingManager,getOldTimeManager,getStorageDataManager,getBrightnessManager,getHrTimeManager,getTempTimeManager,getLowBatManager
ui.add_screen(_ui.CallLogScreen())
except Exception as e:
usys.print_exception(e)
- try:
- 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())
- except Exception as e:
- usys.print_exception(e)
+ # try:
+ # from appAlipay import Alipay ,AlipayOpenScreen,Alipay_1_1,Alipay_invite,Alipay_inviting,\
+ # Alipay_success,Alipay_paycode,Alipay_pay_success,Alipay_collect,Alipay_parent
+ # from appFactoryMode import FactoryModeAlipayInitScreen,
+ # 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(FactoryModeAlipayInitScreen())
+ # except Exception as e:
+ # usys.print_exception(e)
try:
ui.add_screen(_ui.UIFINDScreen())
ui.add_screen(_ui.MsgDetailScreen())
try:
ui.add_screen(FactoryModeLocationScreen())
ui.add_screen(FactoryModeScreen())
- ui.add_screen(FactoryModeAlipayInitScreen())
+
ui.add_screen(FactoryModeBatTestScreen())
ui.add_screen(FactoryModeHsensorTestScreen())
ui.add_screen(FactoryModeLogScreen())
ui.add_screen(_ui.chargeInScreen())
ui.add_screen(_ui.chargeOutScreen())
ui.add_screen(_ui.restore_confirmScreen())
- ui.add_screen(_ui.calendar_Screen())
+
ui.add_screen(NewWechatPopupScreen())
ui.add_screen(HealthScreen())
# ui.add_screen(_ui.Setting3Screen())
# .append_manager(mgr.StopwatchManager()) \
# .append_manager(mgr.CountdownManager()) \
app.append_manager(playPowerAudioManager())
- app.append_manager(Alipay())
+ #app.append_manager(Alipay())
app.append_manager(ConfigStoreManager())
app.append_manager(NetManager())
app.append_manager(LocationManager())
EventMesh.publish("countdown_end_cb")
"""定时检查是否关闭gps失败"""
- gnss_state = quecgnss.get_state()
- get_location_flag = EventMesh.publish("get_location_flag")
- if get_location_flag != None:
- if gnss_state == 2 and get_location_flag == 0:
- EventMesh.publish(constants.EVENT.GPSCLOSE)
+ # gnss_state = quecgnss.get_state()
+ # get_location_flag = EventMesh.publish("get_location_flag")
+ # if get_location_flag != None:
+ # # if gnss_state == 2 and get_location_flag == 0:
+ # # EventMesh.publish(constants.EVENT.GPSCLOSE)
+ # if(get_location_flag == 0):
+ # EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
"""7分钟一次心跳"""
if math.fabs(time_tmp - self.KA_time) > 7*60: #7分钟一次心跳
if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and status_tmp > 3 :
EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
self.gsensor.clean_status()#清除运动次数
+ else : #关闭定位
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
+
"""电池平均值"""
temp = Power.getVbatt()
if self.bat_count < 10:
self.location_type = 0 #定位类型,0:正常定位,有gps数据或60秒关闭;1:测试模式,只有发CLOSE_LOCATION消息才关闭
self.location_flag = 0
self.start_location_flag = 0
- self.location_thread_id = 0
- self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
+ self.location_thread_id = 0
self.location_queue = Queue(100)
#quecgnss.init()
#quecgnss.gnssEnable(0)
def start_location(self, event, msg):
self.location_queue.put(msg)#测试类型入队
print("start_location:{}".format(msg))
- self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+ self.location_timer_count = 0
if( self.location_flag == 1):
return
- self.location_timer_count = 0
+ self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
self.location_flag = 1
#self.gps_open(event, msg)
- self.start_location_flag = 1
def start_location_test(self, event, msg):
print("start_location_test")
- self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+
+ self.location_type = 1
if( self.location_flag == 1):
return
+ self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
self.location_timer_count = 0
self.location_flag = 1
#self.gps_open(event, msg)
self.location_type = 1
- self.start_location_flag = 1
+
def close_location(self, event, msg):
self.location_flag = 0
self.location_type = 0
- self.gps.power_switch(0)
- wifiScan.control(0)
- self.timer_read_GPS_info.stop()
+
def WIFI_INFO(self, event, msg):
self.wifi_data = msg
#print("Location_send1")
date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
date = date[2:]
+ #date = "180916,025723"
GPS_type = "V"
latitude = "0.000000,N"
longitude = "0.000000,E"
direction = "0.0"
high = "100.0"
number = "0"
- if msg[0] != [] :#有GPS数据
+ precision = "24"
+ if msg[0] :#有GPS数据
GPS_type = "A"
# 纬度
latitude = msg[0]["latitude"]
high = "%s"%(high_tmp[0])
# 讯号质量:搜索到的卫星数目
number = msg[0]["number"]
+ precision = msg[0]["precision"]
+ #date = msg[0]["date"]
#gsm 信号强度
gsm_sig = str((100//31)*EventMesh.publish("screen_get_sig"))
# 电池电量百分比
send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
send_data += ",%d,%s"%(WIFI_num,WIFI_data)
+ send_data+=",%s"%(precision)
#print("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
while True:
if self.location_queue.empty() == False:
def location_thread(self):
- gnss_r_data = ""
- while True:
+ self.wifi_data = []
+ self.gps_data = {}
+ self.cell_data = []
+ gnss_r_data = []
+ self.GSV_sig_ok_count = 0
+ self.GGA_count = 0
+
+ print("location_thread:1")
+ EventMesh.publish(constants.EVENT.GPSOPEN)
+ print("location_thread:2")
+ self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+ #utime.sleep_ms(1000)
+ self.location_timer_count = 0
+ #quecgnss.read(4096)#去掉第一次错误数据
+ #EventMesh.txt_log("START_LOCATION")
+ while self.location_flag == 1:
try :
- if self.location_flag == 1 :
+
+ match_gga_data = []
+ #match_gsv_data = []
+ gnss_r_data = []
+ if self.location_check_data_timer_count > 3 :#3秒查一次基站数据和wifi数据
+ self.location_check_data_timer_count = 0
+ #print(self.location_timer_count)
+ #GSV_dict= {}
- if self.start_location_flag == 1 :
- self.start_location_flag = 0
- self.wifi_data = []
- self.gps_data = []
- self.cell_data = []
- gnss_r_data = []
- print("location_thread:1")
- EventMesh.publish(constants.EVENT.GPSOPEN)
- print("location_thread:2")
- EventMesh.publish(constants.EVENT.WIFISCANOPEN)
- print("location_thread:3")
- utime.sleep_ms(1000)
- self.location_timer_count
- #quecgnss.read(4096)#去掉第一次错误数据
- match_gga_data = []
- #match_gsv_data = []
- gnss_r_data = []
- if self.location_check_data_timer_count > 3 :#5秒查一次基站数据和wifi数据
- self.location_check_data_timer_count = 0
- #print(self.location_timer_count)
- GSV_dict= {}
- GSV_sig_ok_count = 0
- #检查GNSS数据
- if (self.gps_data == [] or self.location_type == 1) and quecgnss.get_state() == 2:
- self.gps.__gps_nmea_data_clean()
- #gnss_r_data = [0,1]
- gnss_r_data = quecgnss.read(4096)
- #print("location gnss_r_data:{}".format(gnss_r_data[1].decode()))
- print("gnss_r_data len:{}".format(gnss_r_data[0]))
- if gnss_r_data[0] > 0 : #有数据
- gsv_data = gnss_r_data[1].split("GSV")
- if len(gsv_data) >= 2 :
- gsv_data = gsv_data[1:]
- for i in range(len(gsv_data)) :
- gsv_data[i] = gsv_data[i].split("\r\n")[0]
- gsv_tmp = gsv_data[i].split(",")
- if len(gsv_tmp) < 7 :
- break
- gsv_tmp = gsv_tmp[4:]
- #print("gsv_tmp:{}".format(gsv_tmp))
- for i in range(len(gsv_tmp)) :
- if i % 4 == 0:
- GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
- try:
- #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
- if gsv_tmp[i+3] != "" :
- if int(gsv_tmp[i+3])>=24:
- GSV_sig_ok_count+=1
- except Exception as e:
- usys.print_exception(e)
- #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
- if len(gsv_tmp)-i < 4:
- break
- #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
- #match_gsv_data = self.match.GxGSV(gnss_r_data[1]).split(",")
- if self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全
- match_gmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
+ #检查GNSS数据
+ if (self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+ self.gps.__gps_nmea_data_clean()
+ #gnss_r_data = [0,1]
+ gnss_r_data = quecgnss.read(4096)
+ print("location gnss_r_data:\n{}".format(gnss_r_data[1].decode()))
+ #print("gnss_r_data len:{}".format(gnss_r_data[0]))
+ if gnss_r_data[0] > 0 : #有数据
+ tmp_ok_count = 0
+ gsv_data = gnss_r_data[1].split("GSV")
+ if len(gsv_data) >= 2 :
+ gsv_data = gsv_data[1:]
+ for i in range(len(gsv_data)) :
+ gsv_data[i] = gsv_data[i].split("\r\n")[0]
+ gsv_tmp = gsv_data[i].split(",")
+ if len(gsv_tmp) < 7 :
+ break
+ #self.GGA_count = int(gsv_tmp[3])
+
+ gsv_tmp = gsv_tmp[4:]
+ #print("gsv_tmp:{}".format(gsv_tmp))
+ for i in range(len(gsv_tmp)) :
+ if i % 4 == 0:
+ #GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
+ try:
+ #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+ if gsv_tmp[i+3] != "" :
+ if int(gsv_tmp[i+3])>=25:
+ tmp_ok_count +=1
+ except Exception as e:
+ usys.print_exception(e)
+ #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
+ if len(gsv_tmp)-i < 4:
+ break
+
+ if(tmp_ok_count > self.GSV_sig_ok_count ):
+ self.GSV_sig_ok_count = tmp_ok_count
+ #print("GGA_count:{} GSV_sig_ok_coun:{}".format(self.GGA_count,self.GSV_sig_ok_count))
+ match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+
+ if len(match_gga_data) > 8:
+ #print(match_gga_data)
+ self.GGA_count = int(match_gga_data[7]) #可用微信
+ print("GGA_count:{} GSV_sig_ok_coun:{} ".format(self.GGA_count,self.GSV_sig_ok_count))
+ #match_gsv_data = self.match.GxGSV(gnss_r_data[1]).split(",")
+ match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
+ #print("match_rmc_data:\n{}".format(match_rmc_data))
+ if len (match_rmc_data)>3: #有rmc数据
+ if match_rmc_data[2] == 'A':
+
+ #match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
match_vtg_data = self.match.GxVTG(gnss_r_data[1]).split(",")
- match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+ if len(match_gga_data) < 8:
+ match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
latitude_tmp = str(gps_data_tmp[1]).split(".")
- if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
- latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
- latitude = "%s,%s"%(latitude,match_gmc_data[4] )
- longitude_tmp = str(gps_data_tmp[0]).split(".")
- if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
- longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
- longitude = "%s,%s"%(longitude,match_gmc_data[6] ) #match_gmc_data[6] + str(gnss_r_data[1])
- high = str(gps_data_tmp[2])
- self.gps_data = {
- "latitude": latitude,
- "longitude": longitude,
- "high": high,
- "direction": match_vtg_data[1],
- "speed": match_vtg_data[5],
- "number": match_gga_data[7],
- }
- #检查wifi数据
- if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
- EventMesh.publish(constants.EVENT.WIFISCANOPEN)
-
- #检查基站数据
- if self.cell_data == []:
- data_tmp = net.getCellInfo()
- for cell in data_tmp:
- if cell and cell[0][0] == 0 and len(cell[0]) > 1:
- self.cell_data = cell
- break
- if self.location_timer_count >= 60*7 : #4分钟关闭
+ if len(match_vtg_data)>5 and len(match_gga_data)>5 and len(latitude_tmp) >= 2:
+
+ print("LOCATION_ok :time:{}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n".format(self.location_timer_count))
+ gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])
+ latitude = "0"
+ if len(latitude_tmp[1])>=5:
+ latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:5])
+ latitude = "%s,%s"%(latitude,match_rmc_data[4] )
+ longitude_tmp = str(gps_data_tmp[0]).split(".")
+ longitude = "0"
+ if len(longitude_tmp[1])>=5:
+ longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
+ longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
+ high = str(gps_data_tmp[2])
+ self.gps_data = {
+ "latitude": latitude,
+ "longitude": longitude,
+ "high": high,
+ "direction": match_vtg_data[1],
+ "speed": match_vtg_data[5],
+ "number": match_gga_data[7],
+ "date": gps_date,
+ "precision": match_gga_data[8]
+ }
+ #检查wifi数据
+ if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
+ EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+
+ #检查基站数据
+ if self.cell_data == []:
+ data_tmp = net.getCellInfo()
+ if(len(data_tmp)>=2):
+ for cell in data_tmp:
+ if cell and cell[0][0] == 0 and len(cell[0]) > 1:
+ self.cell_data = cell
+ break
+
+ if self.location_type == 1: #测试模式
+ self.location_timer_count = 0
+ if len(gnss_r_data) >= 1:
+ if gnss_r_data[0] > 0:
+ EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data])
+ if self.gps_data != {} : #发送数据
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- #break
- #EventMesh.txt_log("GSV_sig_ok_count :{}".format(GSV_sig_ok_count))
- if self.location_type == 1: #测试模式
- if len(gnss_r_data) >= 1:
- if gnss_r_data[0] > 0:
- EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data])
- elif self.location_type == 0: #正常模式
- if self.gps_data != [] or self.location_timer_count > 180: #or( self.wifi_data != [] and self.cell_data != []):
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ self.location_queue.put(constants.PROTOCOL.UD_SEND)
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+
+ elif self.location_type == 0: #正常模式
+ if self.gps_data != {} or self.location_timer_count > 170: #or( self.wifi_data != [] and self.cell_data != []):
+ upload_time = EventMesh.publish("get_upload_data")
+ if upload_time > 200 or self.gps_data != {} : #定位间隔小于3分钟且定位失败不关闭gps,不影响无信号判断
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("CLOSE_LOCATION:location_timer_count:{}".format(self.location_timer_count))
- #break
-
- if len(GSV_dict) < 2 and GSV_sig_ok_count < 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过20秒且卫星个数少于3
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("len(GSV_dict) < 2")
- if GSV_sig_ok_count < 3 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 40: #超过40秒且信号大于30的不足3个
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("GSV_sig_ok_count < 3")
- #break
- utime.sleep_ms(1000)
- #print("location_timer_count:{}".format(self.location_timer_count))
- else :
- utime.sleep_ms(2000)
+ EventMesh.txt_log("CLOSE_LOCATION:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+ if self.GGA_count < 3 and self.wifi_data and self.cell_data and self.location_timer_count > 20 and self.location_timer_count < 30: #超过20秒且有效卫星个数少于3
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+ if self.GSV_sig_ok_count < 3 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 40: #超过40秒且信号大于30的不足3个
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ #break
+ # if self.location_type != 1 and self.location_timer_count >= 60*4 : #4分钟关闭
+ # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ #break
+ #EventMesh.txt_log("self.GSV_sig_ok_count :{}".format(self.GSV_sig_ok_count))
+ #EventMesh.publish("set_old_step_value",self.location_timer_count)
+
+ #print("location_timer_count:{}".format(self.location_timer_count))
+
except Exception as e:
usys.print_exception(e)
- utime.sleep_ms(1000)
- print("location_thread:ERROR:{}\r\n{}".format(e,Exception))
+ EventMesh.txt_log("location_thread:ERROR:".format(e))
+ #print("location_thread:ERROR:{}".format(usys.print_exception(e)))
print("self.gps_data{},self.wifi_data{},self.cell_data{}".format(self.gps_data,self.wifi_data,self.cell_data))
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ #self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ #EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ utime.sleep_ms(1000)
+ self.timer_read_GPS_info.stop()
+ self.gps.power_switch(0)
+ wifiScan.control(0)
+
+ print("CLOSE_LOCATION")
+ #EventMesh.txt_log("CLOSE_LOCATION")
def server_init(server_type = None):
- #服务器选择1,防走丢,2大锤,3三基同创,4童信
+ #服务器选择1,防走丢,2大锤,3三基同创,4童信,5云米,6荣为
if server_type == None:
server_type = 1
#print("server_init:server_type:{}".format(server_type))
d_server_port = 8505
d_md5_key = ""
d_PID = "3G"
+ elif server_type == 6:
+ d_server_addr = "120.26.104.21"
+ d_server_port = 9968
+ d_md5_key = "bZld0ALsZTt15tKEZhOlLPgbsO75BLTP"
+ d_PID = "SZKW"
return [d_server_addr,d_server_port,d_md5_key,d_PID]
from queue import Queue
def unicode_to_utf8(src):
def connect(self):
print("connect1{}:{}".format(self.server_addr, self.server_port))
- if EventMesh.publish("network_state") == 0: #没注网
+ if EventMesh.publish("get_sim_Status") != 1: #没sim
return
try:
if(self.sock != None) :
except Exception as e:
self.reconnect()
self.socket_send_queue.put(data)#重新把数据加回队列
- print("socket_send_queue_thread1:ERROR:")
- usys.print_exception(e)
+ #print("socket_send_queue_thread1:ERROR:")
+ #usys.print_exception(e)
elif socketsta < 4:#正在连接,等待连接成功重新发送
count = 0
while True:
except Exception as e:
self.reconnect()
self.socket_send_queue.put(data)#重新把数据加回队列
- print("socket_send_queue_thread2:ERROR:")
- usys.print_exception(e)
+ #print("socket_send_queue_thread2:ERROR:")
+ #usys.print_exception(e)
break
else :#连接错误
print("socket_send_queue_thread:ERROR:reconnect")
def send(self, topic, msg):
# print("TCP:send data:{}".format(msg))
- if EventMesh.publish("network_state") == 0: #没注网,则不发送
+ if EventMesh.publish("get_sim_Status") != 1: #没sim,则不发送
EventMesh.publish(constants.EVENT.SET_CONNECT, 0)#标记断网
print("dataCall not connect")
return
data = b''
except Exception as e:
- print("TCP:ERROR:recv:")
- usys.print_exception(e)
+ #print("TCP:ERROR:recv:")
+ #usys.print_exception(e)
self.run_flag = False
self.reconnect()
@param msg: 接收到的下行数据
"""
# b'[SZKW*867387060319166*000A*MONITOR]'
- read_data = EventMesh.publish("set_storage_config","center_dial")
+ read_data = EventMesh.publish("get_storage_config","center_dial")
if read_data != None:
contact = read_data
# print("test end2")
-# import request
-# import ujson
+import request
+import ujson
-# def manual_url_encode(s: str) -> str:
-# """Encodes a string for use in a URL query string."""
-# safe_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.*"
-# encoded_str = ""
+def manual_url_encode(s: str) -> str:
+ """Encodes a string for use in a URL query string."""
+ safe_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.*"
+ encoded_str = ""
-# for char in s:
-# if char in safe_chars:
-# encoded_str += char
-# else:
-# encoded_str += ''.join(['%' + hex(c)[2:].upper() for c in char.encode('utf-8')])
-# return encoded_str
-
-# def generate_url(base_uri: str, params: dict) -> str:
-# """Generates a full URL given a base URI and a dictionary of query parameters."""
-# # Encode each key-value pair in the params dictionary
-# encoded_params = "&".join([key + "=" + manual_url_encode(str(value)) for key, value in params.items()])
-# return base_uri + "?" + encoded_params
-
-# # Test the function with the given example
-# base_uri = "http://ability.raisound.com:8096/bwtts"
-# params = {
-# "text": "这是一个测试用例,一二三四五,上山打老虎",
-# "voice_name": "xiaomu",
-# "sample_rate": 16000,
-# "audio_format": "mp3"
-# }
-# generated_url = generate_url(base_uri, params)
-# print("url:{}".format(generated_url))
-# response = request.get(generated_url)
-# print("status_code:{}".format(response.status_code))
-# play_flag = 2 # = 1流播放 =2保存文件播放
-# import audio
-# from machine import Pin
-# record_test = audio.Record()
-# record_test.gain(4,12)
-# aud = audio.Audio(0)
-# aud.set_pa(Pin.GPIO29)
-# aud.setVolume(11)
-# tmp = bytearray()
-# size = 10*1024
-# ret = 0
-# if play_flag == 1:
-# for i in response.content:
-# #print("type:{}".format(type(i)))
-# tmp+= bytearray(i)
-# print("data len:{}".format(len(tmp)))
-# #print("data:{}".format(tmp))
-# ret = aud.playStream(3, tmp)
-# utime.sleep_ms(20)
-# else:
-# len_tmp = 0
-# with open('/ext/test.mp3', 'w+')as fp:
-# for i in response.content:
-# fp.write(i)
-# len_tmp+=len(i)
-# print("data len:{}".format(len_tmp))
-# #ret = aud.play(1, 1, '/ext/test.mp3')
-# with open("/ext/test.mp3", "rb")as f:
-# while 1:
-# b = f.read(size) # read
-# if not b:
-# break
-# ret =aud.playStream(3, b)
-# utime.sleep_ms(20)
-# print("ret:{}".format(ret))
-
-
-
-
-import quecgnss
-import utime
-
-import quecgnss
-import utime
-import ure
-
-gnss_init_flag = 0
-ret = -1
-fix_num = 0
-
-def gnss_nmea_debug(gnss_data):
- global fix_num
- global gnss_init_flag
- try:
- rmc_info = ure.search("GNRMC(.+?)M", gnss_data)
- if rmc_info.group(0).split(",")[2] == 'A':
- if fix_num > 1:
- print("输出有效定位!\r\n")
- else:
- fix_num = fix_num + 1
-
- except:
- pass
-
-
-def gnss_nmea_get_sat(gnss_data):
- try:
- nema_str_list = gnss_data.split('\r\n')
- for i in range(len(nema_str_list)):
- if(ure.search("GPGSV(.+?)", nema_str_list[i]) != None):
- # print(nema_str_list[i].split(",")[3])
- try:
- print('GPS SAT NUM:{},SAT1 {} SNR {},SAT2 {} SNR {},SAT3 {} SNR {},SAT4 {} SNR {}\r\n'.format(nema_str_list[i].split(",")[3], \
- nema_str_list[i].split(",")[4], nema_str_list[i].split(",")[7], nema_str_list[i].split(",")[8], \
- nema_str_list[i].split(",")[11], nema_str_list[i].split(",")[12], nema_str_list[i].split(",")[15], \
- nema_str_list[i].split(",")[16], nema_str_list[i].split(",")[19]))
-
- except:
- pass
-
- elif(ure.search("GBGSV(.+?)", nema_str_list[i]) != None):
- # print(nema_str_list[i].split(",")[3])
- try:
- print('BDS SAT NUM:{},SAT1 {} SNR {},SAT2 {} SNR {},SAT3 {} SNR {},SAT4 {} SNR {}\r\n'.format(nema_str_list[i].split(",")[3], \
- nema_str_list[i].split(",")[4], nema_str_list[i].split(",")[7], nema_str_list[i].split(",")[8], \
- nema_str_list[i].split(",")[11], nema_str_list[i].split(",")[12], nema_str_list[i].split(",")[15], \
- nema_str_list[i].split(",")[16], nema_str_list[i].split(",")[19]))
- except:
- pass
-
- else:
- pass
- except Exception as e:
- print(str(e))
-
-
-def main():
- global fix_num
- global gnss_init_flag
- global ret
- if(gnss_init_flag == 0):
- ret = quecgnss.init()
- if ret == 0:
- print('GNSS init ok.\r\n')
- gnss_init_flag = 1
+ for char in s:
+ if char in safe_chars:
+ encoded_str += char
else:
- print('GNSS init failed.\r\n')
- return -1
- else:
- print('GNSS has been init.\r\n')
- quecgnss.gnssEnable(1)
-
- for i in range(60):
- print("==========GNSS READTIME {}==========\r\n".format(i+1))
- data = quecgnss.read(4096)
- gnss_data = data[1].decode()
- print(gnss_data)
- gnss_nmea_get_sat(gnss_data)
- utime.sleep(1)
-
- quecgnss.gnssEnable(0)
- fix_num = 0
- utime.sleep(5)
- quecgnss.gnssEnable(1)
- print("==========GNSS RESTART==========\r\n")
-
- for i in range(60):
- print("==========GNSS READTIME {}==========\r\n".format(i+1))
- data = quecgnss.read(4096)
- gnss_data = data[1].decode()
- print(gnss_data)
- gnss_nmea_get_sat(gnss_data)
- utime.sleep(1)
-
- quecgnss.gnssEnable(0)
- fix_num = 0
-
-
-
-if __name__ == '__main__':
- main()
\ No newline at end of file
+ encoded_str += ''.join(['%' + hex(c)[2:].upper() for c in char.encode('utf-8')])
+ return encoded_str
+
+def generate_url(base_uri: str, params: dict) -> str:
+ """Generates a full URL given a base URI and a dictionary of query parameters."""
+ # Encode each key-value pair in the params dictionary
+ encoded_params = "&".join([key + "=" + manual_url_encode(str(value)) for key, value in params.items()])
+ return base_uri + "?" + encoded_params
+
+# Test the function with the given example
+base_uri = "http://ability.raisound.com:8096/bwtts"
+params = {
+ "text": "这是一个测试用例,一二三四五,上山打老虎",
+ "voice_name": "xiaomu",
+ "sample_rate": 44100,
+ "audio_format": "mp3"
+}
+import audio
+from machine import Pin
+record_test = audio.Record()
+record_test.gain(4,12)
+aud = audio.Audio(0)
+aud.set_pa(Pin.GPIO29)
+aud.setVolume(11)
+tmp = bytearray()
+generated_url = generate_url(base_uri, params)
+print("url:{}".format(generated_url))
+response = request.get(generated_url)
+print("status_code:{}".format(response.status_code))
+play_flag = 1 # = 1流播放 =2保存文件播放
+
+size = 10*1024
+ret = 0
+if play_flag == 1:
+ for i in response.content:
+ print("len:{}".format(len(i)))
+ #tmp+= bytearray(i)
+ ret = aud.playStream(3, bytearray(i))
+ print("data len:{}".format(len(tmp)))
+ #print("data:{}".format(tmp))
+ #ret = aud.playStream(3, tmp)
+ utime.sleep_ms(20)
+else:
+ len_tmp = 0
+ with open('/ext/test.mp3', 'w+')as fp:
+ for i in response.content:
+ fp.write(i)
+ len_tmp+=len(i)
+ print("data len:{}".format(len_tmp))
+ #ret = aud.play(1, 1, '/ext/test.mp3')
+ with open("/ext/test.mp3", "rb")as f:
+ while 1:
+ b = f.read(size) # read
+ if not b:
+ break
+ ret =aud.playStream(3, b)
+ utime.sleep_ms(20)
+print("ret:{}".format(ret))
+
+
+
+
+# import quecgnss
+# import utime
+
+# import quecgnss
+# import utime
+# import ure
+
+# gnss_init_flag = 0
+# ret = -1
+# fix_num = 0
+
+# def gnss_nmea_debug(gnss_data):
+# global fix_num
+# global gnss_init_flag
+# try:
+# rmc_info = ure.search("GNRMC(.+?)M", gnss_data)
+# if rmc_info.group(0).split(",")[2] == 'A':
+# if fix_num > 1:
+# print("输出有效定位!\r\n")
+# else:
+# fix_num = fix_num + 1
+
+# except:
+# pass
+
+
+# def gnss_nmea_get_sat(gnss_data):
+# try:
+# nema_str_list = gnss_data.split('\r\n')
+# for i in range(len(nema_str_list)):
+# if(ure.search("GPGSV(.+?)", nema_str_list[i]) != None):
+# # print(nema_str_list[i].split(",")[3])
+# try:
+# print('GPS SAT NUM:{},SAT1 {} SNR {},SAT2 {} SNR {},SAT3 {} SNR {},SAT4 {} SNR {}\r\n'.format(nema_str_list[i].split(",")[3], \
+# nema_str_list[i].split(",")[4], nema_str_list[i].split(",")[7], nema_str_list[i].split(",")[8], \
+# nema_str_list[i].split(",")[11], nema_str_list[i].split(",")[12], nema_str_list[i].split(",")[15], \
+# nema_str_list[i].split(",")[16], nema_str_list[i].split(",")[19]))
+
+# except:
+# pass
+
+# elif(ure.search("GBGSV(.+?)", nema_str_list[i]) != None):
+# # print(nema_str_list[i].split(",")[3])
+# try:
+# print('BDS SAT NUM:{},SAT1 {} SNR {},SAT2 {} SNR {},SAT3 {} SNR {},SAT4 {} SNR {}\r\n'.format(nema_str_list[i].split(",")[3], \
+# nema_str_list[i].split(",")[4], nema_str_list[i].split(",")[7], nema_str_list[i].split(",")[8], \
+# nema_str_list[i].split(",")[11], nema_str_list[i].split(",")[12], nema_str_list[i].split(",")[15], \
+# nema_str_list[i].split(",")[16], nema_str_list[i].split(",")[19]))
+# except:
+# pass
+
+# else:
+# pass
+# except Exception as e:
+# print(str(e))
+
+
+# def main():
+# global fix_num
+# global gnss_init_flag
+# global ret
+# if(gnss_init_flag == 0):
+# ret = quecgnss.init()
+# if ret == 0:
+# print('GNSS init ok.\r\n')
+# gnss_init_flag = 1
+# else:
+# print('GNSS init failed.\r\n')
+# return -1
+# else:
+# print('GNSS has been init.\r\n')
+# quecgnss.gnssEnable(1)
+
+# for i in range(60):
+# print("==========GNSS READTIME {}==========\r\n".format(i+1))
+# data = quecgnss.read(4096)
+# gnss_data = data[1].decode()
+# print(gnss_data)
+# gnss_nmea_get_sat(gnss_data)
+# utime.sleep(1)
+
+# quecgnss.gnssEnable(0)
+# fix_num = 0
+# utime.sleep(5)
+# quecgnss.gnssEnable(1)
+# print("==========GNSS RESTART==========\r\n")
+
+# for i in range(60):
+# print("==========GNSS READTIME {}==========\r\n".format(i+1))
+# data = quecgnss.read(4096)
+# gnss_data = data[1].decode()
+# print(gnss_data)
+# gnss_nmea_get_sat(gnss_data)
+# utime.sleep(1)
+
+# quecgnss.gnssEnable(0)
+# fix_num = 0
+
+
+
+# if __name__ == '__main__':
+# main()
\ No newline at end of file
self.timer = osTimer()
self.point = 0
self.spo2_value = 0
-
+ #self.Hsensor = None
def initialization(self):
global spo2_screen,spo2_label,spo2_value_label,spo2_reset_btn_img,spo2_done_img,spo2_line_bg_img,spo2_line1,spo2_line2,\
spo2_line3,spo2_line4,spo2_line5,spo2_line6,spo2_line7,spo2_line_bg_img ,spo2_start_label ,spo2_done_label
self.spo2_value = 0
self.show_history_data()
self.restart_up(0)
-
+
def restart_up(self,e):
global spo2_value_label,heartrate_bpm_label,spo2_start_label,spo2_reset_btn_img
self.point = 0
self.point = self.point + 1
EventMesh.publish("system_sleep_rest")#防止黑屏
WEAR = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
+ # if self.Hsensor == None:
+ # self.Hsensor = EventMesh.publish("get_Hsensor")
+ # c_data = self.Hsensor.get_test_data()#校准数据和工厂数据
+ # print(" 佩戴状态\n红外:{}活体:{}佩戴:{}\n{},{} \n{},{} \n{},{}\n校准数据:{},{},{},{}\n漏光数据:{},{},{}"
+ # .format(c_data[3],c_data[4],WEAR,c_data[5],c_data[6],c_data[7],c_data[8],c_data[9],c_data[10],
+ # c_data[11],c_data[12],c_data[13],c_data[14],c_data[0],c_data[1],c_data[2],))
# print("sop2:start_measure:point{}".format(self.point))
self.spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
if self.point >= 2:
label_text.set_size(0, 0)
label_text.set_text("0")
MainMenu2_num+=1
-#支付宝
-MainMenu2_alipay = MainMenu2_til.add_tile(MainMenu2x, 0, lv.DIR.LEFT | lv.DIR.RIGHT)
-#MainMenu2_alipay.set_tile_act(7,0,lv.ANIM.ON)#设置拼接
-label_text = lv.label(MainMenu2_alipay)
-label_text.set_pos(0, 240)
-label_text.set_size(0, 0)
-label_text.set_text("{}".format(MainMenu2_num))
-MainMenu2_img_alipay_text = lv.label(MainMenu2_alipay)
-MainMenu2_img_alipay_text.set_pos(int(0),int(220))
-MainMenu2_img_alipay_text.set_size(240,100)
-MainMenu2_img_alipay_text.add_flag(lv.obj.FLAG.CLICKABLE)
-MainMenu2_img_alipay_text.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
-MainMenu2_img_alipay_text.set_text("支付宝")
-MainMenu2_img_alipay_text.add_style(style_font_youyuan_font_60, lv.PART.MAIN|lv.STATE.DEFAULT)
-
-MainMenu2_img_alipay = lv.img(MainMenu2_alipay)
-MainMenu2_img_alipay.set_size(160,160)
-MainMenu2_img_alipay.set_pos(40,20)
-MainMenu2_img_alipay.set_src("U:/static/alipay_.png")
-MainMenu2_img_alipay.add_flag(lv.obj.FLAG.CLICKABLE)
-MainMenu2_img_alipay.add_style(style_MainMenu_img_default, lv.PART.MAIN | lv.STATE.DEFAULT)
-MainMenu2_num+=1
-MainMenu2x+=1
+# #支付宝
+# MainMenu2_alipay = MainMenu2_til.add_tile(MainMenu2x, 0, lv.DIR.LEFT | lv.DIR.RIGHT)
+# #MainMenu2_alipay.set_tile_act(7,0,lv.ANIM.ON)#设置拼接
+# label_text = lv.label(MainMenu2_alipay)
+# label_text.set_pos(0, 240)
+# label_text.set_size(0, 0)
+# label_text.set_text("{}".format(MainMenu2_num))
+# MainMenu2_img_alipay_text = lv.label(MainMenu2_alipay)
+# MainMenu2_img_alipay_text.set_pos(int(0),int(220))
+# MainMenu2_img_alipay_text.set_size(240,100)
+# MainMenu2_img_alipay_text.add_flag(lv.obj.FLAG.CLICKABLE)
+# MainMenu2_img_alipay_text.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
+# MainMenu2_img_alipay_text.set_text("支付宝")
+# MainMenu2_img_alipay_text.add_style(style_font_youyuan_font_60, lv.PART.MAIN|lv.STATE.DEFAULT)
+
+# MainMenu2_img_alipay = lv.img(MainMenu2_alipay)
+# MainMenu2_img_alipay.set_size(160,160)
+# MainMenu2_img_alipay.set_pos(40,20)
+# MainMenu2_img_alipay.set_src("U:/static/alipay_.png")
+# MainMenu2_img_alipay.add_flag(lv.obj.FLAG.CLICKABLE)
+# MainMenu2_img_alipay.add_style(style_MainMenu_img_default, lv.PART.MAIN | lv.STATE.DEFAULT)
+# MainMenu2_num+=1
+# MainMenu2x+=1
# label_alipay.set_long_mode(lv.label.LONG.WRAP)
# label_alipay.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
MainMenu2_img_wechat.add_event_cb(lambda e: EventMesh.callback_wrapper(self.img_cb(e, "wechat")), lv.EVENT.CLICKED, None)
# MainMenu2_img_spo2.add_event_cb(lambda e: EventMesh.callback_wrapper(self.img_cb(e, "spo2")), lv.EVENT.CLICKED, None)
MainMenu2_img_sms.add_event_cb(lambda e: EventMesh.callback_wrapper(self.img_cb(e, "popup")), lv.EVENT.CLICKED, None)
- MainMenu2_img_alipay.add_event_cb(lambda e: EventMesh.callback_wrapper(self.img_cb(e, "alipay_open")), lv.EVENT.CLICKED, None)
+ #MainMenu2_img_alipay.add_event_cb(lambda e: EventMesh.callback_wrapper(self.img_cb(e, "alipay_open")), lv.EVENT.CLICKED, None)
EventMesh.subscribe("watch_top_show", self.watch_top_show)
EventMesh.subscribe("return_alipay", self.return_alipay)