#include "SL_algo1.h" #if SL_Sensor_Algo_Release_Enable==0x00 #include "usart.h" extern signed short SL_DEBUG_DATA[10][128]; extern unsigned char SL_DEBUG_DATA_LEN; extern unsigned char sl_sleep_sys_cnt; #endif #if SL_Sensor_Algo_Release_Enable==0x00 extern signed short SL_ACCEL_DATA_Buf[3][16]; extern unsigned char SL_FIFO_ACCEL_PEDO_NUM; signed short hp_buf[16]; #endif #define SL_SC7A20_SPI_IIC_MODE 1 /***SL_SC7A20_SPI_IIC_MODE==0 :SPI*******/ /***SL_SC7A20_SPI_IIC_MODE==1 :IIC*******/ static signed char sl_init_status=0x00; /**Please modify the following parameters according to the actual situation**/ signed char SL_SC7A20_PEDO_KCAL_WRIST_SLEEP_SWAY_INIT(void) { #if SL_Sensor_Algo_Release_Enable==0x00 unsigned char sl_version_value=0x00; #endif // bool fifo_status =0; unsigned char sl_person_para[4] ={178,60,26,1}; unsigned char Turn_Wrist_Para[3]={1,3,0};//refer pdf #if SL_Sensor_Algo_Release_Enable==0x00 //sl_version_value==0x11 SC7A20 //sl_version_value==0x26 SC7A20E SL_SC7A20_I2c_Spi_Read(1, SL_SC7A20_VERSION_ADDR,1, &sl_version_value); USART_printf( USART1, "Version ID=0x%x!\r\n",sl_version_value); if(sl_version_value==SL_SC7A20_VERSION_VALUE) USART_printf( USART1, "SC7A20!\r\n"); else if(sl_version_value==SL_SC7A20E_VERSION_VALUE) USART_printf( USART1, "SC7A20E!\r\n"); #endif /*****if use spi mode please config first******/ #if SL_SC7A20_SPI_IIC_MODE == 0//spi sl_init_status=SL_SC7A20_Driver_Init(1,0x04);//iic mode pull up config //init sensor sl_init_status=SL_SC7A20_Driver_Init(0,0x04);//spi or iic select #else//i2c sl_init_status=SL_SC7A20_Driver_Init(1,0x00);//spi or iic select //0x08-->close sdo pull up #endif /**********sc7a20 fifo test***************/ //fifo_status=SL_SC7A20_FIFO_TEST(); /**********set pedo sensitivity***********/ SL_PEDO_TH_SET(32,10,1,30,50);//36 12 0 30 50for motor /*which axis used to pedo depend on algo**/ SL_PEDO_SET_AXIS(3); /**********set int para*******************/ SL_PEDO_INT_SET(2,1,1);//0 or 1 sleep is different /**********set motion para****************/ SL_Pedo_Person_Inf_Init(&sl_person_para[0]);//personal para init /**********set turn wrist para************/ SL_Turn_Wrist_Init(&Turn_Wrist_Para[0]); /**********set sleep sensitivity**********/ SL_Sleep_Para(120,10,1); return sl_init_status; } static unsigned int SL_STEP = 0; static unsigned int SL_STEP_TEMP = 0; static unsigned char SL_STEP_MOTION = 0; static unsigned int SL_DISTANCE = 0; static unsigned int SL_KCAL = 0; static unsigned char SL_CADENCE_STEP = 0;//step per minutes static unsigned short SL_CADENCE_AMP = 0;//Equal scale scaling static unsigned char SL_CADENCE_DEGREE = 0;//degree static signed char SL_WRIST = 0; static unsigned char SL_SLEEP_ACTIVE = 0; static unsigned char SL_SLEEP_STATUS = 0; static unsigned char SL_SLEEP_ADOM = 0; static unsigned char SL_SLEEP_CNT = 0; static bool SL_CLOCK_STATUS = 0; static bool SL_SWAY_STATUS = 0; static bool SL_SWAY_ENABLE = 0; static unsigned char SL_INT_TIME_CNT = 0; #define SL_INT_TIME_TH 12 //per lsb is 0.5s extern unsigned char sl_sleep_sys_hour; unsigned char SL_MCU_SLEEP_ALGO_FUNCTION(void); unsigned int SL_SC7A20_PEDO_KCAL_WRIST_SLEEP_SWAY_ALGO(void) { #if SL_Sensor_Algo_Release_Enable==0x00 unsigned char sl_i; #endif signed short SC7A20_XYZ_Buf[3][14]; unsigned char SC7A20_FIFO_NUM; bool SC7A20_INT_STATUS; if((sl_init_status!=SL_SC7A20_VERSION_VALUE)&&(sl_init_status!=SL_SC7A20E_VERSION_VALUE)) return 0;//initial fail /*******read int status******/ SC7A20_INT_STATUS=SL_INT_STATUS_READ(); if((SC7A20_INT_STATUS==1)||(SL_STEP_TEMP!= SL_STEP)) { SL_INT_TIME_CNT =0; SL_STEP_TEMP =SL_STEP; } else { if(SL_INT_TIME_CNT<200) { SL_INT_TIME_CNT++; } } if(SL_INT_TIME_CNT200) // { /**reset pedo value**/ // SL_Pedo_Kcal_ResetStepCount(); // } /*******get wrist value******/ SL_WRIST= SL_Watch_Wrist_Algo(); /*******get overturn value******/ SL_CLOCK_STATUS=SL_Get_Clock_Status(1);//open overturn monitor if(SL_CLOCK_STATUS==1)//overturn success { SL_Get_Clock_Status(0);//close overturn monitor } /*******get sway value******/ if(SL_SWAY_ENABLE==1) { /**this function will disable pedo function**/ SL_SWAY_STATUS=SL_Get_Phone_Answer_Status(4,5);//get sway value } } else { //sc7a20 's data for heart rate algo //SC7A20_FIFO_NUM= SL_SC7A20_Read_FIFO(); //SC7A20_FIFO_NUM= SL_SC7A20_GET_FIFO_Buf(&SC7A20_XYZ_Buf[0][0],&SC7A20_XYZ_Buf[1][0],&SC7A20_XYZ_Buf[2][0],0); SL_Pedo_WorkMode_Reset(); //SL_Turn_Wrist_WorkMode_Reset();please not use this function SC7A20_FIFO_NUM=0; } /*******get sleep status value******/ SL_SLEEP_CNT++; #if SL_Sensor_Algo_Release_Enable==0x00 if(SL_SLEEP_CNT>39)//1min #else if(SL_SLEEP_CNT>119)//1min #endif { #if SL_Sensor_Algo_Release_Enable==0 sl_sleep_sys_cnt++; if(sl_sleep_sys_cnt>59)//min { sl_sleep_sys_cnt=0; sl_sleep_sys_hour++;//hour if(sl_sleep_sys_hour==24) sl_sleep_sys_hour=0; } #endif SL_SLEEP_CNT=0; SL_MCU_SLEEP_ALGO_FUNCTION(); } #if SL_Sensor_Algo_Release_Enable==0x00 SL_DEBUG_DATA_LEN=SC7A20_FIFO_NUM; for(sl_i=0;sl_i