#include "hal_wearshoes.h" #include "bsp_time.h" #include "system.h" #include "hal_mode_manage.h" #include "hal_imu.h" #include "arm_math.h" #define HAL_WEARSHOES_PROCESS_CYCLE 100 //线程周期,单位ms #define HAL_WEARSHOES_TIMEOUT 100 //检测周期,当前1分钟检测一次。 static uint8_t isWearShoes = WEARSHOES_YES; /** @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 hal_wearshoes_determine(uint16_t timeout) { int16_t Acc[3]={0}; //获取最新一组前脚加速度 if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, Acc, NULL, NULL); mode_switch(Acc[0], Acc[1], Acc[2], timeout); } void hal_wearshoes_Process(void) { if(hal_mode_get() == HAL_MODE_NORMAL && isWearShoes == WEARSHOES_NO) { hal_mode_set(HAL_MODE_STANDBY); //切换为待机模式 } else if(hal_mode_get() == HAL_MODE_STANDBY && isWearShoes == WEARSHOES_YES) { hal_mode_set(HAL_MODE_NORMAL); //切换为日常模式 } else if(hal_mode_get() != HAL_MODE_GAME && hal_mode_get() != HAL_MODE_REALSTEP) { hal_wearshoes_determine(HAL_WEARSHOES_TIMEOUT); //检测是否穿鞋 } } uint8_t hal_wearshoes_is_wearshoes(void) { return isWearShoes; } void hal_wearshoes_Init(void) { if(INIT_MODE == HAL_MODE_NORMAL)isWearShoes = WEARSHOES_YES; else if(INIT_MODE == HAL_MODE_STANDBY)isWearShoes = WEARSHOES_NO; Process_Start(HAL_WEARSHOES_PROCESS_CYCLE,"hal_wearshoes_Process",hal_wearshoes_Process); }