#include "usr_config.h" #include "hal_battery.h" #include "nrf_drv_saadc.h" #include "bsp_time.h" #include "system.h" #include "hal_led.h" #include "hal_imu.h" #include "app_overturn.h" #include "app_wearshoes.h" #define acc0Value 3000 #define acc1iValue -1600 #define acc1aValue 0 #define acc2iValue -1500 #define acc2aValue 400 /************************ 踮脚显示电量 ***********************************/ static uint8_t flag_move =0; void app_BatDispaly_Process_N(void) { int16_t acc[3]; static uint32_t cnt = 0; if(app_wearshoes_is_wearshoes()== WEARSHOES_YES) return;//停止状态 IMU_Get_Index_Front_Low_Power_Data(acc, NULL, NULL, IMU_Get_Front_Update_Data_GroupNum()); // SEGGER_RTT_printf(0,"0:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]); if(acc[2] > acc1iValue){ cnt++; if(cnt==1){ if(GetBatteryPersent()>20){ LED_SetColor(LED_OVERTURN,COLOR_GREEN); }else{ LED_SetColor(LED_OVERTURN,COLOR_RED); } LED_Start(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process_N,1); } if(cnt==100){ LED_Stop(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process_N,0); } }else{ if(cnt>0){ cnt = 0; LED_Stop(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process_N,0); } if(flag_move == 1){ flag_move =0; LED_Stop(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process_N,0); } } } void app_BatDispaly_Process(void) { int16_t acc[3]; static uint32_t cnt = 0; static int16_t acc0 = acc0Value; static int16_t acc1i = acc1iValue; static int16_t acc1a = acc1aValue; static int16_t acc2i = acc2iValue; static int16_t acc2a = acc2aValue; if(1 == IMU_GetSensorEnable()) { LED_Stop(LED_OVERTURN); return;// } if(app_wearshoes_is_wearshoes() == WEARSHOES_NO) return;//走路状态 IMU_Get_Index_Front_Low_Power_Data(acc, NULL, NULL, IMU_Get_Front_Update_Data_GroupNum()); // SEGGER_RTT_printf(0,"1:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]); if(acc[0] < acc0 && acc[1] > acc1i && acc[1] < acc1a && acc[2] < acc2a && acc[2] > acc2i){ cnt++; if(cnt==10){ if(GetBatteryPersent()>20){ LED_SetColor(LED_OVERTURN,COLOR_GREEN); }else{ LED_SetColor(LED_OVERTURN,COLOR_RED); } LED_Start(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process,1); acc0 = acc0Value; acc1i = acc1iValue; acc1a = acc1aValue; acc2i = acc2iValue; acc2a = acc2aValue; } if(cnt==100){ LED_Stop(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process,0); acc0 = acc0Value-200; acc1i = acc1iValue; acc1a = acc1aValue; acc2i = acc2iValue; acc2a = acc2aValue; } }else{ if(cnt>0){ cnt = 0; LED_Stop(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process,0); acc0 = acc0Value; acc1i = acc1iValue; acc1a = acc1aValue; acc2i = acc2iValue; acc2a = acc2aValue; } if(flag_move == 0){ flag_move =1; LED_Stop(LED_OVERTURN); Process_SetHoldOn(app_BatDispaly_Process,0); acc0 = acc0Value; acc1i = acc1iValue; acc1a = acc1aValue; acc2i = acc2iValue; acc2a = acc2aValue; } } } void app_overturn_Init(void) { Process_Start(100,"BatDispaly",app_BatDispaly_Process); Process_Start(100,"BatDispaly_N",app_BatDispaly_Process_N); }