123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #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 "hal_mode_manage.h"
- #include "app_overturn.h"
- #include "hal_wearshoes.h"
- #define acc0Value -1400
- #define acc1iValue -1600
- #define acc1aValue 1800
- #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(hal_mode_get() == HAL_MODE_NORMAL) return;//停止状态
-
- //获取最新一组前脚加速度
- if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, acc, NULL, NULL);
-
- // 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==5){
- if(GetBatteryPersent()>20){
- LED_Start(LED_OVERTURN,COLOR_GREEN);
- }else{
- LED_Start(LED_OVERTURN,COLOR_RED);
- }
- 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(1== flag_move){
- 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(hal_mode_get() == HAL_MODE_STANDBY) return;//走路状态
-
- //获取最新一组前脚加速度
- if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, acc, NULL, NULL);
- // 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_Start(LED_OVERTURN,COLOR_GREEN);
- }else{
- LED_Start(LED_OVERTURN,COLOR_RED);
- }
- 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(StandByPower_Interval,"BatDispaly",app_BatDispaly_Process);
- Process_Start(StandByPower_Interval,"BatDispaly_N",app_BatDispaly_Process_N);
- }
|