123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #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 "hal_step.h"
- #include "hal_attitude.h"
- #define acc0Value -9000
- #define acc1iValue -9000
- #define acc1aValue 9000
- #define acc2iValue -12000
- #define acc2aValue -4000
-
- /************************ 追신鞫刻든좆 ***********************************/
- static uint8_t flag_move =0;
- void app_BatDispaly_Process_N(void)
- {
- static uint32_t cnt = 0;
-
- if(get_isLoader()>0) return;//界岺榴檄
-
- int16_t * acc = hal_att_GetAcc();
- // 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)
- {
- 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_GetGameMode()) {
- LED_Stop(LED_OVERTURN);
- return;//
- }
- if(get_isLoader()==0) return;//浬쨌榴檄
-
- int16_t * acc = hal_att_GetAcc();
- // 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);
- }
|