#include "app_wearshoes.h" #include "bsp_time.h" #include "system.h" #include "hal_imu.h" #include "arm_math.h" #define APP_WEARSHOES_PROCESS_CYCLE 100 //线程周期,单位ms #define APP_WEARSHOES_TIMEOUT (APP_WEARSHOES_PROCESS_CYCLE * 6) //检测周期,当前1分钟检测一次。 static uint8_t isWearShoes = WEARSHOES_NO; /** @brief 求变异系数的绝对值 @param p_array-[in] 数组地址 @param len-[in] 数组成员个数 @return 变异系数的绝对值 */ static float32_t CoefficientVariation(double *p_array, uint32_t len) { int i; float32_t sum = 0; //总和 float32_t avg; //平均值 float32_t spow = 0; for(i=0;i= USED_ACC_CHECK_WEARSHOES_VALUE) // flag = 1; //前脚地磁触发条件 if((cur_shake - last_shake) >= USED_MAG_CHECK_WEARSHOES_VALUE) flag = 1; if(isWearShoes && (counter >= timeout)) { isWearShoes = WEARSHOES_NO; SEGGER_RTT_printf(0,"isWearShoes,%d\r\n",isWearShoes); } else if(!isWearShoes && flag){ isWearShoes = WEARSHOES_YES; SEGGER_RTT_printf(0,"isWearShoes,%d\r\n",isWearShoes); } if(flag)counter = 0; else counter++; last_shake = cur_shake; } static void app_wearshoes_determine(uint16_t timeout) { int16_t Acc[3]={0}; int16_t MagFront[3]={0}; int32_t front_mag_norm; IMU_Get_Index_Front_Low_Power_Data(Acc, MagFront, NULL, IMU_Get_Front_Update_Data_GroupNum()); //获取最新一组前脚地磁和加速度 front_mag_norm = (int32_t)(sqrt((float) (MagFront[0] * MagFront[0] + MagFront[1] * MagFront[1] + MagFront[2] * MagFront[2]))); mode_switch(front_mag_norm, ~front_mag_norm, 0, timeout); } void app_wearshoes_lowpower_Process(void) { if(IMU_GetCurrentMode() == STATE_LOW_POWER_MODE)//判断是否处于低功耗模式 { app_wearshoes_determine(APP_WEARSHOES_TIMEOUT); } } uint8_t app_wearshoes_is_wearshoes(void) { return isWearShoes; } void app_wearshoes_Init(void) { Process_Start(APP_WEARSHOES_PROCESS_CYCLE,"app_wearshoes_lowpower_Process",app_wearshoes_lowpower_Process); }