From 5e02aaa74bd161d42cd3a48dc5d6f89491ea29ef Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期二, 31 十二月 2024 16:17:51 +0800
Subject: [PATCH] 新测距算法加入,稳定测距版本

---
 keil/include/main/main.c |   60 +++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/keil/include/main/main.c b/keil/include/main/main.c
index e267301..233a8b8 100644
--- a/keil/include/main/main.c
+++ b/keil/include/main/main.c
@@ -193,12 +193,12 @@
     }
 				if(fVoltage_mv<3300)
 				{
-					power_low_flag=1;
-					gps_air780_power_change(gps_power_state,0);//gps原样,关闭4G 
+					//power_low_flag=1;
+					//gps_air780_power_change(gps_power_state,0);//gps原样,关闭4G 
 					//LOG_INFO(TRACE_MODULE_APP, "电池电压低于3.3V,4G,GPS停止工作\r\n");
 				}else{
-					power_low_flag=0;
-					gps_air780_power_change(gps_power_state,1);//gps原样,开启4G
+					//power_low_flag=0;
+					//gps_air780_power_change(gps_power_state,1);//gps原样,开启4G
 					//LOG_INFO(TRACE_MODULE_APP, "电池电压正常,4G,GPS,正常工作\r\n");
 				}
 		PCA9555_Set_One_Value_Output(ADC_MINIUS,1);//拉高
@@ -215,7 +215,7 @@
 uint8_t TCP_reconnect_timer,flag_TCP_reconnectting = 1,flag_alam_state = 0,userkey_state;
 uint8_t gps_enable_flag,motor_open_air_flag,moter_open_uwb_flag,flag_fenli_alarm = 0,fenli_alarm_count,delaysleep_count,enbale_blink_flag;
 int need_open_gps_count;
-uint32_t keystarttime,keystarttime2;
+uint32_t keystarttime,keystarttime2,keystarttime3;
 extern uint32_t get_in_num,get_out_num;
 void MotorPoll(void)
 {
@@ -300,25 +300,46 @@
 	}
 }
 void UserKeyTask(void)
- {
-     if(!GET_USERKEY)
+{
+if(!read_userkey_input_pca())
      {
-        if(HIDO_TimerGetTick() - keystarttime>3)
+        if(HIDO_TimerGetTick() - keystarttime3>2)
         {
             userkey_state = 1;
-            keystarttime =  HIDO_TimerGetTick();
-						UDPClient_UploadGPS();
+            keystarttime3 =  HIDO_TimerGetTick();
+						//UDPClient_UploadGPS();
         }
-        if(HIDO_TimerGetTick() - keystarttime2>10)
+//        if(HIDO_TimerGetTick() - keystarttime2>10)
+//        {
+//						
+//            g_com_map[CNT_RESTART] = 1;
+//        }
+     }else
+     {
+       keystarttime3 =  HIDO_TimerGetTick(); 
+     }
+} 
+void PowerTask(void)
+{
+     if(read_powerkey_input_pca())
+     {
+        if(HIDO_TimerGetTick() - keystarttime>2)
         {
-            g_com_map[CNT_RESTART] = 1;
+            keystarttime =  HIDO_TimerGetTick();
+						PCA9555_Set_One_Value_Output(PWR_ENABLE,0);//低电平关闭
+						PCA9555_Set_One_Value_Output(GPS_LED,0);//输出低电平关闭LED
         }
+//        if(HIDO_TimerGetTick() - keystarttime2>10)
+//        {
+//						
+//            g_com_map[CNT_RESTART] = 1;
+//        }
      }else
      {
        keystarttime =  HIDO_TimerGetTick(); 
        keystarttime2 =  HIDO_TimerGetTick(); 
      }
- } 
+}
 void MinuteTask(void)
 {		
 		PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低
@@ -331,7 +352,7 @@
         second_count = 0;
         MinuteTask();
     }
-		
+		//UWBOneSecondTask();
 //		if(!power_low_flag)
 //		Gps_change();
 //		else{
@@ -605,7 +626,7 @@
      delay_ms(500);
      Set4LEDColor(RED,WHITE,RED,WHITE);
      delay_ms(500);		
-     Set4LEDColor(LEDOFF,LEDOFF,LEDOFF,LEDOFF);       
+     //Set4LEDColor(LEDOFF,LEDOFF,LEDOFF,LEDOFF);       
     }
 			//IO_control_init();
 //    io_pin_mux_set(SCL_PIN, IO_FUNC0);//测试测距波形
@@ -613,7 +634,6 @@
 //    io_pull_set(SCL_PIN , IO_PULL_UP, IO_PULL_UP_LEVEL4);
     //gps_air780_power_change(0,1);//开启gps,4G 
 //加速度计初始化必须在IO_control_init之前因为复用SDA引脚
-		gpio_pin_clr(ADC_GND_ENABLE);
 		   Program_Init();
     //uart_open(UART_ID1, &test_uart_cfg);
    // uart1_change_from_gps_to_debug();   
@@ -624,8 +644,8 @@
     power_init();
       //AIR780E_Reset(); //4G模块重启,耗时1.5秒,这个是无法同步的关键
     sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback);
-    sleep_timer_start(__MS_TO_32K_CNT(g_com_map[COM_INTERVAL]));//测试
-    //sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试
+    //sleep_timer_start(__MS_TO_32K_CNT(g_com_map[COM_INTERVAL]));//测试
+    sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试
  //   board_5V_input_init(voltage_input_handler);
 			PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低
 		 adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样
@@ -638,6 +658,7 @@
     while (1)
     { 
 			uwb_app_poll();
+			
 			//test4=gpio_pin_get_val(SCL_PIN);
 			//UWBPoll();
 //			if(!power_low_flag)//确认是否休眠下才开启功能
@@ -672,8 +693,9 @@
             SecondTask();
 					
         }
-//				UserKeyTask();
+				PowerTask();
 //				IMUTask();
+				UserKeyTask();
         IdleTask();
 #ifndef DEBUG_MODE
 //if(flag_sleeptimer)

--
Gitblit v1.9.3